From 65acab4512df0208a93d46d39405c87fc77a2700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Falc=C3=B3n?= Date: Wed, 3 Jun 2026 17:29:23 +0200 Subject: [PATCH] refactor(requests): dedupe UpdateAutomationRuleRequest (#476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What `UpdateAutomationRuleRequest` was **byte-identical** to `StoreAutomationRuleRequest` (verified with `diff`): same `rules()`, `passedValidation()`, `withValidator()`. Now it simply extends the Store request. ## Stats - **-74 / +1 lines** ## Checks - `php artisan test --filter=AutomationRule` — 63 passed (211 assertions) - `vendor/bin/pint --dirty` — applied Part of duplication-removal series (#475 was first). --- .../Settings/UpdateAutomationRuleRequest.php | 75 +------------------ 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/app/Http/Requests/Settings/UpdateAutomationRuleRequest.php b/app/Http/Requests/Settings/UpdateAutomationRuleRequest.php index 747a4c08..777709e3 100644 --- a/app/Http/Requests/Settings/UpdateAutomationRuleRequest.php +++ b/app/Http/Requests/Settings/UpdateAutomationRuleRequest.php @@ -2,77 +2,4 @@ namespace App\Http\Requests\Settings; -use Illuminate\Contracts\Validation\ValidationRule; -use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rule; - -class UpdateAutomationRuleRequest extends FormRequest -{ - /** - * Determine if the user is authorized to make this request. - */ - public function authorize(): bool - { - return true; - } - - /** - * Get the validation rules that apply to the request. - * - * @return array|string> - */ - public function rules(): array - { - return [ - 'title' => ['required', 'string', 'max:255'], - 'priority' => ['required', 'integer', 'min:0'], - 'rules_json' => ['required', 'json', function ($attribute, $value, $fail) { - $decoded = json_decode($value, true); - if (! is_array($decoded) || empty($decoded)) { - $fail('The rules JSON must be a valid JsonLogic object.'); - } - }], - 'action_category_id' => [ - 'nullable', - 'string', - Rule::exists('categories', 'id')->where(function ($query) { - $query->where('user_id', auth()->id()); - }), - ], - 'action_note' => ['nullable', 'string'], - 'action_note_iv' => ['nullable', 'string', 'required_with:action_note'], - 'action_label_ids' => ['nullable', 'array'], - 'action_label_ids.*' => [ - 'required', - 'string', - 'uuid', - Rule::exists('labels', 'id')->where(function ($query) { - $query->where('user_id', auth()->id()); - }), - ], - ]; - } - - /** - * Decode the rules_json string into an array so the model's array cast doesn't double-encode it. - */ - protected function passedValidation(): void - { - $this->merge([ - 'rules_json' => json_decode($this->rules_json, true), - ]); - } - - /** - * Configure the validator instance. - */ - public function withValidator($validator): void - { - $validator->after(function ($validator) { - $hasLabels = ! empty($this->action_label_ids); - if (! $this->action_category_id && ! $hasLabels) { - $validator->errors()->add('action_category_id', 'At least one action (category or labels) must be provided.'); - } - }); - } -} +class UpdateAutomationRuleRequest extends StoreAutomationRuleRequest {}