user()?->tokenCan('press-release-images:write') === true; } /** * Get the validation rules that apply to the request. * * KI-Kennzeichnung je Bild (Art. 50 KI-VO) ist im v1-Vertrag Pflicht. * Mit Formular v2 (Bildkennzeichnung Block C, Decision-Update S4) kommen * Bildnachweis, Rechtebestätigung und die Kennung des bestätigten * Wortlauts als Pflichtfelder dazu; Lizenz- und Quellenlink, * Fokuspunkt und Letterbox bleiben optional. * * @return array|string> */ public function rules(): array { $rightsV2 = (bool) config('images.rights_v2'); $maxKilobytes = $rightsV2 ? (int) ((int) config('images.max_bytes') / 1024) : 8192; $rules = [ 'image' => ['required', 'image', 'mimes:jpg,jpeg,png,webp', 'max:'.$maxKilobytes], 'ai_declaration' => ['required', Rule::enum(AiImageDeclaration::class)], 'title' => ['nullable', 'string', 'max:120'], 'description' => ['nullable', 'string', 'max:500'], 'copyright' => [$rightsV2 ? 'required' : 'nullable', 'string', 'max:255'], 'is_preview' => ['nullable', 'boolean'], ]; if ($rightsV2) { $rules += [ 'rights_confirmed' => ['required', 'accepted'], 'confirm_text_version' => ['required', 'string', 'max:40'], 'license_url' => ['nullable', 'url:http,https', 'max:2048'], 'source_url' => ['nullable', 'url:http,https', 'max:2048'], 'focus_x' => ['nullable', 'integer', 'between:0,100'], 'focus_y' => ['nullable', 'integer', 'between:0,100'], 'no_crop' => ['nullable', 'boolean'], ]; } return $rules; } /** * Die Kennung muss die heute aktive Fassung sein; sonst 422 mit Hinweis * auf die aktuelle Kennung (Decision-Update 7.1: „sonst 422 mit Hinweis"). */ public function after(): array { return [ function (Validator $validator): void { if (! config('images.rights_v2') || $validator->errors()->has('confirm_text_version')) { return; } $current = app(ImageRightsTextRenderer::class)->current(); $given = (string) $this->input('confirm_text_version'); if ($current === null || $given !== $current->key) { $validator->errors()->add( 'confirm_text_version', sprintf('The confirmation text version is not current. Current version: %s.', $current !== null ? $current->key : 'none'), ); } }, ]; } /** * @return array */ public function messages(): array { return [ 'rights_confirmed.accepted' => 'The rights confirmation is required (rights_confirmed must be true).', 'copyright.required' => 'The image credit (copyright) is required.', ]; } }