Merge branch 'develop' into 5.8-dev

# Conflicts:
#	app/Http/Requests/RuleFormRequest.php
This commit is contained in:
James Cole 2022-12-28 06:51:59 +01:00
commit d3a619cb15
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
3 changed files with 105 additions and 62 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* RuleFormRequest.php * RuleFormRequest.php
* Copyright (c) 2019 james@firefly-iii.org * Copyright (c) 2019 james@firefly-iii.org
@ -69,19 +70,48 @@ class RuleFormRequest extends FormRequest
foreach ($triggerData as $trigger) { foreach ($triggerData as $trigger) {
$stopProcessing = $trigger['stop_processing'] ?? '0'; $stopProcessing = $trigger['stop_processing'] ?? '0';
$prohibited = $trigger['prohibited'] ?? '0'; $prohibited = $trigger['prohibited'] ?? '0';
$set = [ $set = [
'type' => $trigger['type'] ?? 'invalid', 'type' => $trigger['type'] ?? 'invalid',
'value' => $trigger['value'] ?? '', 'value' => $trigger['value'] ?? '',
'stop_processing' => 1 === (int) $stopProcessing, 'stop_processing' => 1 === (int)$stopProcessing,
'prohibited' => 1 === (int) $prohibited, 'prohibited' => 1 === (int)$prohibited,
]; ];
$return[] = $set; $set = self::replaceAmountTrigger($set);
$return[] = $set;
} }
} }
return $return; return $return;
} }
/**
* @param array $array
* @return array
*/
public static function replaceAmountTrigger(array $array): array
{
// do some sneaky search and replace.
$amountFields = [
'amount_is',
'amount',
'amount_exactly',
'amount_less',
'amount_max',
'amount_more',
'amount_min',
'foreign_amount_is',
'foreign_amount',
'foreign_amount_less',
'foreign_amount_max',
'foreign_amount_more',
'foreign_amount_min',
];
if (in_array($array['type'], $amountFields, true) && '0' === $array['value']) {
$array['value'] = '0.00';
}
return $array;
}
/** /**
* @return array * @return array
*/ */
@ -95,7 +125,7 @@ class RuleFormRequest extends FormRequest
$return[] = [ $return[] = [
'type' => $action['type'] ?? 'invalid', 'type' => $action['type'] ?? 'invalid',
'value' => $action['value'] ?? '', 'value' => $action['value'] ?? '',
'stop_processing' => 1 === (int) $stopProcessing, 'stop_processing' => 1 === (int)$stopProcessing,
]; ];
} }
} }
@ -126,9 +156,9 @@ class RuleFormRequest extends FormRequest
'stop_processing' => 'boolean', 'stop_processing' => 'boolean',
'rule_group_id' => 'required|belongsToUser:rule_groups', 'rule_group_id' => 'required|belongsToUser:rule_groups',
'trigger' => 'required|in:store-journal,update-journal', 'trigger' => 'required|in:store-journal,update-journal',
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers), 'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
'triggers.*.value' => sprintf('required_if:triggers.*.type,%s|min:1|ruleTriggerValue', $contextTriggers), 'triggers.*.value' => sprintf('required_if:triggers.*.type,%s|min:1|ruleTriggerValue', $contextTriggers),
'actions.*.type' => 'required|in:' . implode(',', $validActions), 'actions.*.type' => 'required|in:'.implode(',', $validActions),
'actions.*.value' => sprintf('required_if:actions.*.type,%s|min:0|max:255|ruleActionValue', $contextActions), 'actions.*.value' => sprintf('required_if:actions.*.type,%s|min:0|max:255|ruleActionValue', $contextActions),
'strict' => 'in:0,1', 'strict' => 'in:0,1',
]; ];
@ -137,7 +167,7 @@ class RuleFormRequest extends FormRequest
$rule = $this->route()->parameter('rule'); $rule = $this->route()->parameter('rule');
if (null !== $rule) { if (null !== $rule) {
$rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,' . $rule->id; $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,'.$rule->id;
} }
return $rules; return $rules;

View File

@ -27,6 +27,7 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Exceptions\ValidationException; use FireflyIII\Exceptions\ValidationException;
use FireflyIII\Helpers\Help\HelpInterface; use FireflyIII\Helpers\Help\HelpInterface;
use FireflyIII\Http\Requests\RuleFormRequest;
use FireflyIII\Http\Requests\TestRuleFormRequest; use FireflyIII\Http\Requests\TestRuleFormRequest;
use FireflyIII\Support\Binder\AccountList; use FireflyIII\Support\Binder\AccountList;
use FireflyIII\User; use FireflyIII\User;
@ -60,7 +61,7 @@ trait RequestInformation
/** /**
* Get a list of triggers. * Get a list of triggers.
* *
* @param TestRuleFormRequest $request * @param TestRuleFormRequest $request
* *
* @return array * @return array
*/ */
@ -70,14 +71,15 @@ trait RequestInformation
$data = $request->get('triggers'); $data = $request->get('triggers');
if (is_array($data)) { if (is_array($data)) {
foreach ($data as $triggerInfo) { foreach ($data as $triggerInfo) {
$triggers[] = [ $current = [
'type' => $triggerInfo['type'] ?? '', 'type' => $triggerInfo['type'] ?? '',
'value' => $triggerInfo['value'] ?? '', 'value' => $triggerInfo['value'] ?? '',
'stop_processing' => 1 === (int) ($triggerInfo['stop_processing'] ?? '0'), 'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'),
]; ];
$current = RuleFormRequest::replaceAmountTrigger($current);
$triggers[] = $current;
} }
} }
return $triggers; return $triggers;
} }
@ -127,13 +129,13 @@ trait RequestInformation
*/ */
final protected function getSpecificPageName(): string // get request info final protected function getSpecificPageName(): string // get request info
{ {
return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType'); return null === RouteFacade::current()->parameter('objectType') ? '' : '_'.RouteFacade::current()->parameter('objectType');
} }
/** /**
* Check if date is outside session range. * Check if date is outside session range.
* *
* @param Carbon $date * @param Carbon $date
* *
* @return bool * @return bool
* *
@ -159,7 +161,7 @@ trait RequestInformation
/** /**
* Parses attributes from URL * Parses attributes from URL
* *
* @param array $attributes * @param array $attributes
* *
* @return array * @return array
*/ */
@ -189,9 +191,9 @@ trait RequestInformation
/** /**
* Validate users new password. * Validate users new password.
* *
* @param User $user * @param User $user
* @param string $current * @param string $current
* @param string $new * @param string $new
* *
* @return bool * @return bool
* *
@ -200,11 +202,11 @@ trait RequestInformation
final protected function validatePassword(User $user, string $current, string $new): bool //get request info final protected function validatePassword(User $user, string $current, string $new): bool //get request info
{ {
if (!Hash::check($current, $user->password)) { if (!Hash::check($current, $user->password)) {
throw new ValidationException((string) trans('firefly.invalid_current_password')); throw new ValidationException((string)trans('firefly.invalid_current_password'));
} }
if ($current === $new) { if ($current === $new) {
throw new ValidationException((string) trans('firefly.should_change')); throw new ValidationException((string)trans('firefly.should_change'));
} }
return true; return true;
@ -213,7 +215,7 @@ trait RequestInformation
/** /**
* Get a validator for an incoming registration request. * Get a validator for an incoming registration request.
* *
* @param array $data * @param array $data
* *
* @return ValidatorContract * @return ValidatorContract
* @codeCoverageIgnore * @codeCoverageIgnore

93
composer.lock generated
View File

@ -5092,42 +5092,53 @@
}, },
{ {
"name": "ramsey/collection", "name": "ramsey/collection",
"version": "1.2.2", "version": "1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/ramsey/collection.git", "url": "https://github.com/ramsey/collection.git",
"reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a" "reference": "ad7475d1c9e70b190ecffc58f2d989416af339b4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/ramsey/collection/zipball/cccc74ee5e328031b15640b51056ee8d3bb66c0a", "url": "https://api.github.com/repos/ramsey/collection/zipball/ad7475d1c9e70b190ecffc58f2d989416af339b4",
"reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a", "reference": "ad7475d1c9e70b190ecffc58f2d989416af339b4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.3 || ^8", "php": "^7.4 || ^8.0",
"symfony/polyfill-php81": "^1.23" "symfony/polyfill-php81": "^1.23"
}, },
"require-dev": { "require-dev": {
"captainhook/captainhook": "^5.3", "captainhook/plugin-composer": "^5.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "ergebnis/composer-normalize": "^2.28.3",
"ergebnis/composer-normalize": "^2.6", "fakerphp/faker": "^1.21",
"fakerphp/faker": "^1.5", "hamcrest/hamcrest-php": "^2.0",
"hamcrest/hamcrest-php": "^2", "jangregor/phpstan-prophecy": "^1.0",
"jangregor/phpstan-prophecy": "^0.8", "mockery/mockery": "^1.5",
"mockery/mockery": "^1.3", "php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpcsstandards/phpcsutils": "^1.0.0-rc1",
"phpspec/prophecy-phpunit": "^2.0", "phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1", "phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^0.12.32", "phpstan/phpstan": "^1.9",
"phpstan/phpstan-mockery": "^0.12.5", "phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^0.12.11", "phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^8.5 || ^9", "phpunit/phpunit": "^9.5",
"psy/psysh": "^0.10.4", "psalm/plugin-mockery": "^1.1",
"slevomat/coding-standard": "^6.3", "psalm/plugin-phpunit": "^0.18.4",
"squizlabs/php_codesniffer": "^3.5", "ramsey/coding-standard": "^2.0.3",
"vimeo/psalm": "^4.4" "ramsey/conventional-commits": "^1.3",
"vimeo/psalm": "^5.4"
}, },
"type": "library", "type": "library",
"extra": {
"captainhook": {
"force-install": true
},
"ramsey/conventional-commits": {
"configFile": "conventional-commits.json"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Ramsey\\Collection\\": "src/" "Ramsey\\Collection\\": "src/"
@ -5155,7 +5166,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/ramsey/collection/issues", "issues": "https://github.com/ramsey/collection/issues",
"source": "https://github.com/ramsey/collection/tree/1.2.2" "source": "https://github.com/ramsey/collection/tree/1.3.0"
}, },
"funding": [ "funding": [
{ {
@ -5167,7 +5178,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-10-10T03:01:02+00:00" "time": "2022-12-27T19:12:24+00:00"
}, },
{ {
"name": "ramsey/uuid", "name": "ramsey/uuid",
@ -5465,16 +5476,16 @@
}, },
{ {
"name": "spatie/flare-client-php", "name": "spatie/flare-client-php",
"version": "1.3.1", "version": "1.3.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/spatie/flare-client-php.git", "url": "https://github.com/spatie/flare-client-php.git",
"reference": "ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8" "reference": "609903bd154ba3d71f5e23a91c3b431fa8f71868"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/spatie/flare-client-php/zipball/ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8", "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/609903bd154ba3d71f5e23a91c3b431fa8f71868",
"reference": "ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8", "reference": "609903bd154ba3d71f5e23a91c3b431fa8f71868",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5522,7 +5533,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/spatie/flare-client-php/issues", "issues": "https://github.com/spatie/flare-client-php/issues",
"source": "https://github.com/spatie/flare-client-php/tree/1.3.1" "source": "https://github.com/spatie/flare-client-php/tree/1.3.2"
}, },
"funding": [ "funding": [
{ {
@ -5530,7 +5541,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-11-16T08:30:20+00:00" "time": "2022-12-26T14:36:46+00:00"
}, },
{ {
"name": "spatie/ignition", "name": "spatie/ignition",
@ -5609,16 +5620,16 @@
}, },
{ {
"name": "spatie/laravel-ignition", "name": "spatie/laravel-ignition",
"version": "1.6.2", "version": "1.6.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/spatie/laravel-ignition.git", "url": "https://github.com/spatie/laravel-ignition.git",
"reference": "d6e1e1ad93abe280abf41c33f8ea7647dfc0c233" "reference": "2db918babd96f87b73fc26e4195f5a19328dd123"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/d6e1e1ad93abe280abf41c33f8ea7647dfc0c233", "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/2db918babd96f87b73fc26e4195f5a19328dd123",
"reference": "d6e1e1ad93abe280abf41c33f8ea7647dfc0c233", "reference": "2db918babd96f87b73fc26e4195f5a19328dd123",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5695,7 +5706,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-12-08T15:31:38+00:00" "time": "2022-12-26T15:13:03+00:00"
}, },
{ {
"name": "stella-maris/clock", "name": "stella-maris/clock",
@ -8392,16 +8403,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.4.3", "version": "v3.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58" "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58", "url": "https://api.github.com/repos/twigphp/Twig/zipball/3ffcf4b7d890770466da3b2666f82ac054e7ec72",
"reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58", "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -8416,7 +8427,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.4-dev" "dev-master": "3.5-dev"
} }
}, },
"autoload": { "autoload": {
@ -8452,7 +8463,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.4.3" "source": "https://github.com/twigphp/Twig/tree/v3.5.0"
}, },
"funding": [ "funding": [
{ {
@ -8464,7 +8475,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-09-28T08:42:51+00:00" "time": "2022-12-27T12:28:18+00:00"
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",