Skip to content

Firefly III: a personal finances manager

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

github-actionsd98d757f8b32
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
index 7277fce1b0..0086841f41 100644
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -68,13 +68,10 @@ class Handler extends ExceptionHandler
JsonApiException::class,
];
-
/**
* Register the exception handling callbacks for the application.
- *
- * @return void
*/
- public function register()
+ public function register(): void
{
$this->renderable(
ExceptionParser::make()->renderable()
@@ -98,11 +95,13 @@ class Handler extends ExceptionHandler
app('log')->debug('Now in Handler::render()');
- if($e instanceof JsonApiException) {
+ if ($e instanceof JsonApiException) {
// 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);
}
diff --git a/app/JsonApi/V2/Accounts/AccountRepository.php b/app/JsonApi/V2/Accounts/AccountRepository.php
index a39958cd29..f0e5f73e00 100644
--- a/app/JsonApi/V2/Accounts/AccountRepository.php
+++ b/app/JsonApi/V2/Accounts/AccountRepository.php
@@ -102,8 +102,6 @@ class AccountRepository extends AbstractRepository implements QueriesAll, Create
/**
* TODO piggy banks
* TODO transactions
- *
- * @return CrudRelations
*/
protected function relations(): CrudRelations
{
diff --git a/app/JsonApi/V2/Accounts/AccountRequest.php b/app/JsonApi/V2/Accounts/AccountRequest.php
index 251d91c33e..07e2498ee9 100644
--- a/app/JsonApi/V2/Accounts/AccountRequest.php
+++ b/app/JsonApi/V2/Accounts/AccountRequest.php
@@ -9,7 +9,6 @@ use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsValidPositiveAmount;
use FireflyIII\Rules\UniqueAccountNumber;
use FireflyIII\Rules\UniqueIban;
-use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Support\Facades\Log;
use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest;
@@ -25,33 +24,32 @@ class AccountRequest extends ResourceRequest
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
$type = $this->convertString('type');
- //var_dump($types);exit;
+ // var_dump($types);exit;
return [
- 'name' => ['required', 'max:1024', 'min:1'], // , new IsUniqueAccount()
- 'account_type' => ['required','max:1024','min:1', sprintf('in:%s', $types)],
-// 'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
-// 'bic' => 'bic|nullable',
-// 'account_number' => ['min:1', 'max:255', 'nullable', new UniqueAccountNumber(null, $type)],
-// 'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
-// 'opening_balance_date' => 'date|required_with:opening_balance|nullable',
-// 'virtual_balance' => 'numeric|nullable',
-// 'order' => 'numeric|nullable',
-// 'currency_id' => 'numeric|exists:transaction_currencies,id',
-// 'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
-// 'active' => [new IsBoolean()],
-// 'include_net_worth' => [new IsBoolean()],
-// 'account_role' => sprintf('nullable|in:%s|required_if:type,asset', $accountRoles),
-// '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',
-// '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_start_date' => 'required_with:liability_amount|date',
-// 'liability_direction' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:credit,debit',
-// 'interest' => 'min:0|max:100|numeric',
-// 'interest_period' => sprintf('nullable|in:%s', implode(',', config('firefly.interest_periods'))),
-// 'notes' => 'min:0|max:32768',
-
+ 'name' => ['required', 'max:1024', 'min:1'], // , new IsUniqueAccount()
+ 'account_type' => ['required', 'max:1024', 'min:1', sprintf('in:%s', $types)],
+ // 'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
+ // 'bic' => 'bic|nullable',
+ // 'account_number' => ['min:1', 'max:255', 'nullable', new UniqueAccountNumber(null, $type)],
+ // 'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
+ // 'opening_balance_date' => 'date|required_with:opening_balance|nullable',
+ // 'virtual_balance' => 'numeric|nullable',
+ // 'order' => 'numeric|nullable',
+ // 'currency_id' => 'numeric|exists:transaction_currencies,id',
+ // 'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
+ // 'active' => [new IsBoolean()],
+ // 'include_net_worth' => [new IsBoolean()],
+ // 'account_role' => sprintf('nullable|in:%s|required_if:type,asset', $accountRoles),
+ // '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',
+ // '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_start_date' => 'required_with:liability_amount|date',
+ // 'liability_direction' => 'nullable|required_if:type,liability|required_if:type,liabilities|in:credit,debit',
+ // 'interest' => 'min:0|max:100|numeric',
+ // 'interest_period' => sprintf('nullable|in:%s', implode(',', config('firefly.interest_periods'))),
+ // 'notes' => 'min:0|max:32768',
];
}
}
diff --git a/app/JsonApi/V2/Accounts/AccountSchema.php b/app/JsonApi/V2/Accounts/AccountSchema.php
index c7d358983b..ad26c027dc 100644
--- a/app/JsonApi/V2/Accounts/AccountSchema.php
+++ b/app/JsonApi/V2/Accounts/AccountSchema.php
@@ -60,7 +60,7 @@ class AccountSchema extends Schema
Attribute::make('liability_direction'),
Attribute::make('interest'),
Attribute::make('interest_period'),
- //Attribute::make('current_debt')->sortable(),
+ // Attribute::make('current_debt')->sortable(),
// TODO credit card fields.
diff --git a/app/JsonApi/V2/Accounts/Capabilities/CrudAccount.php b/app/JsonApi/V2/Accounts/Capabilities/CrudAccount.php
index 9d524a94ef..cf9d50d72b 100644
--- a/app/JsonApi/V2/Accounts/Capabilities/CrudAccount.php
+++ b/app/JsonApi/V2/Accounts/Capabilities/CrudAccount.php
@@ -51,7 +51,10 @@ class CrudAccount extends CrudResource
return $enrichment->enrichSingle($account);
}
- public function create(array $validatedData): Account {
- var_dump($validatedData);exit;
+ public function create(array $validatedData): Account
+ {
+ var_dump($validatedData);
+
+ exit;
}
}
diff --git a/app/Policies/AccountPolicy.php b/app/Policies/AccountPolicy.php
index 296bb25b4b..7c2b4fae03 100644
--- a/app/Policies/AccountPolicy.php
+++ b/app/Policies/AccountPolicy.php
@@ -37,7 +37,8 @@ class AccountPolicy
return auth()->check() && $user->id === $account->user_id;
}
- public function create(): bool {
+ public function create(): bool
+ {
return auth()->check();
}
diff --git a/app/Rules/Account/IsUniqueAccount.php b/app/Rules/Account/IsUniqueAccount.php
index e8fba9ab04..4daa56b034 100644
--- a/app/Rules/Account/IsUniqueAccount.php
+++ b/app/Rules/Account/IsUniqueAccount.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Rules\Account;
-use Closure;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\User;
@@ -35,20 +34,19 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsUniqueAccount implements ValidationRule, DataAwareRule
{
- protected Closure $fail;
+ protected \Closure $fail;
protected array $data = [];
- /**
- * @inheritDoc
- */
- #[\Override] public function validate(string $attribute, mixed $value, Closure $fail): void
+ #[\Override]
+ public function validate(string $attribute, mixed $value, \Closure $fail): void
{
return;
- $this->fail = $fail;
+ $this->fail = $fail;
// because a user does not have to be logged in (tests and what-not).
if (!auth()->check()) {
app('log')->debug('validateUniqueAccountForUser::anon');
$fail('validation.nog_logged_in')->translate();
+
return;
}
if (array_key_exists('type', $this->data)) {
@@ -77,22 +75,15 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
app('log')->debug('validateUniqueAccountForUser::accountName');
$this->validateByAccountName($value);
-
}
/**
* 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
{
/** @var null|array $search */
- $search = config('firefly.accountTypeByIdentifier.%s', $type);
+ $search = config('firefly.accountTypeByIdentifier.%s', $type);
if (null === $search) {
return false;
@@ -103,17 +94,16 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
$accountTypeIds = $accountTypes->pluck('id')->toArray();
/** @var null|Account $result */
- $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
- ->where('name', $value)
- ->first();
+ $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
+ ->where('name', $value)
+ ->first()
+ ;
return null === $result;
}
/**
* TODO duplicate from old validation class.
- *
- * @return void
*/
private function validateAccountAnonymously(): void
{
@@ -122,9 +112,9 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
}
/** @var User $user */
- $user = User::find($this->data['user_id']);
- $type = AccountType::find($this->data['account_type_id'])->first();
- $value = $this->data['name'];
+ $user = User::find($this->data['user_id']);
+ $type = AccountType::find($this->data['account_type_id'])->first();
+ $value = $this->data['name'];
/** @var null|Account $result */
$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 */
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
- ->where('name', $value)
- ->first();
+ ->where('name', $value)
+ ->first()
+ ;
return null === $result;
}
@@ -161,12 +152,13 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** @var Account $existingAccount */
$existingAccount = Account::find($accountId);
- $type = $existingAccount->accountType;
- $ignore = $existingAccount->id;
+ $type = $existingAccount->accountType;
+ $ignore = $existingAccount->id;
- $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
- ->where('name', $value)
- ->first();
+ $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
+ ->where('name', $value)
+ ->first()
+ ;
return null === $entry;
}
@@ -181,12 +173,13 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/** @var Account $existingAccount */
$existingAccount = Account::find($this->data['id']);
- $type = $existingAccount->accountType;
- $ignore = $existingAccount->id;
+ $type = $existingAccount->accountType;
+ $ignore = $existingAccount->id;
- $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
- ->where('name', $value)
- ->first();
+ $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
+ ->where('name', $value)
+ ->first()
+ ;
return null === $entry;
}
@@ -194,20 +187,14 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
/**
* TODO is duplicate
* TODO does not take group into account. Must be made group aware.
- *
- * @param string $value
- *
- * @return bool
*/
private function validateByAccountName(string $value): bool
{
return 0 === auth()->user()->accounts()->where('name', $value)->count();
}
- /**
- * @inheritDoc
- */
- #[\Override] public function setData(array $data): void
+ #[\Override]
+ public function setData(array $data): void
{
$this->data = $data;
}
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index a03b2185fc..ebae5cb468 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -44,7 +44,7 @@ class Steam
*/
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 */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($account->user);
@@ -95,8 +95,8 @@ class Steam
*/
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
{
-// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
- $cache = new CacheProperties();
+ // Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
+ $cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty('balance-in-range');
$cache->addProperty(null !== $currency ? $currency->id : 0);
@@ -220,7 +220,7 @@ class Steam
*/
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:
$cache = new CacheProperties();
$cache->addProperty($account->id);
@@ -395,7 +395,7 @@ class Steam
*/
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));
$cache = new CacheProperties();
$cache->addProperty($account->id);
@@ -632,7 +632,7 @@ class Steam
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:
$cache = new CacheProperties();
$cache->addProperty($account->id);
diff --git a/package-lock.json b/package-lock.json
index 6d5281b54b..7acf9cecbe 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4011,9 +4011,9 @@
}
},
"node_modules/caniuse-lite": {
- "version": "1.0.30001647",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001647.tgz",
- "integrity": "sha512-n83xdNiyeNcHpzWY+1aFbqCK7LuLfBricc4+alSQL2Xb6OR3XpnQAmlDG+pQcdTfiHRuLcQ96VOfrPSGiNJYSg==",
+ "version": "1.0.30001649",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001649.tgz",
+ "integrity": "sha512-fJegqZZ0ZX8HOWr6rcafGr72+xcgJKI9oWfDW5DrD7ExUtgZC7a7R7ZYmZqplh7XDocFdGeIFn7roAxhOeYrPQ==",
"dev": true,
"funding": [
{
@@ -6966,9 +6966,9 @@
}
},
"node_modules/launch-editor": {
- "version": "2.8.0",
- "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.8.0.tgz",
- "integrity": "sha512-vJranOAJrI/llyWGRQqiDM+adrw+k83fvmmx3+nV47g3+36xM15jE+zyZ6Ffel02+xSvuM0b2GDRosXZkbb6wA==",
+ "version": "2.8.1",
+ "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.8.1.tgz",
+ "integrity": "sha512-elBx2l/tp9z99X5H/qev8uyDywVh0VXAwEbjk8kJhnc5grOFkGh7aW6q55me9xnYbss261XtnUrysZ+XvGbhQA==",
"dev": true,
"dependencies": {
"picocolors": "^1.0.0",
diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php
index 2a9df099fc..7a0bc452dc 100644
--- a/resources/lang/en_US/validation.php
+++ b/resources/lang/en_US/validation.php
@@ -28,7 +28,7 @@ return [
'filter_must_be_in' => 'Filter ":filter" must be one of: :values',
'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.',
- '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_destination' => 'Firefly III can\'t determine the transaction type based on this destination account.',
'missing_where' => 'Array is missing "where"-clause',
diff --git a/routes/api.php b/routes/api.php
index 74ac5b7dcb..c4403f67c3 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -241,18 +241,20 @@ Route::group(
// V2 JSON API ROUTES
JsonApiRoute::server('v2')->prefix('v2')
- ->resources(function (ResourceRegistrar $server): void {
- // ACCOUNTS
- $server->resource('accounts', AccountController::class)
- ->relationships(function (Relationships $relations): void {
- $relations->hasOne('user')->readOnly();
- });
-
- // USERS
- $server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations): void {
- $relations->hasMany('accounts')->readOnly();
- });
- });
+ ->resources(function (ResourceRegistrar $server): void {
+ // ACCOUNTS
+ $server->resource('accounts', AccountController::class)
+ ->relationships(function (Relationships $relations): void {
+ $relations->hasOne('user')->readOnly();
+ })
+ ;
+
+ // USERS
+ $server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations): void {
+ $relations->hasMany('accounts')->readOnly();
+ });
+ })
+;
/*
* ____ ____ __ .______ ______ __ __ .___________. _______ _______.