diff --git a/app/Http/Requests/Admin/Nodes/Isos/StoreIsoRequest.php b/app/Http/Requests/Admin/Nodes/Isos/StoreIsoRequest.php index d68426bcf16..c1a170eb97e 100644 --- a/app/Http/Requests/Admin/Nodes/Isos/StoreIsoRequest.php +++ b/app/Http/Requests/Admin/Nodes/Isos/StoreIsoRequest.php @@ -29,11 +29,18 @@ public function rules(): array return $rules; } - public function withValidator(Validator $validator) + public function after(): array { + $rules = [ + function (Validator $validator) { + if (ISO::where('file_name', $this->string('file_name'))->exists()) { + $validator->errors()->add('file_name', __('validation.unique', ['attribute' => 'file name'])); + } + } + ]; if (!$this->boolean('should_download')) { - $validator->after(function (Validator $validator) { + $rules[] = function (Validator $validator) { $node = $this->parameter('node', Node::class); $iso = app(IsoService::class)->getIso($node, $this->input('file_name')); @@ -41,7 +48,9 @@ public function withValidator(Validator $validator) if (is_null($iso)) { $validator->errors()->add('file_name', 'This ISO doesn\'t exist.'); } - }); + }; } + + return $rules; } } diff --git a/app/Http/Requests/Admin/Nodes/Isos/UpdateIsoRequest.php b/app/Http/Requests/Admin/Nodes/Isos/UpdateIsoRequest.php index c81533f0b03..459638ad06d 100644 --- a/app/Http/Requests/Admin/Nodes/Isos/UpdateIsoRequest.php +++ b/app/Http/Requests/Admin/Nodes/Isos/UpdateIsoRequest.php @@ -7,19 +7,6 @@ class UpdateIsoRequest 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 - */ public function rules(): array { $rules = ISO::getRulesForUpdate($this->parameter('iso', ISO::class)); diff --git a/app/Models/ISO.php b/app/Models/ISO.php index 0a0ece7a39a..ac50bf0f8c1 100644 --- a/app/Models/ISO.php +++ b/app/Models/ISO.php @@ -24,7 +24,7 @@ class ISO extends Model 'node_id' => 'required|integer|exists:nodes,id', 'is_successful' => 'sometimes|boolean', 'name' => 'required|string|min:1|max:40', - 'file_name' => 'required|unique:iso_library,file_name|string|ends_with:.iso|max:191', + 'file_name' => 'required|string|ends_with:.iso|max:191', 'size' => 'sometimes|numeric|min:0', 'hidden' => 'sometimes|boolean', 'completed_at' => 'nullable|date',