mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Update request must also have valid triggers and actions.
This commit is contained in:
@@ -167,7 +167,9 @@ class UpdateRequest extends FormRequest
|
|||||||
$validator->after(
|
$validator->after(
|
||||||
function (Validator $validator) {
|
function (Validator $validator) {
|
||||||
$this->atLeastOneTrigger($validator);
|
$this->atLeastOneTrigger($validator);
|
||||||
|
$this->atLeastOneValidTrigger($validator);
|
||||||
$this->atLeastOneAction($validator);
|
$this->atLeastOneAction($validator);
|
||||||
|
$this->atLeastOneValidAction($validator);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -187,6 +189,35 @@ class UpdateRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
|
*/
|
||||||
|
protected function atLeastOneValidTrigger(Validator $validator): void
|
||||||
|
{
|
||||||
|
$data = $validator->getData();
|
||||||
|
$triggers = $data['triggers'] ?? [];
|
||||||
|
$allInactive = true;
|
||||||
|
$inactiveIndex = 0;
|
||||||
|
// need at least one trigger
|
||||||
|
if (is_array($triggers) && empty($triggers)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach ($triggers as $index => $trigger) {
|
||||||
|
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true; // assume true
|
||||||
|
if (true === $active) {
|
||||||
|
$allInactive = false;
|
||||||
|
}
|
||||||
|
if (false === $active) {
|
||||||
|
$inactiveIndex = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (true === $allInactive) {
|
||||||
|
$validator->errors()->add(sprintf('triggers.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_trigger'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
*
|
*
|
||||||
@@ -201,4 +232,34 @@ class UpdateRequest extends FormRequest
|
|||||||
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
|
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
|
*/
|
||||||
|
protected function atLeastOneValidAction(Validator $validator): void
|
||||||
|
{
|
||||||
|
$data = $validator->getData();
|
||||||
|
$actions = $data['actions'] ?? [];
|
||||||
|
$allInactive = true;
|
||||||
|
$inactiveIndex = 0;
|
||||||
|
// need at least one action
|
||||||
|
if (is_array($actions) && empty($actions)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($actions as $index => $action) {
|
||||||
|
$active = array_key_exists('active', $action) ? $action['active'] : true; // assume true
|
||||||
|
if (true === $active) {
|
||||||
|
$allInactive = false;
|
||||||
|
}
|
||||||
|
if (false === $active) {
|
||||||
|
$inactiveIndex = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (true === $allInactive) {
|
||||||
|
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user