mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Update repositories, remove references to admin id
This commit is contained in:
@@ -67,9 +67,9 @@ class AccountController extends Controller
|
|||||||
* TODO list of checks
|
* TODO list of checks
|
||||||
* 1. use dates from ParameterBag
|
* 1. use dates from ParameterBag
|
||||||
* 2. Request validates dates
|
* 2. Request validates dates
|
||||||
* 3. Request includes user_group_id as administration_id
|
* 3. Request includes user_group_id
|
||||||
* 4. Endpoint is documented.
|
* 4. Endpoint is documented.
|
||||||
* 5. Collector uses administration_id
|
* 5. Collector uses user_group_id
|
||||||
*
|
*
|
||||||
* @param AutocompleteRequest $request
|
* @param AutocompleteRequest $request
|
||||||
*
|
*
|
||||||
|
@@ -76,7 +76,7 @@ class AccountController extends Controller
|
|||||||
* If a transaction has foreign currency = native currency, the foreign amount will be used, no conversion
|
* If a transaction has foreign currency = native currency, the foreign amount will be used, no conversion
|
||||||
* will take place.
|
* will take place.
|
||||||
*
|
*
|
||||||
* TODO validate and set administration_id from request
|
* TODO validate and set user_group_id from request
|
||||||
*
|
*
|
||||||
* @param DateRequest $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
|
@@ -71,7 +71,7 @@ class BalanceController extends Controller
|
|||||||
* If the transaction being processed is already in native currency OR if the
|
* If the transaction being processed is already in native currency OR if the
|
||||||
* foreign amount is in the native currency, the amount will not be converted.
|
* foreign amount is in the native currency, the amount will not be converted.
|
||||||
*
|
*
|
||||||
* TODO validate and set administration_id
|
* TODO validate and set user_group_id
|
||||||
* TODO collector set group, not user
|
* TODO collector set group, not user
|
||||||
*
|
*
|
||||||
* @param BalanceChartRequest $request
|
* @param BalanceChartRequest $request
|
||||||
|
@@ -52,6 +52,7 @@ class ShowController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->repository = app(BillRepositoryInterface::class);
|
$this->repository = app(BillRepositoryInterface::class);
|
||||||
|
|
||||||
|
// new way of user group validation
|
||||||
$userGroup = $this->validateUserGroup($request);
|
$userGroup = $this->validateUserGroup($request);
|
||||||
if (null !== $userGroup) {
|
if (null !== $userGroup) {
|
||||||
$this->repository->setUserGroup($userGroup);
|
$this->repository->setUserGroup($userGroup);
|
||||||
|
@@ -62,8 +62,6 @@ class StoreController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO this method is practically the same as the V1 method and borrows as much code as possible.
|
* TODO this method is practically the same as the V1 method and borrows as much code as possible.
|
||||||
* TODO still it duplicates a lot.
|
|
||||||
* TODO the v1 endpoints will never support separate administrations, this is an important distinction.
|
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@@ -74,7 +72,6 @@ class StoreController extends Controller
|
|||||||
|
|
||||||
app('log')->debug('Now in API v2 StoreController::store()');
|
app('log')->debug('Now in API v2 StoreController::store()');
|
||||||
$data = $request->getAll();
|
$data = $request->getAll();
|
||||||
$data['user'] = auth()->user()->id;
|
|
||||||
$userGroup = $request->getUserGroup();
|
$userGroup = $request->getUserGroup();
|
||||||
$data['user_group'] = $userGroup;
|
$data['user_group'] = $userGroup;
|
||||||
|
|
||||||
|
@@ -26,8 +26,9 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
|
|||||||
|
|
||||||
use FireflyIII\Api\V2\Controllers\Controller;
|
use FireflyIII\Api\V2\Controllers\Controller;
|
||||||
use FireflyIII\Api\V2\Request\Generic\SingleDateRequest;
|
use FireflyIII\Api\V2\Request\Generic\SingleDateRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||||
|
use FireflyIII\Support\Http\Api\ConvertsExchangeRates;
|
||||||
|
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +36,9 @@ use Illuminate\Http\JsonResponse;
|
|||||||
*/
|
*/
|
||||||
class NetWorthController extends Controller
|
class NetWorthController extends Controller
|
||||||
{
|
{
|
||||||
|
use ValidatesUserGroupTrait;
|
||||||
|
use ConvertsExchangeRates;
|
||||||
|
|
||||||
private NetWorthInterface $netWorth;
|
private NetWorthInterface $netWorth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +50,12 @@ class NetWorthController extends Controller
|
|||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->netWorth = app(NetWorthInterface::class);
|
$this->netWorth = app(NetWorthInterface::class);
|
||||||
$this->netWorth->setUser(auth()->user());
|
|
||||||
|
// new way of user group validation
|
||||||
|
$userGroup = $this->validateUserGroup($request);
|
||||||
|
if (null !== $userGroup) {
|
||||||
|
$this->netWorth->setUserGroup($userGroup);
|
||||||
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -63,7 +72,6 @@ class NetWorthController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function get(SingleDateRequest $request): JsonResponse
|
public function get(SingleDateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
throw new FireflyException('deprecated use of thing.');
|
|
||||||
$date = $request->getDate();
|
$date = $request->getDate();
|
||||||
$result = $this->netWorth->sumNetWorthByCurrency($date);
|
$result = $this->netWorth->sumNetWorthByCurrency($date);
|
||||||
$converted = $this->cerSum($result);
|
$converted = $this->cerSum($result);
|
||||||
|
@@ -24,13 +24,10 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V2\Request\Autocomplete;
|
namespace FireflyIII\Api\V2\Request\Autocomplete;
|
||||||
|
|
||||||
use FireflyIII\Enums\UserRoleEnum;
|
use FireflyIII\Enums\UserRoleEnum;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\UserRole;
|
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use FireflyIII\Validation\Administration\ValidatesAdministrationAccess;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
@@ -39,13 +36,12 @@ use Illuminate\Validation\Validator;
|
|||||||
*/
|
*/
|
||||||
class AutocompleteRequest extends FormRequest
|
class AutocompleteRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
protected array $acceptedRoles = [UserRoleEnum::MANAGE_TRANSACTIONS];
|
||||||
use ConvertsDataTypes;
|
use ConvertsDataTypes;
|
||||||
use ChecksLogin;
|
use ChecksLogin;
|
||||||
use ValidatesAdministrationAccess;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function getData(): array
|
public function getData(): array
|
||||||
{
|
{
|
||||||
@@ -63,11 +59,10 @@ class AutocompleteRequest extends FormRequest
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'types' => $array,
|
'types' => $array,
|
||||||
'query' => $this->convertString('query'),
|
'query' => $this->convertString('query'),
|
||||||
'date' => $this->getCarbonDate('date'),
|
'date' => $this->getCarbonDate('date'),
|
||||||
'limit' => $limit,
|
'limit' => $limit,
|
||||||
'administration_id' => (int)($this->get('administration_id', null) ?? $user->getAdministrationId()),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,8 +29,8 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface as AdminAccountRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface as AdminAccountRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
@@ -39,6 +39,8 @@ use Illuminate\Support\Collection;
|
|||||||
use JsonException;
|
use JsonException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This class can handle both request with and without a user group and will return the appropriate repository when
|
||||||
|
* necessary.
|
||||||
*
|
*
|
||||||
* Class NetWorth
|
* Class NetWorth
|
||||||
*/
|
*/
|
||||||
@@ -49,7 +51,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
|
|
||||||
private CurrencyRepositoryInterface $currencyRepos;
|
private CurrencyRepositoryInterface $currencyRepos;
|
||||||
private User $user;
|
private User $user;
|
||||||
private UserGroup $userGroup;
|
private null | UserGroup $userGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
@@ -67,7 +69,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
$cache->addProperty('net-worth-by-accounts');
|
$cache->addProperty('net-worth-by-accounts');
|
||||||
$cache->addProperty($ids);
|
$cache->addProperty($ids);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
//return $cache->get();
|
return $cache->get();
|
||||||
}
|
}
|
||||||
app('log')->debug(sprintf('Now in byAccounts("%s", "%s")', $ids, $date->format('Y-m-d')));
|
app('log')->debug(sprintf('Now in byAccounts("%s", "%s")', $ids, $date->format('Y-m-d')));
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
app('log')->debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
|
app('log')->debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
|
||||||
$currency = $this->adminAccountRepository->getAccountCurrency($account);
|
$currency = $this->getRepository()->getAccountCurrency($account);
|
||||||
$currencyId = (int)$currency->id;
|
$currencyId = (int)$currency->id;
|
||||||
$balance = '0';
|
$balance = '0';
|
||||||
$nativeBalance = '0';
|
$nativeBalance = '0';
|
||||||
@@ -137,6 +139,17 @@ class NetWorth implements NetWorthInterface
|
|||||||
return $netWorth;
|
return $netWorth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return AdminAccountRepositoryInterface|AccountRepositoryInterface
|
||||||
|
*/
|
||||||
|
private function getRepository(): AdminAccountRepositoryInterface | AccountRepositoryInterface
|
||||||
|
{
|
||||||
|
if (null === $this->userGroup) {
|
||||||
|
return $this->accountRepository;
|
||||||
|
}
|
||||||
|
return $this->adminAccountRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user's net worth in an array with the following layout:
|
* Returns the user's net worth in an array with the following layout:
|
||||||
*
|
*
|
||||||
@@ -181,7 +194,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
// Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
|
// Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
|
||||||
$currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id');
|
$currencyId = (int)$this->getRepository()->getMetaValue($account, 'currency_id');
|
||||||
$currencyId = 0 === $currencyId ? $default->id : $currencyId;
|
$currencyId = 0 === $currencyId ? $default->id : $currencyId;
|
||||||
|
|
||||||
// Log::debug(sprintf('Currency ID is #%d', $currencyId));
|
// Log::debug(sprintf('Currency ID is #%d', $currencyId));
|
||||||
@@ -227,7 +240,8 @@ class NetWorth implements NetWorthInterface
|
|||||||
if (null === $user) {
|
if (null === $user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
$this->userGroup = null;
|
||||||
|
|
||||||
// make repository:
|
// make repository:
|
||||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||||
@@ -239,7 +253,6 @@ class NetWorth implements NetWorthInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function setUserGroup(UserGroup $userGroup): void
|
public function setUserGroup(UserGroup $userGroup): void
|
||||||
{
|
{
|
||||||
@@ -260,7 +273,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
$return = [];
|
$return = [];
|
||||||
$balances = app('steam')->balancesByAccounts($accounts, $date);
|
$balances = app('steam')->balancesByAccounts($accounts, $date);
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
$currency = $this->getRepository()->getAccountCurrency($account);
|
||||||
$balance = $balances[$account->id] ?? '0';
|
$balance = $balances[$account->id] ?? '0';
|
||||||
|
|
||||||
// always subtract virtual balance.
|
// always subtract virtual balance.
|
||||||
@@ -288,13 +301,13 @@ class NetWorth implements NetWorthInterface
|
|||||||
*/
|
*/
|
||||||
private function getAccounts(): Collection
|
private function getAccounts(): Collection
|
||||||
{
|
{
|
||||||
$accounts = $this->accountRepository->getAccountsByType(
|
$accounts = $this->getRepository()->getAccountsByType(
|
||||||
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
|
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
|
||||||
);
|
);
|
||||||
$filtered = new Collection();
|
$filtered = new Collection();
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
if (1 === (int)$this->accountRepository->getMetaValue($account, 'include_net_worth')) {
|
if (1 === (int)$this->getRepository()->getMetaValue($account, 'include_net_worth')) {
|
||||||
$filtered->push($account);
|
$filtered->push($account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,24 +26,21 @@ namespace FireflyIII\Http\Requests;
|
|||||||
use FireflyIII\Enums\UserRoleEnum;
|
use FireflyIII\Enums\UserRoleEnum;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
use FireflyIII\Models\UserRole;
|
|
||||||
use FireflyIII\Rules\UniqueIban;
|
use FireflyIII\Rules\UniqueIban;
|
||||||
use FireflyIII\Support\Request\AppendsLocationData;
|
use FireflyIII\Support\Request\AppendsLocationData;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use FireflyIII\Validation\Administration\ValidatesAdministrationAccess;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Validator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountFormRequest.
|
* Class AccountFormRequest.
|
||||||
*/
|
*/
|
||||||
class AccountFormRequest extends FormRequest
|
class AccountFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
protected array $acceptedRoles = [UserRoleEnum::MANAGE_TRANSACTIONS];
|
||||||
use ConvertsDataTypes;
|
use ConvertsDataTypes;
|
||||||
use AppendsLocationData;
|
use AppendsLocationData;
|
||||||
use ChecksLogin;
|
use ChecksLogin;
|
||||||
use ValidatesAdministrationAccess;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all data.
|
* Get all data.
|
||||||
@@ -53,7 +50,6 @@ class AccountFormRequest extends FormRequest
|
|||||||
public function getAccountData(): array
|
public function getAccountData(): array
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'administration_id' => $this->convertInteger('administration_id'),
|
|
||||||
'name' => $this->convertString('name'),
|
'name' => $this->convertString('name'),
|
||||||
'active' => $this->boolean('active'),
|
'active' => $this->boolean('active'),
|
||||||
'account_type_name' => $this->convertString('objectType'),
|
'account_type_name' => $this->convertString('objectType'),
|
||||||
@@ -73,9 +69,6 @@ class AccountFormRequest extends FormRequest
|
|||||||
'include_net_worth' => '1',
|
'include_net_worth' => '1',
|
||||||
'liability_direction' => $this->convertString('liability_direction'),
|
'liability_direction' => $this->convertString('liability_direction'),
|
||||||
];
|
];
|
||||||
if (0 === $data['administration_id']) {
|
|
||||||
$data['administration_id'] = auth()->user()->getAdministrationId();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->appendLocationData($data, 'location');
|
$data = $this->appendLocationData($data, 'location');
|
||||||
if (false === $this->boolean('include_net_worth')) {
|
if (false === $this->boolean('include_net_worth')) {
|
||||||
@@ -110,7 +103,6 @@ class AccountFormRequest extends FormRequest
|
|||||||
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
|
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
|
||||||
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
|
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
|
||||||
$rules = [
|
$rules = [
|
||||||
'administration_id' => 'min:1|max:16777216|numeric',
|
|
||||||
'name' => 'required|max:1024|min:1|uniqueAccountForUser',
|
'name' => 'required|max:1024|min:1|uniqueAccountForUser',
|
||||||
'opening_balance' => 'numeric|nullable|max:1000000000',
|
'opening_balance' => 'numeric|nullable|max:1000000000',
|
||||||
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
|
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
|
||||||
@@ -140,21 +132,4 @@ class AccountFormRequest extends FormRequest
|
|||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the validator instance with special rules for after the basic validation rules.
|
|
||||||
*
|
|
||||||
* @param Validator $validator
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function withValidator(Validator $validator): void
|
|
||||||
{
|
|
||||||
$validator->after(
|
|
||||||
function (Validator $validator) {
|
|
||||||
// validate if the account can access this administration
|
|
||||||
$this->validateAdministration($validator, [UserRoleEnum::MANAGE_TRANSACTIONS->value]);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountRepository
|
* Class AccountRepository
|
||||||
@@ -40,6 +41,32 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
{
|
{
|
||||||
use UserGroupTrait;
|
use UserGroupTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function findByName(string $name, array $types): ?Account
|
||||||
|
{
|
||||||
|
$query = $this->userGroup->accounts();
|
||||||
|
|
||||||
|
if (0 !== count($types)) {
|
||||||
|
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||||
|
$query->whereIn('account_types.type', $types);
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
|
||||||
|
|
||||||
|
$query->where('accounts.name', $name);
|
||||||
|
/** @var Account $account */
|
||||||
|
$account = $query->first(['accounts.*']);
|
||||||
|
if (null === $account) {
|
||||||
|
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
|
@@ -41,6 +41,14 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function find(int $accountId): ?Account;
|
public function find(int $accountId): ?Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Account|null
|
||||||
|
*/
|
||||||
|
public function findByName(string $name, array $types): ?Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
|
@@ -48,15 +48,14 @@ class UserTransformer extends AbstractTransformer
|
|||||||
$this->repository = $this->repository ?? app(UserRepositoryInterface::class);
|
$this->repository = $this->repository ?? app(UserRepositoryInterface::class);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (int)$user->id,
|
'id' => (int)$user->id,
|
||||||
'administration_id' => (string)$user->getAdministrationId(),
|
'created_at' => $user->created_at->toAtomString(),
|
||||||
'created_at' => $user->created_at->toAtomString(),
|
'updated_at' => $user->updated_at->toAtomString(),
|
||||||
'updated_at' => $user->updated_at->toAtomString(),
|
'email' => $user->email,
|
||||||
'email' => $user->email,
|
'blocked' => 1 === (int)$user->blocked,
|
||||||
'blocked' => 1 === (int)$user->blocked,
|
'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code,
|
||||||
'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code,
|
'role' => $this->repository->getRoleByUser($user),
|
||||||
'role' => $this->repository->getRoleByUser($user),
|
'links' => [
|
||||||
'links' => [
|
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'uri' => '/users/' . $user->id,
|
'uri' => '/users/' . $user->id,
|
||||||
|
@@ -34,6 +34,7 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* Trait ValidatesAdministrationAccess
|
* Trait ValidatesAdministrationAccess
|
||||||
*/
|
*/
|
||||||
trait ValidatesAdministrationAccess
|
trait ValidatesAdministrationAccess
|
||||||
@@ -45,6 +46,7 @@ trait ValidatesAdministrationAccess
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
protected function validateAdministration(Validator $validator, array $allowedRoles): void
|
protected function validateAdministration(Validator $validator, array $allowedRoles): void
|
||||||
{
|
{
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
"alpinejs": "^3.13.0",
|
"alpinejs": "^3.13.0",
|
||||||
"bootstrap": "^5.3.0",
|
"bootstrap": "^5.3.0",
|
||||||
"bootstrap5-autocomplete": "^1.1.20",
|
"bootstrap5-autocomplete": "^1.1.22",
|
||||||
"chart.js": "^4.4.0",
|
"chart.js": "^4.4.0",
|
||||||
"chartjs-adapter-date-fns": "^3.0.0",
|
"chartjs-adapter-date-fns": "^3.0.0",
|
||||||
"chartjs-chart-sankey": "^0.12.0",
|
"chartjs-chart-sankey": "^0.12.0",
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
"alpinejs": "^3.13.0",
|
"alpinejs": "^3.13.0",
|
||||||
"bootstrap": "^5.3.0",
|
"bootstrap": "^5.3.0",
|
||||||
"bootstrap5-autocomplete": "^1.1.20",
|
"bootstrap5-autocomplete": "^1.1.22",
|
||||||
"chart.js": "^4.4.0",
|
"chart.js": "^4.4.0",
|
||||||
"chartjs-adapter-date-fns": "^3.0.0",
|
"chartjs-adapter-date-fns": "^3.0.0",
|
||||||
"chartjs-chart-sankey": "^0.12.0",
|
"chartjs-chart-sankey": "^0.12.0",
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user