fix(core,board,ecommerce,page): 중첩 리소스 스코프·계층 무결성 결함 12건 일괄 수정
중첩 라우트의 상위 리소스 ID 를 조회 스코프에 반영하지 않아 A 의 경로로 B 의 하위 리소스를 읽거나 변경할 수 있었다. 방어 위치를 Repository where 절(SSoT)로 통일하고 컨트롤러 사후 비교에 의존하지 않게 했다. 같은 리소스의 형제 엔드포인트가 서로 다른 강도로 검증하던 부분도 맞췄다. 계층 리소스는 자기 자신·자손을 부모로 지정하는 순환을 검증 계층에서 차단하고, 검증을 우회하는 경로(시더/훅/오염 데이터)를 위해 path 재귀에 방문 ID 가드를 뒀다. 설정값이 정하는 깊이 상한을 Service 가 리터럴로 재클램프하던 부분을 제거해 게시판 설정이 실제로 적용되게 했다. 쓰기 경로는 validated 기준으로 좁혀 FormRequest 미정의 필드가 fillable 로 새지 않게 했다. 기존 오염 데이터는 업그레이드 스텝이 정리한다(삭제 없이 최상위로 이동). 재발 방지로 audit 룰 3종을 추가하고, 규정 문서와 트러블슈팅 사례를 함께 갱신했다. 공개 이슈: gnuboard/g7
This commit is contained in:
1 parent
9dda22f8e4
commit
abb40ad210
74 files changed
+3880
-192
No files matched your search
@@ -127,8 +127,8 @@ class CommentController extends AdminBaseController
|
||||
public function update(UpdateCommentRequest $request, string $slug, int $postId, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
// 댓글 조회
|
||||
$comment = $this->commentService->getComment($slug, $id);
|
||||
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
|
||||
$comment = $this->commentService->getComment($slug, $id, $postId);
|
||||
|
||||
// 권한 체크: 본인 댓글 또는 admin.manage
|
||||
if ($response = $this->authorizeCommentModification($slug, $comment->user_id)) {
|
||||
@@ -146,7 +146,7 @@ class CommentController extends AdminBaseController
|
||||
}
|
||||
|
||||
$data = $request->validated();
|
||||
$updatedComment = $this->commentService->updateComment($slug, $id, $data);
|
||||
$updatedComment = $this->commentService->updateComment($slug, $id, $data, $postId);
|
||||
|
||||
return $this->successWithResource(
|
||||
'sirsoft-board::messages.comment.update_success',
|
||||
@@ -170,8 +170,8 @@ class CommentController extends AdminBaseController
|
||||
public function destroy(string $slug, int $postId, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
// 댓글 조회
|
||||
$comment = $this->commentService->getComment($slug, $id);
|
||||
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
|
||||
$comment = $this->commentService->getComment($slug, $id, $postId);
|
||||
|
||||
// 권한 체크: 본인 댓글 또는 admin.manage
|
||||
if ($response = $this->authorizeCommentModification($slug, $comment->user_id)) {
|
||||
@@ -188,7 +188,7 @@ class CommentController extends AdminBaseController
|
||||
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
|
||||
}
|
||||
|
||||
$this->commentService->deleteComment($slug, $id, 'admin');
|
||||
$this->commentService->deleteComment($slug, $id, 'admin', $postId);
|
||||
|
||||
return $this->success('sirsoft-board::messages.comment.delete_success');
|
||||
} catch (ModelNotFoundException) {
|
||||
@@ -223,7 +223,7 @@ class CommentController extends AdminBaseController
|
||||
$validated = $request->validated();
|
||||
$reason = $validated['reason'] ?? '';
|
||||
|
||||
$comment = $this->commentService->blindComment($slug, $id, $reason);
|
||||
$comment = $this->commentService->blindComment($slug, $id, $reason, null, $postId);
|
||||
|
||||
return $this->successWithResource(
|
||||
'sirsoft-board::messages.comment.blind_success',
|
||||
@@ -259,7 +259,7 @@ class CommentController extends AdminBaseController
|
||||
}
|
||||
|
||||
$reason = $request->validated()['reason'] ?? null;
|
||||
$comment = $this->commentService->restoreComment($slug, $id, $reason);
|
||||
$comment = $this->commentService->restoreComment($slug, $id, $reason, null, $postId);
|
||||
|
||||
return $this->successWithResource(
|
||||
'sirsoft-board::messages.comment.restore_success',
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace Modules\Sirsoft\Board\Http\Controllers\User;
|
||||
use App\Http\Controllers\Api\Base\PublicBaseController;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Sirsoft\Board\Http\Requests\StoreCommentRequest;
|
||||
use Modules\Sirsoft\Board\Http\Requests\UpdateCommentRequest;
|
||||
use Modules\Sirsoft\Board\Http\Requests\VerifyCommentPasswordRequest;
|
||||
use Modules\Sirsoft\Board\Http\Resources\CommentResource;
|
||||
use Modules\Sirsoft\Board\Models\Board;
|
||||
use Modules\Sirsoft\Board\Services\BoardService;
|
||||
use Modules\Sirsoft\Board\Services\CommentService;
|
||||
|
||||
/**
|
||||
@@ -26,9 +26,11 @@ class CommentController extends PublicBaseController
|
||||
* CommentController 생성자
|
||||
*
|
||||
* @param CommentService $commentService 댓글 서비스
|
||||
* @param BoardService $boardService 게시판 서비스
|
||||
*/
|
||||
public function __construct(
|
||||
private CommentService $commentService
|
||||
private CommentService $commentService,
|
||||
private BoardService $boardService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -43,7 +45,11 @@ class CommentController extends PublicBaseController
|
||||
public function index(string $slug, int $postId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$board = Board::where('slug', $slug)->firstOrFail();
|
||||
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
|
||||
|
||||
if (! $board) {
|
||||
return $this->error('sirsoft-board::messages.boards.not_found', 404);
|
||||
}
|
||||
|
||||
if (! $board->use_comment) {
|
||||
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
|
||||
@@ -73,13 +79,19 @@ class CommentController extends PublicBaseController
|
||||
public function store(StoreCommentRequest $request, string $slug, int $postId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$board = Board::where('slug', $slug)->firstOrFail();
|
||||
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
|
||||
|
||||
if (! $board) {
|
||||
return $this->error('sirsoft-board::messages.boards.not_found', 404);
|
||||
}
|
||||
|
||||
if (! $board->use_comment) {
|
||||
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
|
||||
}
|
||||
|
||||
$data = $request->validated();
|
||||
// 경로의 게시글을 SSoT 로 고정 (요청 본문 값이 경로와 갈라지지 않도록)
|
||||
$data['post_id'] = $postId;
|
||||
$data['ip_address'] = $request->ip();
|
||||
|
||||
// user_id 설정 (인증 필수)
|
||||
@@ -119,13 +131,18 @@ class CommentController extends PublicBaseController
|
||||
public function update(UpdateCommentRequest $request, string $slug, int $postId, int $commentId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$board = Board::where('slug', $slug)->firstOrFail();
|
||||
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
|
||||
|
||||
if (! $board) {
|
||||
return $this->error('sirsoft-board::messages.boards.not_found', 404);
|
||||
}
|
||||
|
||||
if (! $board->use_comment) {
|
||||
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
|
||||
}
|
||||
|
||||
$comment = $this->commentService->getComment($slug, $commentId);
|
||||
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
|
||||
$comment = $this->commentService->getComment($slug, $commentId, $postId);
|
||||
|
||||
// 권한 확인 (Service에서 처리)
|
||||
$canUpdate = $this->commentService->canUpdate(
|
||||
@@ -139,9 +156,9 @@ class CommentController extends PublicBaseController
|
||||
return $this->forbidden('sirsoft-board::messages.comment.update_forbidden');
|
||||
}
|
||||
|
||||
// password는 검증용이므로 제거
|
||||
$data = $request->except('password');
|
||||
$updatedComment = $this->commentService->updateComment($slug, $commentId, $data);
|
||||
// 검증된 필드만 반영 (미검증 입력의 대량 할당 차단). password는 검증용이므로 제거
|
||||
$data = collect($request->validated())->except('password')->toArray();
|
||||
$updatedComment = $this->commentService->updateComment($slug, $commentId, $data, $postId);
|
||||
|
||||
return $this->successWithResource(
|
||||
'sirsoft-board::messages.comment.update_success',
|
||||
@@ -165,13 +182,18 @@ class CommentController extends PublicBaseController
|
||||
public function destroy(string $slug, int $postId, int $commentId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$board = Board::where('slug', $slug)->firstOrFail();
|
||||
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
|
||||
|
||||
if (! $board) {
|
||||
return $this->error('sirsoft-board::messages.boards.not_found', 404);
|
||||
}
|
||||
|
||||
if (! $board->use_comment) {
|
||||
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
|
||||
}
|
||||
|
||||
$comment = $this->commentService->getComment($slug, $commentId);
|
||||
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
|
||||
$comment = $this->commentService->getComment($slug, $commentId, $postId);
|
||||
|
||||
// 비회원인 경우 password 파라미터 필요
|
||||
$password = request()->input('password');
|
||||
@@ -188,7 +210,7 @@ class CommentController extends PublicBaseController
|
||||
return $this->forbidden('sirsoft-board::messages.comment.delete_forbidden');
|
||||
}
|
||||
|
||||
$this->commentService->deleteComment($slug, $commentId, 'user');
|
||||
$this->commentService->deleteComment($slug, $commentId, 'user', $postId);
|
||||
|
||||
return $this->success(
|
||||
'sirsoft-board::messages.comment.delete_success'
|
||||
@@ -203,17 +225,13 @@ class CommentController extends PublicBaseController
|
||||
/**
|
||||
* 비회원 댓글 비밀번호를 검증합니다.
|
||||
*
|
||||
* @param Request $request 요청
|
||||
* @param VerifyCommentPasswordRequest $request 비밀번호 확인 요청
|
||||
* @param string $slug 게시판 slug
|
||||
* @param int $commentId 댓글 ID
|
||||
* @return JsonResponse 비밀번호 검증 결과 응답
|
||||
*/
|
||||
public function verifyPassword(Request $request, string $slug, int $commentId): JsonResponse
|
||||
public function verifyPassword(VerifyCommentPasswordRequest $request, string $slug, int $commentId): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'password' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
try {
|
||||
$comment = $this->commentService->getComment($slug, $commentId);
|
||||
|
||||
|
||||
@@ -76,7 +76,8 @@ class StoreCommentRequest extends FormRequest
|
||||
'parent_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
new CommentValidationRule($slug, 'parent_comment'),
|
||||
// 부모 댓글은 요청 경로의 게시글에 속해야 한다 (교차 게시글 부모 차단)
|
||||
new CommentValidationRule($slug, 'parent_comment', (int) $this->route('postId')),
|
||||
],
|
||||
// depth는 서비스에서 자동 계산되므로 요청 데이터에서 받지 않음 (보안상 이유)
|
||||
'is_secret' => ['boolean'],
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Board\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 비회원 댓글 비밀번호 확인 요청 폼 검증
|
||||
*/
|
||||
class VerifyCommentPasswordRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 사용자가 이 요청을 수행할 권한이 있는지 확인
|
||||
*
|
||||
* @return bool 권한 검증 결과 (권한 체크는 미들웨어 위임, 항상 true)
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 요청에 적용할 검증 규칙
|
||||
*
|
||||
* @return array<string, mixed> 필드별 검증 규칙
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 검증 오류 메시지 커스터마이징
|
||||
*
|
||||
* @return array<string, string> 규칙별 다국어 메시지
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'password.required' => __('sirsoft-board::validation.comment.password.required'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 검증할 필드의 이름을 커스터마이징
|
||||
*
|
||||
* @return array<string, string> 필드별 표시명
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'password' => __('sirsoft-board::validation.attributes.comment.password'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -252,16 +252,20 @@ class CommentRepository implements CommentRepositoryInterface
|
||||
/**
|
||||
* ID로 댓글을 조회합니다.
|
||||
*
|
||||
* $postId 를 전달하면 해당 게시글에 속한 댓글만 조회합니다 (교차 게시글 접근 차단).
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param int|null $postId 상위 게시글 ID (null 이면 게시판 범위 전체)
|
||||
* @return Comment|null 댓글 또는 null
|
||||
*/
|
||||
public function find(string $slug, int $id): ?Comment
|
||||
public function find(string $slug, int $id, ?int $postId = null): ?Comment
|
||||
{
|
||||
$board = Board::where('slug', $slug)->first();
|
||||
|
||||
return Comment::query()
|
||||
->where('board_id', $board?->id)
|
||||
->when($postId !== null, fn ($query) => $query->where('post_id', $postId))
|
||||
->withTrashed()
|
||||
->with(['user'])
|
||||
->find($id);
|
||||
@@ -270,18 +274,22 @@ class CommentRepository implements CommentRepositoryInterface
|
||||
/**
|
||||
* ID로 댓글을 조회하며, 없으면 예외를 발생시킵니다.
|
||||
*
|
||||
* $postId 를 전달하면 해당 게시글에 속한 댓글만 조회합니다 (교차 게시글 접근 차단).
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param int|null $postId 상위 게시글 ID (null 이면 게시판 범위 전체)
|
||||
* @return Comment 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail(string $slug, int $id): Comment
|
||||
public function findOrFail(string $slug, int $id, ?int $postId = null): Comment
|
||||
{
|
||||
$board = Board::where('slug', $slug)->firstOrFail();
|
||||
|
||||
return Comment::query()
|
||||
->where('board_id', $board->id)
|
||||
->when($postId !== null, fn ($query) => $query->where('post_id', $postId))
|
||||
->withTrashed()
|
||||
->with(['user'])
|
||||
->findOrFail($id);
|
||||
|
||||
+11
-2
@@ -19,6 +19,8 @@ interface CommentRepositoryInterface
|
||||
* @param int $postId 게시글 ID
|
||||
* @param bool $withTrashed 삭제된 댓글 포함 여부 (기본값: false)
|
||||
* @param string $orderDirection 정렬 방향 (ASC 또는 DESC, 기본값: DESC)
|
||||
* @param string|null $scopePermission 스코프 권한 식별자 (null 이면 스코프 필터 미적용)
|
||||
* @param int|null $boardId 게시판 ID (전달 시 Board 재조회 생략)
|
||||
* @return Collection 정렬된 댓글 컬렉션
|
||||
*/
|
||||
public function getByPostId(string $slug, int $postId, bool $withTrashed = false, string $orderDirection = 'DESC', ?string $scopePermission = null, ?int $boardId = null): Collection;
|
||||
@@ -35,22 +37,28 @@ interface CommentRepositoryInterface
|
||||
/**
|
||||
* ID로 댓글을 조회합니다.
|
||||
*
|
||||
* $postId 를 전달하면 해당 게시글에 속한 댓글만 조회합니다 (교차 게시글 접근 차단).
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param int|null $postId 상위 게시글 ID (null 이면 게시판 범위 전체)
|
||||
* @return Comment|null 댓글 모델 또는 null
|
||||
*/
|
||||
public function find(string $slug, int $id): ?Comment;
|
||||
public function find(string $slug, int $id, ?int $postId = null): ?Comment;
|
||||
|
||||
/**
|
||||
* ID로 댓글을 조회하며, 없으면 예외를 발생시킵니다.
|
||||
*
|
||||
* $postId 를 전달하면 해당 게시글에 속한 댓글만 조회합니다 (교차 게시글 접근 차단).
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param int|null $postId 상위 게시글 ID (null 이면 게시판 범위 전체)
|
||||
* @return Comment 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail(string $slug, int $id): Comment;
|
||||
public function findOrFail(string $slug, int $id, ?int $postId = null): Comment;
|
||||
|
||||
/**
|
||||
* 댓글을 수정합니다.
|
||||
@@ -94,6 +102,7 @@ interface CommentRepositoryInterface
|
||||
* @param string $status 변경할 상태 (blinded/deleted)
|
||||
* @param array $actionLog 작업 이력 데이터
|
||||
* @param string|null $triggerType 트리거 유형 (report, admin, auto_hide 등)
|
||||
* @return Comment 상태가 변경된 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
|
||||
@@ -23,10 +23,12 @@ class CommentValidationRule implements ValidationRule
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param string $validationType 검증 타입 ('post' 또는 'parent_comment')
|
||||
* @param int|null $postId 상위 게시글 ID (parent_comment 검증 시 부모 댓글의 소속 게시글 확인용)
|
||||
*/
|
||||
public function __construct(
|
||||
private string $slug,
|
||||
private string $validationType = 'post'
|
||||
private string $validationType = 'post',
|
||||
private ?int $postId = null
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -89,7 +91,10 @@ class CommentValidationRule implements ValidationRule
|
||||
{
|
||||
$board = Board::where('slug', $this->slug)->first();
|
||||
$parentComment = $board
|
||||
? Comment::where('board_id', $board->id)->withTrashed()->find($parentId)
|
||||
? Comment::where('board_id', $board->id)
|
||||
->when($this->postId !== null, fn ($query) => $query->where('post_id', $this->postId))
|
||||
->withTrashed()
|
||||
->find($parentId)
|
||||
: null;
|
||||
|
||||
if (! $parentComment) {
|
||||
|
||||
@@ -89,12 +89,14 @@ class CommentService
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param int|null $postId 상위 게시글 ID (전달 시 해당 게시글의 댓글로 조회 범위 제한)
|
||||
* @return Comment 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getComment(string $slug, int $id): Comment
|
||||
public function getComment(string $slug, int $id, ?int $postId = null): Comment
|
||||
{
|
||||
return $this->commentRepository->findOrFail($slug, $id);
|
||||
return $this->commentRepository->findOrFail($slug, $id, $postId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,6 +230,7 @@ class CommentService
|
||||
*
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param array $data 댓글 생성 데이터
|
||||
* @return Comment 생성된 댓글 모델
|
||||
*
|
||||
* @throws \Exception 블라인드/삭제된 게시글에 댓글 작성 시
|
||||
*/
|
||||
@@ -251,10 +254,11 @@ class CommentService
|
||||
|
||||
// depth 자동 계산 (답글인 경우)
|
||||
if (! empty($data['parent_id'])) {
|
||||
$parentComment = $this->commentRepository->find($slug, $data['parent_id']);
|
||||
// 같은 게시글에 속한 부모 댓글만 인정 (교차 게시글 부모 차단)
|
||||
$parentComment = $this->commentRepository->find($slug, $data['parent_id'], (int) $data['post_id']);
|
||||
if ($parentComment) {
|
||||
// 부모 댓글의 depth + 1 (최대 5까지)
|
||||
$data['depth'] = min(($parentComment->depth ?? 0) + 1, 5);
|
||||
// 부모 댓글의 depth + 1 — 상한은 CommentValidationRule 이 게시판 설정으로 검증
|
||||
$data['depth'] = ($parentComment->depth ?? 0) + 1;
|
||||
} else {
|
||||
// 부모 댓글을 찾을 수 없으면 0으로 설정
|
||||
$data['depth'] = 0;
|
||||
@@ -282,12 +286,14 @@ class CommentService
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param array $data 수정할 데이터
|
||||
* @param int|null $postId 상위 게시글 ID (전달 시 해당 게시글의 댓글로 조회 범위 제한)
|
||||
* @return Comment 수정된 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function updateComment(string $slug, int $id, array $data): Comment
|
||||
public function updateComment(string $slug, int $id, array $data, ?int $postId = null): Comment
|
||||
{
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id);
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id, $postId);
|
||||
|
||||
// 훅: before_update
|
||||
HookManager::doAction('sirsoft-board.comment.before_update', $comment, $data, $slug);
|
||||
@@ -312,12 +318,14 @@ class CommentService
|
||||
* @param string $slug 게시판 슬러그
|
||||
* @param int $id 댓글 ID
|
||||
* @param string|null $triggerType 트리거 유형 (admin, user, report 등)
|
||||
* @param int|null $postId 상위 게시글 ID (전달 시 해당 게시글의 댓글로 조회 범위 제한)
|
||||
* @return bool 삭제 성공 여부
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function deleteComment(string $slug, int $id, ?string $triggerType = null): bool
|
||||
public function deleteComment(string $slug, int $id, ?string $triggerType = null, ?int $postId = null): bool
|
||||
{
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id);
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id, $postId);
|
||||
|
||||
// 훅: before_delete
|
||||
HookManager::doAction('sirsoft-board.comment.before_delete', $comment, $slug);
|
||||
@@ -345,12 +353,14 @@ class CommentService
|
||||
* @param int $id 댓글 ID
|
||||
* @param string $reason 블라인드 사유
|
||||
* @param string|null $triggerType 트리거 유형 (report, admin, auto_hide 등)
|
||||
* @param int|null $postId 상위 게시글 ID (전달 시 해당 게시글의 댓글로 조회 범위 제한)
|
||||
* @return Comment 블라인드 처리된 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function blindComment(string $slug, int $id, string $reason, ?string $triggerType = null): Comment
|
||||
public function blindComment(string $slug, int $id, string $reason, ?string $triggerType = null, ?int $postId = null): Comment
|
||||
{
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id);
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id, $postId);
|
||||
|
||||
// 멱등성: 이미 블라인드 상태이면 중복 처리 방지
|
||||
if ($comment->status === PostStatus::Blinded) {
|
||||
@@ -379,12 +389,14 @@ class CommentService
|
||||
* @param int $id 댓글 ID
|
||||
* @param string|null $reason 복원 사유
|
||||
* @param string|null $triggerType 트리거 유형 (report, admin, auto_hide 등)
|
||||
* @param int|null $postId 상위 게시글 ID (전달 시 해당 게시글의 댓글로 조회 범위 제한)
|
||||
* @return Comment 복원된 댓글 모델
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function restoreComment(string $slug, int $id, ?string $reason = null, ?string $triggerType = null): Comment
|
||||
public function restoreComment(string $slug, int $id, ?string $reason = null, ?string $triggerType = null, ?int $postId = null): Comment
|
||||
{
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id);
|
||||
$comment = $this->commentRepository->findOrFail($slug, $id, $postId);
|
||||
|
||||
// 멱등성: 이미 게시됨 상태이면 중복 처리 방지
|
||||
if ($comment->status === PostStatus::Published) {
|
||||
|
||||
Reference in new issue
Block a user