mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-01 18:42:01 +00:00
Extend acceptedRoles to chart controllers.
This commit is contained in:
@@ -37,6 +37,7 @@ use FireflyIII\Support\Chart\ChartData;
|
|||||||
use FireflyIII\Support\Facades\Preferences;
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Http\Api\ApiSupport;
|
use FireflyIII\Support\Http\Api\ApiSupport;
|
||||||
|
use FireflyIII\Support\Http\Api\CleansChartData;
|
||||||
use FireflyIII\Support\Http\Api\CollectsAccountsFromFilter;
|
use FireflyIII\Support\Http\Api\CollectsAccountsFromFilter;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -48,10 +49,11 @@ class AccountController extends Controller
|
|||||||
{
|
{
|
||||||
use ApiSupport;
|
use ApiSupport;
|
||||||
use CollectsAccountsFromFilter;
|
use CollectsAccountsFromFilter;
|
||||||
|
use CleansChartData;
|
||||||
|
|
||||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||||
|
|
||||||
private ChartData $chartData;
|
private array $chartData;
|
||||||
private AccountRepositoryInterface $repository;
|
private AccountRepositoryInterface $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,11 +64,9 @@ class AccountController extends Controller
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->chartData = new ChartData();
|
|
||||||
$this->repository = app(AccountRepositoryInterface::class);
|
$this->repository = app(AccountRepositoryInterface::class);
|
||||||
|
$this->repository->setUserGroup($this->userGroup);
|
||||||
$userGroup = $this->validateUserGroup($request);
|
$this->repository->setUser($this->user);
|
||||||
$this->repository->setUserGroup($userGroup);
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ class AccountController extends Controller
|
|||||||
// move date to end of day
|
// move date to end of day
|
||||||
$queryParameters['start']->startOfDay();
|
$queryParameters['start']->startOfDay();
|
||||||
$queryParameters['end']->endOfDay();
|
$queryParameters['end']->endOfDay();
|
||||||
Log::debug(sprintf('dashboard(), convert to primary: %s', var_export($this->convertToPrimary, true)));
|
// Log::debug(sprintf('dashboard(), convert to primary: %s', var_export($this->convertToPrimary, true)));
|
||||||
|
|
||||||
// loop each account, and collect info:
|
// loop each account, and collect info:
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
@@ -93,7 +93,7 @@ class AccountController extends Controller
|
|||||||
$this->renderAccountData($queryParameters, $account);
|
$this->renderAccountData($queryParameters, $account);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($this->chartData->render());
|
return response()->json($this->clean($this->chartData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +110,7 @@ class AccountController extends Controller
|
|||||||
$previous = array_values($range)[0]['balance'];
|
$previous = array_values($range)[0]['balance'];
|
||||||
$pcPrevious = null;
|
$pcPrevious = null;
|
||||||
if (!$currency instanceof TransactionCurrency) {
|
if (!$currency instanceof TransactionCurrency) {
|
||||||
$currency = $this->default;
|
$currency = $this->primaryCurrency;
|
||||||
}
|
}
|
||||||
$currentSet = [
|
$currentSet = [
|
||||||
'label' => $account->name,
|
'label' => $account->name,
|
||||||
@@ -162,21 +162,6 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
}
|
}
|
||||||
$this->chartData->add($currentSet);
|
$this->chartData[] = $currentSet;
|
||||||
}
|
|
||||||
|
|
||||||
private function getFrontPageAccountIds(): array
|
|
||||||
{
|
|
||||||
$defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
|
|
||||||
|
|
||||||
/** @var Preference $frontpage */
|
|
||||||
$frontpage = Preferences::get('frontpageAccounts', $defaultSet);
|
|
||||||
|
|
||||||
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
|
|
||||||
$frontpage->data = $defaultSet;
|
|
||||||
$frontpage->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $frontpage->data ?? $defaultSet;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class BalanceController extends Controller
|
|||||||
use CollectsAccountsFromFilter;
|
use CollectsAccountsFromFilter;
|
||||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||||
|
|
||||||
private array $chartData;
|
private array $chartData = [];
|
||||||
private GroupCollectorInterface $collector;
|
private GroupCollectorInterface $collector;
|
||||||
private AccountRepositoryInterface $repository;
|
private AccountRepositoryInterface $repository;
|
||||||
|
|
||||||
@@ -40,11 +40,10 @@ class BalanceController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->repository = app(AccountRepositoryInterface::class);
|
$this->repository = app(AccountRepositoryInterface::class);
|
||||||
$this->collector = app(GroupCollectorInterface::class);
|
$this->collector = app(GroupCollectorInterface::class);
|
||||||
$userGroup = $this->validateUserGroup($request);
|
$this->repository->setUserGroup($this->userGroup);
|
||||||
$this->repository->setUserGroup($userGroup);
|
$this->collector->setUserGroup($this->userGroup);
|
||||||
$this->collector->setUserGroup($userGroup);
|
$this->repository->setUser($this->user);
|
||||||
$this->chartData = [];
|
$this->collector->setUser($this->user);
|
||||||
// $this->default = app('amount')->getPrimaryCurrency();
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,13 +63,17 @@ class BudgetController extends Controller
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
|
$this->validateUserGroup($request);
|
||||||
$this->repository = app(BudgetRepositoryInterface::class);
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
||||||
$userGroup = $this->validateUserGroup($request);
|
$this->validateUserGroup($request);
|
||||||
$this->repository->setUserGroup($userGroup);
|
$this->repository->setUserGroup($this->userGroup);
|
||||||
$this->opsRepository->setUserGroup($userGroup);
|
$this->opsRepository->setUserGroup($this->userGroup);
|
||||||
$this->blRepository->setUserGroup($userGroup);
|
$this->blRepository->setUserGroup($this->userGroup);
|
||||||
|
$this->repository->setUser($this->user);
|
||||||
|
$this->opsRepository->setUser($this->user);
|
||||||
|
$this->blRepository->setUser($this->user);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -157,12 +161,6 @@ class BudgetController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if no limits
|
|
||||||
// if (0 === $limits->count()) {
|
|
||||||
// return as a single item in an array
|
|
||||||
// $rows = $this->noBudgetLimits($budget, $start, $end);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// is always an array
|
// is always an array
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
@@ -193,9 +191,9 @@ class BudgetController extends Controller
|
|||||||
],
|
],
|
||||||
'pc_entries' => [
|
'pc_entries' => [
|
||||||
'budgeted' => $row['pc_budgeted'],
|
'budgeted' => $row['pc_budgeted'],
|
||||||
'spent' => '0',
|
'spent' => $row['pc_spent'],
|
||||||
'left' => '0',
|
'left' => $row['pc_left'],
|
||||||
'overspent' => '0',
|
'overspent' => $row['pc_overspent'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$return[] = $current;
|
$return[] = $current;
|
||||||
|
|||||||
@@ -61,9 +61,10 @@ class CategoryController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||||
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
$userGroup = $this->validateUserGroup($request);
|
$this->accountRepos->setUserGroup($this->userGroup);
|
||||||
$this->accountRepos->setUserGroup($userGroup);
|
$this->currencyRepos->setUserGroup($this->userGroup);
|
||||||
$this->currencyRepos->setUserGroup($userGroup);
|
$this->accountRepos->setUser($this->user);
|
||||||
|
$this->currencyRepos->setUser($this->user);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user