A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4f9f6c63b3
commit 7e1e26f20b
126 changed files with 7917 additions and 204 deletions

View File

@@ -149,6 +149,9 @@ class StoreEntryRequest extends FormRequest
$rules['files_metadata'] = 'array|nullable';
$rules['files_metadata.*.online_patcher'] = 'nullable|boolean';
$rules['files_metadata.*.secondary_online_patcher'] = 'nullable|boolean|required_with:files_metadata.*.online_patcher';
$rules['files_metadata.*.play_online'] = 'nullable|boolean';
$rules['files_metadata.*.play_online_core'] = 'nullable|string';
$rules['files_metadata.*.play_online_threads'] = 'nullable|boolean';
}
if( $isEdit && $this->user()->can('moderate', $this->route('entry') ) ){

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests;
class StoreNewsDraftRequest extends StoreNewsRequest
{
public function rules(): array
{
$rules = parent::rules();
$rules['submit-state'] = 'required|string|in:draft';
$rules = array_map(function($rule){
if( is_array($rule) ){
return array_map( fn($r) => $r === 'required' ? 'nullable' : $r, $rule);
}
return preg_replace(
['/\brequired_without\S*/', '/required_with\S*/', '/\brequired\b/'],
['nullable', 'nullable', 'nullable'],
$rule
);
}, $rules );
return $rules;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Http\Requests;
use App\Models\News;
use App\Rules\PublicFileExists;
use App\Rules\XfUserExists;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class StoreNewsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
$news = $this->route('news');
if( $news )
return $this->user()->can('update', $news);
return $this->user()->can('create', News::class);
}
public function prepareForValidation(): void
{
$this->merge([
'gallery' => $this->input('gallery') !== '' ? $this->input('gallery') : null,
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$isEdit = (bool) $this->route('news');
$rules = [];
$rules['title'] = 'required|string|max:255';
$rules['category'] = 'required|integer|exists:categories,id';
$rules['description'] = 'required|string';
$rules['gallery'] = 'array|required|min:1';
$rules['gallery.*'] = [ 'string', new PublicFileExists ];
$rules['entry_id'] = 'nullable|integer|exists:entries,id';
$rules['release_site'] = 'nullable|url|max:500';
$rules['youtube_video'] = 'nullable|url|max:500';
if( $isEdit ){
$ss = 'draft,pending,published';
if( \Auth::user()->can('moderate', $this->route('news')) && \Auth::user()->can('view-hidden', $this->route('news')) )
$ss .= ',hidden';
if(\Auth::user()->can('moderate', $this->route('news')) && \Auth::user()->can('view-locked', $this->route('news')) )
$ss .= ',locked';
$rules['submit-state'] = 'required|in:' . $ss;
} else {
if( $this->user()->can('skip-queue', '\App\Models\News') ){
$rules['submit-state'] = 'required|string|in:draft,pending,published';
} else {
$rules['submit-state'] = 'required|string|in:draft,pending';
}
}
if( $isEdit && $this->user()->can('moderate', $this->route('news') ) ){
$rules['staff_comment'] = 'nullable|string';
$rules['owner_user_id'] = [ 'required', 'integer', new XfUserExists ];
$rules['comments_thread_id'] = 'nullable|integer';
}
return $rules;
}
}