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
3 changed files with 105 additions and 62 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* RuleFormRequest.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -69,19 +70,48 @@ class RuleFormRequest extends FormRequest
foreach ($triggerData as $trigger) {
$stopProcessing = $trigger['stop_processing'] ?? '0';
$prohibited = $trigger['prohibited'] ?? '0';
$set = [
$set = [
'type' => $trigger['type'] ?? 'invalid',
'value' => $trigger['value'] ?? '',
'stop_processing' => 1 === (int) $stopProcessing,
'prohibited' => 1 === (int) $prohibited,
'stop_processing' => 1 === (int)$stopProcessing,
'prohibited' => 1 === (int)$prohibited,
];
$return[] = $set;
$set = self::replaceAmountTrigger($set);
$return[] = $set;
}
}
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
*/
@@ -95,7 +125,7 @@ class RuleFormRequest extends FormRequest
$return[] = [
'type' => $action['type'] ?? 'invalid',
'value' => $action['value'] ?? '',
'stop_processing' => 1 === (int) $stopProcessing,
'stop_processing' => 1 === (int)$stopProcessing,
];
}
}
@@ -126,9 +156,9 @@ class RuleFormRequest extends FormRequest
'stop_processing' => 'boolean',
'rule_group_id' => 'required|belongsToUser:rule_groups',
'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),
'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),
'strict' => 'in:0,1',
];
@@ -137,7 +167,7 @@ class RuleFormRequest extends FormRequest
$rule = $this->route()->parameter('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;

View File

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