v7.0.0 release
This commit is contained in:
1 parent
0e7fa04b03
commit
c4ea9a6cd1
3582 files changed
+626189
-160151
No files matched your search
@@ -9,17 +9,21 @@ use App\Rules\LocaleRequiredTranslatable;
|
||||
use App\Rules\TranslatableField;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Modules\Sirsoft\Board\Http\Requests\Concerns\ValidatesLengthRange;
|
||||
use Modules\Sirsoft\Board\Rules\BoardTypeValidationRule;
|
||||
use Modules\Sirsoft\Board\Rules\PermissionRolesRequiredRule;
|
||||
|
||||
// use Modules\Sirsoft\Board\Rules\CategoryInUseRule; // TODO: Task 5.5에서 구현 예정
|
||||
|
||||
class UpdateBoardRequest extends FormRequest
|
||||
{
|
||||
use ValidatesLengthRange;
|
||||
|
||||
/**
|
||||
* 사용자가 이 요청을 수행할 권한이 있는지 확인
|
||||
*
|
||||
* 권한 체크는 라우트의 permission 미들웨어에서 수행됩니다.
|
||||
*
|
||||
* @return bool 항상 true (권한은 미들웨어에서 검증)
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
@@ -74,18 +78,18 @@ class UpdateBoardRequest extends FormRequest
|
||||
*
|
||||
* slug는 수정 불가하므로 제외됩니다.
|
||||
* 부분 업데이트를 지원하기 위해 sometimes 규칙을 적용합니다.
|
||||
*
|
||||
* @return array<string, mixed> 검증 규칙 배열
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// route()가 없는 테스트 환경에서도 동작하도록 null 체크
|
||||
$board = $this->route() ? $this->route('board') : null;
|
||||
|
||||
// config에서 제한값 가져오기
|
||||
$limits = config('sirsoft-board.limits', []);
|
||||
$perPageMin = $limits['per_page_min'] ?? 5;
|
||||
$perPageMax = $limits['per_page_max'] ?? 100;
|
||||
$maxFileSizeMax = $limits['max_file_size_max'] ?? 200; // MB
|
||||
$maxFileCountMax = $limits['max_file_count_max'] ?? 20;
|
||||
$categoryMax = $limits['category_max'] ?? 50;
|
||||
|
||||
// 제목 길이 제한
|
||||
$minTitleLengthMin = $limits['min_title_length_min'] ?? 0;
|
||||
@@ -118,15 +122,18 @@ class UpdateBoardRequest extends FormRequest
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
'type' => ['sometimes', 'required', 'string', 'max:50', new BoardTypeValidationRule],
|
||||
|
||||
// 관리자 메뉴 표시 토글 (DB 컬럼 아님 - Service에서 메뉴 추가/제거에 사용)
|
||||
'add_to_menu' => ['sometimes', 'boolean'],
|
||||
|
||||
// 목록 설정
|
||||
'per_page' => ['sometimes', 'required', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
|
||||
'per_page_mobile' => ['sometimes', 'required', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
|
||||
'order_by' => ['sometimes', 'required', 'in:created_at,view_count,title,author'],
|
||||
'order_direction' => ['sometimes', 'required', 'in:ASC,DESC'],
|
||||
|
||||
// 분류 설정
|
||||
'categories' => ['sometimes', 'nullable', 'array'],
|
||||
'categories.*' => ['string', 'max:50'],
|
||||
// 분류 설정 (개수 상한은 config 기준, 빈/공백 이름 차단)
|
||||
'categories' => ['sometimes', 'nullable', 'array', "max:{$categoryMax}"],
|
||||
'categories.*' => ['string', 'filled', 'regex:/\S/', 'max:50'],
|
||||
|
||||
// 기능 설정
|
||||
'show_view_count' => ['sometimes', 'required', 'boolean'],
|
||||
@@ -153,7 +160,9 @@ class UpdateBoardRequest extends FormRequest
|
||||
'use_file_upload' => ['sometimes', 'required', 'boolean'],
|
||||
'max_file_size' => ['sometimes', 'nullable', 'integer', 'min:1', "max:{$maxFileSizeMax}"],
|
||||
'max_file_count' => ['sometimes', 'nullable', 'integer', 'min:1', "max:{$maxFileCountMax}"],
|
||||
'allowed_extensions' => ['sometimes', 'nullable', 'array'],
|
||||
// 허용 확장자: 전송되면 최소 1개 필수 (빈 배열 저장 시 전 파일 거부되던 버그 방지).
|
||||
// 부분 수정을 위해 sometimes 유지, nullable 제거.
|
||||
'allowed_extensions' => ['sometimes', 'array', 'min:1'],
|
||||
'allowed_extensions.*' => ['string', 'max:10'],
|
||||
|
||||
// 관리자 설정 (관리자는 최소 1명 필수, 스텝은 선택적)
|
||||
@@ -180,29 +189,68 @@ class UpdateBoardRequest extends FormRequest
|
||||
'blocked_keywords.*' => ['string', 'max:100'],
|
||||
];
|
||||
|
||||
// TODO: Task 5.5에서 CategoryInUseRule 구현 후 주석 해제
|
||||
// CategoryInUseRule 적용 (board가 있을 때만)
|
||||
// if ($board && isset($rules['categories'])) {
|
||||
// $rules['categories'][] = new CategoryInUseRule(
|
||||
// $board->slug,
|
||||
// $board->categories ?? [],
|
||||
// $this->input('categories', [])
|
||||
// );
|
||||
// }
|
||||
// 카테고리 삭제는 차단하지 않는다. 삭제된 분류의 게시글은 category 문자열이 그대로
|
||||
// 남아 게시판 분류 목록에서만 빠지며, 사용자/관리자 목록의 '미분류' 필터로 조회된다
|
||||
// (PostRepository: category === 'unclassified' → 미등록 분류 글 포함). 안내문으로 고지.
|
||||
|
||||
// 훅: 모듈/플러그인이 validation rules를 동적으로 추가할 수 있도록 필터 제공
|
||||
return HookManager::applyFilters('sirsoft-board.board.update_validation_rules', $rules, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검증기에 교차 검증 규칙을 추가합니다.
|
||||
*
|
||||
* 길이 제한 필드의 min ≤ max 관계를 검증합니다. 두 값이 함께 전송될 때만
|
||||
* 비교하므로 부분 수정(sometimes)에서는 적용되지 않습니다.
|
||||
*
|
||||
* @param Validator $validator 검증기
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$this->applyLengthRangeValidation($validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검증할 필드의 이름을 커스터마이징
|
||||
*
|
||||
* @return array<string, string> 필드명 → 표시명 매핑
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
$attributes = [
|
||||
'blocked_keywords' => __('sirsoft-board::admin.form.fields.blocked_keywords.label'),
|
||||
'add_to_menu' => __('sirsoft-board::validation.attributes.board.add_to_menu'),
|
||||
];
|
||||
|
||||
// 정수/설정 필드의 표시명 매핑 (.integer 등 기본 메시지 폴백 시 :attribute 가
|
||||
// 영문 snake_case 로 노출되는 것을 차단). 기존 settings.basic_defaults 라벨을 재사용.
|
||||
// 라벨 배열의 키는 'basic_defaults.per_page' 형태(점 포함 단일 키)이므로
|
||||
// settings 배열을 통째로 받아 인덱싱한다 (__() 의 점 경로 분해로는 도달 불가).
|
||||
$settingLabels = __('sirsoft-board::validation.attributes.settings');
|
||||
|
||||
if (is_array($settingLabels)) {
|
||||
$settingFieldKeys = [
|
||||
'per_page', 'per_page_mobile', 'order_by', 'order_direction',
|
||||
'secret_mode', 'use_comment', 'use_reply', 'use_report',
|
||||
'comment_order', 'show_view_count',
|
||||
'max_reply_depth', 'max_comment_depth',
|
||||
'min_title_length', 'max_title_length',
|
||||
'min_content_length', 'max_content_length',
|
||||
'min_comment_length', 'max_comment_length',
|
||||
'use_file_upload', 'max_file_size', 'max_file_count',
|
||||
'allowed_extensions', 'notify_admin_on_post', 'notify_author',
|
||||
'new_display_hours',
|
||||
];
|
||||
|
||||
foreach ($settingFieldKeys as $field) {
|
||||
$labelKey = "basic_defaults.{$field}";
|
||||
|
||||
if (isset($settingLabels[$labelKey])) {
|
||||
$attributes[$field] = $settingLabels[$labelKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 권한 필드에 대한 동적 속성 매핑
|
||||
$permissionDefinitions = config('sirsoft-board.board_permission_definitions', []);
|
||||
|
||||
@@ -221,7 +269,7 @@ class UpdateBoardRequest extends FormRequest
|
||||
|
||||
// permissions.{key}.roles 필드에 대한 속성 이름 지정
|
||||
$fieldKey = str_replace('.', '_', $permKey); // admin.posts.read -> admin_posts_read
|
||||
$attributes["permissions.{$fieldKey}.roles"] = "{$permissionName} " . __('sirsoft-board::validation.role_field_suffix');
|
||||
$attributes["permissions.{$fieldKey}.roles"] = "{$permissionName} ".__('sirsoft-board::validation.role_field_suffix');
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
@@ -229,6 +277,8 @@ class UpdateBoardRequest extends FormRequest
|
||||
|
||||
/**
|
||||
* 검증 오류 메시지 커스터마이징
|
||||
*
|
||||
* @return array<string, string> 규칙 키 → 메시지 매핑
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
@@ -256,7 +306,10 @@ class UpdateBoardRequest extends FormRequest
|
||||
|
||||
// 분류 검증 메시지
|
||||
'categories.array' => __('sirsoft-board::validation.categories.array'),
|
||||
'categories.max' => __('sirsoft-board::validation.categories.max'),
|
||||
'categories.*.max' => __('sirsoft-board::validation.categories.item_max'),
|
||||
'categories.*.filled' => __('sirsoft-board::validation.categories.item_required'),
|
||||
'categories.*.regex' => __('sirsoft-board::validation.categories.item_required'),
|
||||
|
||||
// 기능 설정 검증 메시지
|
||||
'show_view_count.required' => __('sirsoft-board::validation.show_view_count.required'),
|
||||
@@ -296,6 +349,7 @@ class UpdateBoardRequest extends FormRequest
|
||||
'max_file_size.max' => __('sirsoft-board::validation.max_file_size.max'),
|
||||
'max_file_count.min' => __('sirsoft-board::validation.max_file_count.min'),
|
||||
'max_file_count.max' => __('sirsoft-board::validation.max_file_count.max'),
|
||||
'allowed_extensions.min' => __('sirsoft-board::validation.allowed_extensions.min'),
|
||||
|
||||
// 관리자 설정 검증 메시지
|
||||
'board_manager_ids.required' => __('sirsoft-board::validation.board_manager_ids.required'),
|
||||
|
||||
Reference in new issue
Block a user