v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

@@ -0,0 +1,36 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
/**
* 대시보드 조회 파라미터 검증
*
* 최신글/신고 카드의 limit 을 검증합니다.
* 그래프 표시 일수는 모듈 설정(graph_days)이 SSoT 이므로 요청 파라미터로 받지 않습니다.
*/
class DashboardRangeRequest extends FormRequest
{
/**
* 요청 권한 확인 (권한은 미들웨어에서 처리).
*
* @return bool 항상 true
*/
public function authorize(): bool
{
return true;
}
/**
* 검증 규칙을 반환합니다.
*
* @return array<string, array<int, mixed>> 검증 규칙
*/
public function rules(): array
{
return [
'limit' => ['nullable', 'integer', 'min:1', 'max:50'],
];
}
}
@@ -0,0 +1,36 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
/**
* 게시판 환경설정 전체 조회 요청
*
* 별도 입력 검증은 없으며, 권한 체크는 라우트의 permission 미들웨어
* (`permission:admin,sirsoft-board.settings.read`)에서 수행됩니다.
*/
class IndexBoardSettingsRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행됩니다.
*
* @return bool 항상 true
*/
public function authorize(): bool
{
return true;
}
/**
* 검증 규칙을 반환합니다.
*
* @return array<string, mixed> 검증 규칙
*/
public function rules(): array
{
return [];
}
}
@@ -0,0 +1,48 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
/**
* 관리자 신고 목록 조회 요청 폼 검증
*
* 검색/필터/정렬/페이지네이션 파라미터의 형식을 검증합니다.
*/
class IndexReportRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인합니다.
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행합니다.
*
* @return bool 항상 true (권한은 미들웨어에서 검증)
*/
public function authorize(): bool
{
return true;
}
/**
* 요청에 적용할 검증 규칙
*
* @return array<string, mixed>
*/
public function rules(): array
{
// status/target_type/target_status 는 단일 문자열(?status=pending) 또는
// 배열(?status[]=pending&status[]=review) 두 형태 모두 허용한다.
return [
'filters' => ['nullable', 'array'],
'status' => ['nullable'],
'target_type' => ['nullable'],
'target_status' => ['nullable'],
'board_id' => ['nullable', 'integer'],
'reported_at_from' => ['nullable', 'string'],
'reported_at_to' => ['nullable', 'string'],
'sort_by' => ['nullable', 'string'],
'sort_order' => ['nullable', 'string', 'in:asc,desc'],
'per_page' => ['nullable', 'integer'],
];
}
}
@@ -0,0 +1,38 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
/**
* 관리자 신고 케이스 신고자 목록 조회 요청 폼 검증
*
* 페이지네이션 파라미터의 형식을 검증합니다.
*/
class ReportersRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인합니다.
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행합니다.
*
* @return bool 항상 true (권한은 미들웨어에서 검증)
*/
public function authorize(): bool
{
return true;
}
/**
* 요청에 적용할 검증 규칙
*
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'per_page' => ['nullable', 'integer', 'min:1'],
'page' => ['nullable', 'integer', 'min:1'],
];
}
}
@@ -0,0 +1,37 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
/**
* 게시판 환경설정 카테고리별 조회 요청
*
* 카테고리는 라우트 파라미터(`settings/{category}`)로 전달되며, 별도 입력 검증은
* 없습니다. 권한 체크는 라우트의 permission 미들웨어
* (`permission:admin,sirsoft-board.settings.read`)에서 수행됩니다.
*/
class ShowBoardSettingsRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행됩니다.
*
* @return bool 항상 true
*/
public function authorize(): bool
{
return true;
}
/**
* 검증 규칙을 반환합니다.
*
* @return array<string, mixed> 검증 규칙
*/
public function rules(): array
{
return [];
}
}
@@ -0,0 +1,68 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Sirsoft\Board\Enums\ReportStatus;
/**
* 관리자 신고 상태별 건수 조회 요청 폼 검증
*
* 일괄 처리 전 선택한 신고들의 상태 분포를 보여주기 위한 요청을 검증합니다.
*/
class StatusCountsRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인합니다.
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행합니다.
*
* @return bool 항상 true (권한은 미들웨어에서 검증)
*/
public function authorize(): bool
{
return true;
}
/**
* 요청에 적용할 검증 규칙
*
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'ids' => ['required', 'array', 'min:1'],
'ids.*' => ['integer'],
'target_status' => ['nullable', 'string', Rule::in(ReportStatus::values())],
];
}
/**
* 검증 오류 메시지 커스터마이징
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'ids.required' => __('sirsoft-board::messages.reports.no_reports_selected'),
'ids.array' => __('sirsoft-board::messages.reports.no_reports_selected'),
'ids.min' => __('sirsoft-board::messages.reports.no_reports_selected'),
'target_status.in' => __('sirsoft-board::validation.report.status.in'),
];
}
/**
* 검증할 필드의 이름을 커스터마이징
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'ids' => __('sirsoft-board::attributes.report.ids'),
];
}
}
@@ -88,6 +88,18 @@ class StoreBoardSettingsRequest extends FormRequest
}
}
// default_board_permissions 는 flat 키(값 = 역할 식별자 배열) 구조만 허용한다.
// 레거시 오염 데이터로 nested 그룹 키(admin/posts/comments/attachments, 값 = 중첩 객체)가
// 섞여 들어오면 권한 설정 화면에 raw i18n 키와 [object Object] 로 노출되므로,
// 값이 순차 배열(역할 목록)이 아닌 항목은 저장 전에 제거해 재오염을 차단한다.
$permissions = $data['basic_defaults']['default_board_permissions'] ?? null;
if (is_array($permissions)) {
$data['basic_defaults']['default_board_permissions'] = array_filter(
$permissions,
fn ($roles) => is_array($roles) && array_is_list($roles)
);
}
$this->replace($data);
}
@@ -98,6 +110,14 @@ class StoreBoardSettingsRequest extends FormRequest
*/
public function rules(): array
{
$limits = config('sirsoft-board.limits', []);
$perPageMin = $limits['per_page_min'] ?? 5;
$perPageMax = $limits['per_page_max'] ?? 100;
$maxReplyDepthMin = $limits['max_reply_depth_min'] ?? 1;
$maxReplyDepthMax = $limits['max_reply_depth_max'] ?? 10;
$maxCommentDepthMin = $limits['max_comment_depth_min'] ?? 0;
$maxCommentDepthMax = $limits['max_comment_depth_max'] ?? 10;
return [
// 현재 탭 정보 (메타 데이터)
'_tab' => ['sometimes', 'string', 'in:basic_defaults,report_policy,spam_security,general,seo,notifications,notification_definitions'],
@@ -116,15 +136,15 @@ class StoreBoardSettingsRequest extends FormRequest
// ========================================
'basic_defaults' => ['sometimes', 'array'],
'basic_defaults.type' => ['nullable', 'string', 'max:50'],
'basic_defaults.per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
'basic_defaults.per_page_mobile' => ['nullable', 'integer', 'min:1', 'max:100'],
'basic_defaults.per_page' => ['nullable', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
'basic_defaults.per_page_mobile' => ['nullable', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
'basic_defaults.order_by' => ['nullable', 'string', 'in:created_at,view_count,title,author'],
'basic_defaults.order_direction' => ['nullable', 'string', 'in:ASC,DESC'],
'basic_defaults.secret_mode' => ['nullable', 'string', 'in:disabled,enabled,always'],
'basic_defaults.use_comment' => ['nullable', 'boolean'],
'basic_defaults.use_reply' => ['nullable', 'boolean'],
'basic_defaults.max_reply_depth' => ['nullable', 'integer', 'min:1', 'max:5'],
'basic_defaults.max_comment_depth' => ['nullable', 'integer', 'min:0', 'max:10'],
'basic_defaults.max_reply_depth' => ['nullable', 'integer', "min:{$maxReplyDepthMin}", "max:{$maxReplyDepthMax}"],
'basic_defaults.max_comment_depth' => ['nullable', 'integer', "min:{$maxCommentDepthMin}", "max:{$maxCommentDepthMax}"],
'basic_defaults.comment_order' => ['nullable', 'string', 'in:ASC,DESC'],
'basic_defaults.show_view_count' => ['nullable', 'boolean'],
'basic_defaults.use_report' => ['nullable', 'boolean'],
@@ -139,7 +159,9 @@ class StoreBoardSettingsRequest extends FormRequest
'basic_defaults.max_file_count' => ['nullable', 'integer', 'min:1', 'max:20'],
'basic_defaults.blocked_keywords' => ['nullable', 'array'],
'basic_defaults.blocked_keywords.*' => ['string', 'max:100'],
'basic_defaults.allowed_extensions' => ['nullable', 'array'],
// 허용 확장자는 최소 1개 필수 (빈 배열 차단 — 빈 값 저장 시 전 파일 거부되던 버그 방지).
// 부분 탭 저장을 위해 sometimes 유지, nullable 제거.
'basic_defaults.allowed_extensions' => ['sometimes', 'array', 'min:1'],
'basic_defaults.allowed_extensions.*' => ['string', 'max:20'],
'basic_defaults.notify_admin_on_post' => ['nullable', 'boolean'],
'basic_defaults.notify_author' => ['nullable', 'boolean'],
@@ -170,10 +192,10 @@ class StoreBoardSettingsRequest extends FormRequest
// report_permissions (신고 관리 권한) — 설정값이 아닌 DB 권한 데이터
// validatedSettings()에서 제외됨
// ========================================
'report_permissions' => ['sometimes', 'array'],
'report_permissions.view_roles' => ['nullable', 'array'],
'report_permissions.view_roles.*' => ['string', Rule::exists(Role::class, 'identifier')],
'report_permissions.manage_roles' => ['nullable', 'array'],
'report_permissions' => ['sometimes', 'array'],
'report_permissions.view_roles' => ['required_with:report_permissions', 'array', 'min:1'],
'report_permissions.view_roles.*' => ['string', Rule::exists(Role::class, 'identifier')],
'report_permissions.manage_roles' => ['required_with:report_permissions', 'array', 'min:1'],
'report_permissions.manage_roles.*' => ['string', Rule::exists(Role::class, 'identifier')],
// ========================================
@@ -227,8 +249,15 @@ class StoreBoardSettingsRequest extends FormRequest
public function messages(): array
{
$messages = __('sirsoft-board::validation.settings');
$base = is_array($messages) ? $messages : [];
return is_array($messages) ? $messages : [];
return array_merge($base, [
'basic_defaults.allowed_extensions.min' => __('sirsoft-board::validation.allowed_extensions.min'),
'report_permissions.view_roles.required_with' => __('sirsoft-board::validation.report_permissions.view_roles.required_with'),
'report_permissions.view_roles.min' => __('sirsoft-board::validation.report_permissions.view_roles.min'),
'report_permissions.manage_roles.required_with' => __('sirsoft-board::validation.report_permissions.manage_roles.required_with'),
'report_permissions.manage_roles.min' => __('sirsoft-board::validation.report_permissions.manage_roles.min'),
]);
}
/**
@@ -11,6 +11,8 @@ class BlindCommentRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* @return bool 권한 보유 여부
*/
public function authorize(): bool
{
@@ -25,7 +27,7 @@ class BlindCommentRequest extends FormRequest
public function rules(): array
{
return [
'reason' => ['nullable', 'string'],
'reason' => ['nullable', 'string', 'max:1000'],
];
}
@@ -11,6 +11,8 @@ class BlindPostRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* @return bool 권한 보유 여부
*/
public function authorize(): bool
{
@@ -25,7 +27,7 @@ class BlindPostRequest extends FormRequest
public function rules(): array
{
return [
'reason' => ['nullable', 'string'],
'reason' => ['nullable', 'string', 'max:1000'],
];
}
@@ -0,0 +1,74 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests\Concerns;
use Illuminate\Validation\Validator;
/**
* 길이 제한 필드의 최소/최대 교차 검증 트레이트
*
* 제목/본문/댓글 길이의 `min_*_length` 와 `max_*_length` 는 각 필드의 절대 범위만
* 검증되므로, `min_*_length > max_*_length` 같은 논리적으로 모순된 조합이 저장될 수 있다.
* 이 트레이트는 두 값이 모두 요청에 존재할 때 min ≤ max 를 보장한다.
*
* 생성/수정 Request 의 withValidator() 에서 applyLengthRangeValidation() 을 호출한다.
*/
trait ValidatesLengthRange
{
/**
* 교차 검증 대상 필드 쌍 (min 필드 => max 필드).
*
* @return array<string, string>
*/
protected function lengthRangePairs(): array
{
return [
'min_title_length' => 'max_title_length',
'min_content_length' => 'max_content_length',
'min_comment_length' => 'max_comment_length',
];
}
/**
* min_*_length 가 max_*_length 보다 큰 조합을 검증 실패로 처리합니다.
*
* 두 값이 모두 요청에 존재할 때만 비교한다. 부분 수정(한쪽만 전송)에서는
* DB 기존값과의 비교 없이 통과시킨다. 오류는 max_* 필드에 추가하여
* 기존 레이아웃의 max_* 오류 표시 요소가 그대로 렌더하도록 한다.
*
* @param Validator $validator 검증기
*/
protected function applyLengthRangeValidation(Validator $validator): void
{
$validator->after(function (Validator $validator): void {
// 검증 대상 데이터는 validator 에서 직접 읽는다 (단위 테스트의 Validator::make 와
// 실제 HTTP 요청 양쪽에서 동일하게 동작).
$data = $validator->getData();
$errors = $validator->errors();
foreach ($this->lengthRangePairs() as $minField => $maxField) {
if (! array_key_exists($minField, $data) || ! array_key_exists($maxField, $data)) {
continue;
}
if ($errors->has($minField) || $errors->has($maxField)) {
continue;
}
$min = $data[$minField];
$max = $data[$maxField];
if (! is_numeric($min) || ! is_numeric($max)) {
continue;
}
if ((int) $min > (int) $max) {
$validator->errors()->add(
$maxField,
__("sirsoft-board::validation.{$maxField}.gte_min")
);
}
}
});
}
}
@@ -9,15 +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\SlugUniqueRule;
class StoreBoardRequest extends FormRequest
{
use ValidatesLengthRange;
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행됩니다.
*
* @return bool 항상 true (권한은 미들웨어에서 검증)
*/
public function authorize(): bool
{
@@ -93,6 +99,8 @@ class StoreBoardRequest extends FormRequest
/**
* 요청에 적용할 검증 규칙
*
* @return array<string, mixed> 검증 규칙 배열
*/
public function rules(): array
{
@@ -102,6 +110,7 @@ class StoreBoardRequest extends FormRequest
$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;
@@ -135,15 +144,18 @@ class StoreBoardRequest extends FormRequest
'is_active' => ['sometimes', 'boolean'],
'type' => ['required', 'string', 'max:50', new BoardTypeValidationRule],
// 관리자 메뉴 추가 토글 (DB 컬럼 아님 - Service에서 메뉴 등록에 사용)
'add_to_menu' => ['sometimes', 'boolean'],
// 목록 설정
'per_page' => ['required', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
'per_page_mobile' => ['required', 'integer', "min:{$perPageMin}", "max:{$perPageMax}"],
'order_by' => ['required', 'in:created_at,view_count,title,author'],
'order_direction' => ['required', 'in:ASC,DESC'],
// 분류 설정
'categories' => ['nullable', 'array'],
'categories.*' => ['string', 'max:50'],
// 분류 설정 (개수 상한은 config 기준, 빈/공백 이름 차단)
'categories' => ['nullable', 'array', "max:{$categoryMax}"],
'categories.*' => ['string', 'filled', 'regex:/\S/', 'max:50'],
// 기능 설정
'show_view_count' => ['required', 'boolean'],
@@ -170,7 +182,10 @@ class StoreBoardRequest extends FormRequest
'use_file_upload' => ['required', 'boolean'],
'max_file_size' => ['nullable', 'integer', 'min:1', "max:{$maxFileSizeMax}"],
'max_file_count' => ['nullable', 'integer', 'min:1', "max:{$maxFileCountMax}"],
'allowed_extensions' => ['nullable', 'array'],
// 허용 확장자: 첨부 사용 게시판은 최소 1개 필수 (빈 배열 저장 시 전 파일 거부되던 버그 방지).
// 첨부 미사용 게시판은 검증 제외(exclude_if) — min:1 이 빈 배열에 무조건 걸리므로
// required_if 만으로는 빈 값 허용이 불가하다. exclude_if 로 필드 자체를 검증에서 제거한다.
'allowed_extensions' => ['exclude_if:use_file_upload,false', 'required', 'array', 'min:1'],
'allowed_extensions.*' => ['string', 'max:10'],
// 게시판 관리 인원 설정 (관리자는 최소 1명 필수, 스텝은 선택적)
@@ -201,13 +216,28 @@ class StoreBoardRequest extends FormRequest
return HookManager::applyFilters('sirsoft-board.board.store_validation_rules', $rules, $this);
}
/**
* 검증기에 교차 검증 규칙을 추가합니다.
*
* 길이 제한 필드의 min ≤ max 관계를 검증합니다.
*
* @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'),
];
// 권한 필드에 대한 동적 속성 매핑
@@ -228,7 +258,7 @@ class StoreBoardRequest 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;
@@ -236,6 +266,8 @@ class StoreBoardRequest extends FormRequest
/**
* 검증 오류 메시지 커스터마이징
*
* @return array<string, string> 규칙 키 → 메시지 매핑
*/
public function messages(): array
{
@@ -269,7 +301,10 @@ class StoreBoardRequest 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'),
@@ -309,6 +344,8 @@ class StoreBoardRequest 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.required' => __('sirsoft-board::validation.allowed_extensions.min'),
'allowed_extensions.min' => __('sirsoft-board::validation.allowed_extensions.min'),
// 관리자 설정 검증 메시지
'board_manager_ids.required' => __('sirsoft-board::validation.board_manager_ids.required'),
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
use Modules\Sirsoft\Board\Enums\PostStatus;
use Modules\Sirsoft\Board\Models\Board;
use Modules\Sirsoft\Board\Rules\BlockedKeywordsRule;
use Modules\Sirsoft\Board\Rules\CommentValidationRule;
use Modules\Sirsoft\Board\Rules\CooldownRule;
@@ -18,6 +19,8 @@ class StoreCommentRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* @return bool 권한 검증 결과 (권한 체크는 미들웨어 위임, 항상 true)
*/
public function authorize(): bool
{
@@ -28,8 +31,6 @@ class StoreCommentRequest extends FormRequest
* 검증 전 데이터 준비
*
* route 파라미터를 검증 데이터에 merge합니다.
*
* @return void
*/
protected function prepareForValidation(): void
{
@@ -59,12 +60,16 @@ class StoreCommentRequest extends FormRequest
$spamSecurity = g7_module_settings('sirsoft-board', 'spam_security', []);
$commentCooldown = (int) ($spamSecurity['comment_cooldown_seconds'] ?? 0);
// 금지 키워드 목록 가져오기 (게시글과 동일하게 게시판 설정 기준)
$blockedKeywords = $board->blocked_keywords ?? [];
$rules = [
'content' => [
'required',
'string',
'min:'.($board->min_comment_length ?? 2),
'max:'.($board->max_comment_length ?? 1000),
new BlockedKeywordsRule($blockedKeywords),
new CooldownRule('comment', $commentCooldown, $slug),
],
'post_id' => ['bail', 'required', 'integer', new CommentValidationRule($slug, 'post')],
@@ -124,7 +129,9 @@ class StoreCommentRequest extends FormRequest
/**
* 검증 통과 후 비밀번호를 해싱합니다.
*
* @return array<string, mixed>
* @param string|null $key 반환할 특정 검증 값의 키 (null 이면 전체)
* @param mixed $default 키가 없을 때 반환할 기본값
* @return array<string, mixed>|mixed 검증된 데이터 (키 지정 시 해당 값)
*/
public function validated($key = null, $default = null): mixed
{
@@ -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'),
@@ -7,6 +7,7 @@ use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Sirsoft\Board\Enums\PostStatus;
use Modules\Sirsoft\Board\Models\Board;
use Modules\Sirsoft\Board\Rules\BlockedKeywordsRule;
/**
* 댓글 수정 요청 폼 검증
@@ -15,6 +16,8 @@ class UpdateCommentRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* @return bool 권한 검증 결과 (권한 체크는 미들웨어 위임, 항상 true)
*/
public function authorize(): bool
{
@@ -38,12 +41,16 @@ class UpdateCommentRequest extends FormRequest
// 비회원 여부 확인 (request()->user()를 사용해야 PermissionMiddleware에서 설정한 사용자를 인식)
$isGuest = ! $this->user();
// 금지 키워드 목록 가져오기 (게시글과 동일하게 게시판 설정 기준)
$blockedKeywords = $board->blocked_keywords ?? [];
$rules = [
'content' => [
'required',
'string',
'min:'.($board->min_comment_length ?? 2),
'max:'.($board->max_comment_length ?? 1000),
new BlockedKeywordsRule($blockedKeywords),
],
'is_secret' => ['boolean'],
'status' => ['nullable', 'string', Rule::in(PostStatus::values())],
@@ -5,7 +5,7 @@ namespace Modules\Sirsoft\Board\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Sirsoft\Board\Enums\ReportStatus;
use Modules\Sirsoft\Board\Models\Report;
use Modules\Sirsoft\Board\Repositories\Contracts\ReportRepositoryInterface;
/**
* 신고 상태 변경 요청 폼 검증
@@ -13,7 +13,11 @@ use Modules\Sirsoft\Board\Models\Report;
class UpdateStatusRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
* 사용자가 이 요청을 수행할 권한이 있는지 확인합니다.
*
* 권한 체크는 라우트의 permission 미들웨어에서 수행합니다.
*
* @return bool 항상 true (권한은 미들웨어에서 검증)
*/
public function authorize(): bool
{
@@ -33,14 +37,14 @@ class UpdateStatusRequest extends FormRequest
'string',
Rule::in(ReportStatus::values()),
function ($attribute, $value, $fail) {
// 현재 신고 조회
$report = Report::find($this->route('id'));
// 현재 신고 조회 (라우트 파라미터명은 {report} — Repository Interface 경유)
$report = app(ReportRepositoryInterface::class)->find((int) $this->route('report'));
if (! $report) {
return; // 404는 컨트롤러에서 처리
}
// Enum의 전환 규칙 메서드 사용
// Enum의 전환 규칙 메서드 사용 (deleted 등 최종 상태는 전환 불가 → 422)
if (! $report->status->canTransitionTo($value)) {
$fail(__('sirsoft-board::validation.report.invalid_status_transition'));
}