Auto commit for release 'develop' on 2024-08-05

This commit is contained in:
github-actions 2024-08-05 20:37:29 +02:00
parent 0c9a41a929
commit d98d757f8b
11 changed files with 94 additions and 106 deletions

View File

@ -68,13 +68,10 @@ class Handler extends ExceptionHandler
JsonApiException::class, JsonApiException::class,
]; ];
/** /**
* Register the exception handling callbacks for the application. * Register the exception handling callbacks for the application.
*
* @return void
*/ */
public function register() public function register(): void
{ {
$this->renderable( $this->renderable(
ExceptionParser::make()->renderable() ExceptionParser::make()->renderable()
@ -98,11 +95,13 @@ class Handler extends ExceptionHandler
app('log')->debug('Now in Handler::render()'); app('log')->debug('Now in Handler::render()');
if($e instanceof JsonApiException) { if ($e instanceof JsonApiException) {
// ignore it: controller will handle it. // ignore it: controller will handle it.
app('log')->debug(sprintf('Return to parent to handle JsonApiException(%d)', $e->getCode() app('log')->debug(sprintf(
)); 'Return to parent to handle JsonApiException(%d)',
$e->getCode()
));
return parent::render($request, $e); return parent::render($request, $e);
} }

View File

@ -102,8 +102,6 @@ class AccountRepository extends AbstractRepository implements QueriesAll, Create
/** /**
* TODO piggy banks * TODO piggy banks
* TODO transactions * TODO transactions
*
* @return CrudRelations
*/ */
protected function relations(): CrudRelations protected function relations(): CrudRelations
{ {

View File

@ -9,7 +9,6 @@ use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsValidPositiveAmount; use FireflyIII\Rules\IsValidPositiveAmount;
use FireflyIII\Rules\UniqueAccountNumber; use FireflyIII\Rules\UniqueAccountNumber;
use FireflyIII\Rules\UniqueIban; use FireflyIII\Rules\UniqueIban;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest; use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest;
@ -25,33 +24,32 @@ class AccountRequest extends ResourceRequest
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes'))); $ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier'))); $types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
$type = $this->convertString('type'); $type = $this->convertString('type');
//var_dump($types);exit; // var_dump($types);exit;
return [ return [
'name' => ['required', 'max:1024', 'min:1'], // , new IsUniqueAccount() 'name' => ['required', 'max:1024', 'min:1'], // , new IsUniqueAccount()
'account_type' => ['required','max:1024','min:1', sprintf('in:%s', $types)], 'account_type' => ['required', 'max:1024', 'min:1', sprintf('in:%s', $types)],
// 'iban' => ['iban', 'nullable', new UniqueIban(null, $type)], // 'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
// 'bic' => 'bic|nullable', // 'bic' => 'bic|nullable',
// 'account_number' => ['min:1', 'max:255', 'nullable', new UniqueAccountNumber(null, $type)], // 'account_number' => ['min:1', 'max:255', 'nullable', new UniqueAccountNumber(null, $type)],
// 'opening_balance' => 'numeric|required_with:opening_balance_date|nullable', // 'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
// 'opening_balance_date' => 'date|required_with:opening_balance|nullable', // 'opening_balance_date' => 'date|required_with:opening_balance|nullable',
// 'virtual_balance' => 'numeric|nullable', // 'virtual_balance' => 'numeric|nullable',
// 'order' => 'numeric|nullable', // 'order' => 'numeric|nullable',
// 'currency_id' => 'numeric|exists:transaction_currencies,id', // 'currency_id' => 'numeric|exists:transaction_currencies,id',
// 'currency_code' => 'min:3|max:3|exists:transaction_currencies,code', // 'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
// 'active' => [new IsBoolean()], // 'active' => [new IsBoolean()],
// 'include_net_worth' => [new IsBoolean()], // 'include_net_worth' => [new IsBoolean()],
// 'account_role' => sprintf('nullable|in:%s|required_if:type,asset', $accountRoles), // 'account_role' => sprintf('nullable|in:%s|required_if:type,asset', $accountRoles),
// 'credit_card_type' => sprintf('nullable|in:%s|required_if:account_role,ccAsset', $ccPaymentTypes), // 'credit_card_type' => sprintf('nullable|in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),
// 'monthly_payment_date' => 'nullable|date|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull', // 'monthly_payment_date' => 'nullable|date|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
// 'liability_type' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:loan,debt,mortgage', // 'liability_type' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:loan,debt,mortgage',
// 'liability_amount' => ['required_with:liability_start_date', new IsValidPositiveAmount()], // 'liability_amount' => ['required_with:liability_start_date', new IsValidPositiveAmount()],
// 'liability_start_date' => 'required_with:liability_amount|date', // 'liability_start_date' => 'required_with:liability_amount|date',
// 'liability_direction' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:credit,debit', // 'liability_direction' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:credit,debit',
// 'interest' => 'min:0|max:100|numeric', // 'interest' => 'min:0|max:100|numeric',
// 'interest_period' => sprintf('nullable|in:%s', implode(',', config('firefly.interest_periods'))), // 'interest_period' => sprintf('nullable|in:%s', implode(',', config('firefly.interest_periods'))),
// 'notes' => 'min:0|max:32768', // 'notes' => 'min:0|max:32768',
]; ];
} }
} }

View File

@ -60,7 +60,7 @@ class AccountSchema extends Schema
Attribute::make('liability_direction'), Attribute::make('liability_direction'),
Attribute::make('interest'), Attribute::make('interest'),
Attribute::make('interest_period'), Attribute::make('interest_period'),
//Attribute::make('current_debt')->sortable(), // Attribute::make('current_debt')->sortable(),
// TODO credit card fields. // TODO credit card fields.

View File

@ -51,7 +51,10 @@ class CrudAccount extends CrudResource
return $enrichment->enrichSingle($account); return $enrichment->enrichSingle($account);
} }
public function create(array $validatedData): Account { public function create(array $validatedData): Account
var_dump($validatedData);exit; {
var_dump($validatedData);
exit;
} }
} }

View File

@ -37,7 +37,8 @@ class AccountPolicy
return auth()->check() && $user->id === $account->user_id; return auth()->check() && $user->id === $account->user_id;
} }
public function create(): bool { public function create(): bool
{
return auth()->check(); return auth()->check();
} }

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Rules\Account; namespace FireflyIII\Rules\Account;
use Closure;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\User; use FireflyIII\User;
@ -35,20 +34,19 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/ */
class IsUniqueAccount implements ValidationRule, DataAwareRule class IsUniqueAccount implements ValidationRule, DataAwareRule
{ {
protected Closure $fail; protected \Closure $fail;
protected array $data = []; protected array $data = [];
/** #[\Override]
* @inheritDoc public function validate(string $attribute, mixed $value, \Closure $fail): void
*/
#[\Override] public function validate(string $attribute, mixed $value, Closure $fail): void
{ {
return; return;
$this->fail = $fail; $this->fail = $fail;
// because a user does not have to be logged in (tests and what-not). // because a user does not have to be logged in (tests and what-not).
if (!auth()->check()) { if (!auth()->check()) {
app('log')->debug('validateUniqueAccountForUser::anon'); app('log')->debug('validateUniqueAccountForUser::anon');
$fail('validation.nog_logged_in')->translate(); $fail('validation.nog_logged_in')->translate();
return; return;
} }
if (array_key_exists('type', $this->data)) { if (array_key_exists('type', $this->data)) {
@ -77,22 +75,15 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
app('log')->debug('validateUniqueAccountForUser::accountName'); app('log')->debug('validateUniqueAccountForUser::accountName');
$this->validateByAccountName($value); $this->validateByAccountName($value);
} }
/** /**
* TODO duplicate from old validation class. * TODO duplicate from old validation class.
*
* @param string $value
* @param array $parameters
* @param string $type
*
* @return bool
*/ */
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
{ {
/** @var null|array $search */ /** @var null|array $search */
$search = config('firefly.accountTypeByIdentifier.%s', $type); $search = config('firefly.accountTypeByIdentifier.%s', $type);
if (null === $search) { if (null === $search) {
return false; return false;
@ -103,17 +94,16 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
$accountTypeIds = $accountTypes->pluck('id')->toArray(); $accountTypeIds = $accountTypes->pluck('id')->toArray();
/** @var null|Account $result */ /** @var null|Account $result */
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore) $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first(); ->first()
;
return null === $result; return null === $result;
} }
/** /**
* TODO duplicate from old validation class. * TODO duplicate from old validation class.
*
* @return void
*/ */
private function validateAccountAnonymously(): void private function validateAccountAnonymously(): void
{ {
@ -122,9 +112,9 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
} }
/** @var User $user */ /** @var User $user */
$user = User::find($this->data['user_id']); $user = User::find($this->data['user_id']);
$type = AccountType::find($this->data['account_type_id'])->first(); $type = AccountType::find($this->data['account_type_id'])->first();
$value = $this->data['name']; $value = $this->data['name'];
/** @var null|Account $result */ /** @var null|Account $result */
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first(); $result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
@ -145,8 +135,9 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** @var null|Account $result */ /** @var null|Account $result */
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first(); ->first()
;
return null === $result; return null === $result;
} }
@ -161,12 +152,13 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** @var Account $existingAccount */ /** @var Account $existingAccount */
$existingAccount = Account::find($accountId); $existingAccount = Account::find($accountId);
$type = $existingAccount->accountType; $type = $existingAccount->accountType;
$ignore = $existingAccount->id; $ignore = $existingAccount->id;
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first(); ->first()
;
return null === $entry; return null === $entry;
} }
@ -181,12 +173,13 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** @var Account $existingAccount */ /** @var Account $existingAccount */
$existingAccount = Account::find($this->data['id']); $existingAccount = Account::find($this->data['id']);
$type = $existingAccount->accountType; $type = $existingAccount->accountType;
$ignore = $existingAccount->id; $ignore = $existingAccount->id;
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first(); ->first()
;
return null === $entry; return null === $entry;
} }
@ -194,20 +187,14 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** /**
* TODO is duplicate * TODO is duplicate
* TODO does not take group into account. Must be made group aware. * TODO does not take group into account. Must be made group aware.
*
* @param string $value
*
* @return bool
*/ */
private function validateByAccountName(string $value): bool private function validateByAccountName(string $value): bool
{ {
return 0 === auth()->user()->accounts()->where('name', $value)->count(); return 0 === auth()->user()->accounts()->where('name', $value)->count();
} }
/** #[\Override]
* @inheritDoc public function setData(array $data): void
*/
#[\Override] public function setData(array $data): void
{ {
$this->data = $data; $this->data = $data;
} }

View File

@ -44,7 +44,7 @@ class Steam
*/ */
public function balanceIgnoreVirtual(Account $account, Carbon $date): string public function balanceIgnoreVirtual(Account $account, Carbon $date): string
{ {
//Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__)); // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$repository->setUser($account->user); $repository->setUser($account->user);
@ -95,8 +95,8 @@ class Steam
*/ */
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
{ {
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__)); // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($account->id); $cache->addProperty($account->id);
$cache->addProperty('balance-in-range'); $cache->addProperty('balance-in-range');
$cache->addProperty(null !== $currency ? $currency->id : 0); $cache->addProperty(null !== $currency ? $currency->id : 0);
@ -220,7 +220,7 @@ class Steam
*/ */
public function balance(Account $account, Carbon $date, ?TransactionCurrency $currency = null): string public function balance(Account $account, Carbon $date, ?TransactionCurrency $currency = null): string
{ {
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__)); // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
// abuse chart properties: // abuse chart properties:
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($account->id); $cache->addProperty($account->id);
@ -395,7 +395,7 @@ class Steam
*/ */
public function balanceConverted(Account $account, Carbon $date, TransactionCurrency $native): string public function balanceConverted(Account $account, Carbon $date, TransactionCurrency $native): string
{ {
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__)); // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
Log::debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code)); Log::debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($account->id); $cache->addProperty($account->id);
@ -632,7 +632,7 @@ class Steam
public function balancePerCurrency(Account $account, Carbon $date): array public function balancePerCurrency(Account $account, Carbon $date): array
{ {
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__)); // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
// abuse chart properties: // abuse chart properties:
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($account->id); $cache->addProperty($account->id);

12
package-lock.json generated
View File

@ -4011,9 +4011,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001647", "version": "1.0.30001649",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001647.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001649.tgz",
"integrity": "sha512-n83xdNiyeNcHpzWY+1aFbqCK7LuLfBricc4+alSQL2Xb6OR3XpnQAmlDG+pQcdTfiHRuLcQ96VOfrPSGiNJYSg==", "integrity": "sha512-fJegqZZ0ZX8HOWr6rcafGr72+xcgJKI9oWfDW5DrD7ExUtgZC7a7R7ZYmZqplh7XDocFdGeIFn7roAxhOeYrPQ==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -6966,9 +6966,9 @@
} }
}, },
"node_modules/launch-editor": { "node_modules/launch-editor": {
"version": "2.8.0", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.8.0.tgz", "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.8.1.tgz",
"integrity": "sha512-vJranOAJrI/llyWGRQqiDM+adrw+k83fvmmx3+nV47g3+36xM15jE+zyZ6Ffel02+xSvuM0b2GDRosXZkbb6wA==", "integrity": "sha512-elBx2l/tp9z99X5H/qev8uyDywVh0VXAwEbjk8kJhnc5grOFkGh7aW6q55me9xnYbss261XtnUrysZ+XvGbhQA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"picocolors": "^1.0.0", "picocolors": "^1.0.0",

View File

@ -28,7 +28,7 @@ return [
'filter_must_be_in' => 'Filter ":filter" must be one of: :values', 'filter_must_be_in' => 'Filter ":filter" must be one of: :values',
'filter_not_string' => 'Filter ":filter" is expected to be a string of text', 'filter_not_string' => 'Filter ":filter" is expected to be a string of text',
'bad_api_filter' => 'This API endpoint does not support ":filter" as a filter.', 'bad_api_filter' => 'This API endpoint does not support ":filter" as a filter.',
'nog_logged_in' => 'You are not logged in.', 'nog_logged_in' => 'You are not logged in.',
'bad_type_source' => 'Firefly III can\'t determine the transaction type based on this source account.', 'bad_type_source' => 'Firefly III can\'t determine the transaction type based on this source account.',
'bad_type_destination' => 'Firefly III can\'t determine the transaction type based on this destination account.', 'bad_type_destination' => 'Firefly III can\'t determine the transaction type based on this destination account.',
'missing_where' => 'Array is missing "where"-clause', 'missing_where' => 'Array is missing "where"-clause',

View File

@ -241,18 +241,20 @@ Route::group(
// V2 JSON API ROUTES // V2 JSON API ROUTES
JsonApiRoute::server('v2')->prefix('v2') JsonApiRoute::server('v2')->prefix('v2')
->resources(function (ResourceRegistrar $server): void { ->resources(function (ResourceRegistrar $server): void {
// ACCOUNTS // ACCOUNTS
$server->resource('accounts', AccountController::class) $server->resource('accounts', AccountController::class)
->relationships(function (Relationships $relations): void { ->relationships(function (Relationships $relations): void {
$relations->hasOne('user')->readOnly(); $relations->hasOne('user')->readOnly();
}); })
;
// USERS // USERS
$server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations): void { $server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations): void {
$relations->hasMany('accounts')->readOnly(); $relations->hasMany('accounts')->readOnly();
}); });
}); })
;
/* /*
* ____ ____ __ .______ ______ __ __ .___________. _______ _______. * ____ ____ __ .______ ______ __ __ .___________. _______ _______.