mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +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\Steam;
|
||||
use FireflyIII\Support\Http\Api\ApiSupport;
|
||||
use FireflyIII\Support\Http\Api\CleansChartData;
|
||||
use FireflyIII\Support\Http\Api\CollectsAccountsFromFilter;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -48,10 +49,11 @@ class AccountController extends Controller
|
||||
{
|
||||
use ApiSupport;
|
||||
use CollectsAccountsFromFilter;
|
||||
use CleansChartData;
|
||||
|
||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||
|
||||
private ChartData $chartData;
|
||||
private array $chartData;
|
||||
private AccountRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
@@ -62,11 +64,9 @@ class AccountController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->chartData = new ChartData();
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
$this->repository->setUserGroup($this->userGroup);
|
||||
$this->repository->setUser($this->user);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class AccountController extends Controller
|
||||
// move date to end of day
|
||||
$queryParameters['start']->startOfDay();
|
||||
$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:
|
||||
/** @var Account $account */
|
||||
@@ -93,7 +93,7 @@ class AccountController extends Controller
|
||||
$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'];
|
||||
$pcPrevious = null;
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
$currency = $this->default;
|
||||
$currency = $this->primaryCurrency;
|
||||
}
|
||||
$currentSet = [
|
||||
'label' => $account->name,
|
||||
@@ -162,21 +162,6 @@ class AccountController extends Controller
|
||||
|
||||
$currentStart->addDay();
|
||||
}
|
||||
$this->chartData->add($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;
|
||||
$this->chartData[] = $currentSet;
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ class BalanceController extends Controller
|
||||
use CollectsAccountsFromFilter;
|
||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||
|
||||
private array $chartData;
|
||||
private array $chartData = [];
|
||||
private GroupCollectorInterface $collector;
|
||||
private AccountRepositoryInterface $repository;
|
||||
|
||||
@@ -40,11 +40,10 @@ class BalanceController extends Controller
|
||||
function ($request, $next) {
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$this->collector = app(GroupCollectorInterface::class);
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
$this->collector->setUserGroup($userGroup);
|
||||
$this->chartData = [];
|
||||
// $this->default = app('amount')->getPrimaryCurrency();
|
||||
$this->repository->setUserGroup($this->userGroup);
|
||||
$this->collector->setUserGroup($this->userGroup);
|
||||
$this->repository->setUser($this->user);
|
||||
$this->collector->setUser($this->user);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -63,13 +63,17 @@ class BudgetController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->validateUserGroup($request);
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
$this->opsRepository->setUserGroup($userGroup);
|
||||
$this->blRepository->setUserGroup($userGroup);
|
||||
$this->validateUserGroup($request);
|
||||
$this->repository->setUserGroup($this->userGroup);
|
||||
$this->opsRepository->setUserGroup($this->userGroup);
|
||||
$this->blRepository->setUserGroup($this->userGroup);
|
||||
$this->repository->setUser($this->user);
|
||||
$this->opsRepository->setUser($this->user);
|
||||
$this->blRepository->setUser($this->user);
|
||||
|
||||
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
|
||||
$return = [];
|
||||
foreach ($rows as $row) {
|
||||
@@ -193,9 +191,9 @@ class BudgetController extends Controller
|
||||
],
|
||||
'pc_entries' => [
|
||||
'budgeted' => $row['pc_budgeted'],
|
||||
'spent' => '0',
|
||||
'left' => '0',
|
||||
'overspent' => '0',
|
||||
'spent' => $row['pc_spent'],
|
||||
'left' => $row['pc_left'],
|
||||
'overspent' => $row['pc_overspent'],
|
||||
],
|
||||
];
|
||||
$return[] = $current;
|
||||
|
@@ -61,9 +61,10 @@ class CategoryController extends Controller
|
||||
function ($request, $next) {
|
||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
$this->accountRepos->setUserGroup($userGroup);
|
||||
$this->currencyRepos->setUserGroup($userGroup);
|
||||
$this->accountRepos->setUserGroup($this->userGroup);
|
||||
$this->currencyRepos->setUserGroup($this->userGroup);
|
||||
$this->accountRepos->setUser($this->user);
|
||||
$this->currencyRepos->setUser($this->user);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
Reference in New Issue
Block a user