fix(board): 비밀글 반응 노출 결함 수정 + 반응 버튼 UX 개선 + E2E 결함 수정
- 열람 권한 없는 비밀글에 추천/비추천을 남길 수 있던 결함을 서버(ReactionService)와 화면(반응 영역 미노출) 양쪽에서 차단. 신고 기능과 동일한 권한 판정 기준 재사용. - 반응 버튼 UX를 다듬어 활성 상태는 색상으로만 표시하고, 클릭 순간에만 살짝 눌리는 촉각 피드백(active:scale-95)을 추가. - 이슈 명세 재검토 중 describe.skip 상태였던 반응 E2E spec 에서 결함 3건 발견·수정: 대상 게시판/게시글이 실제로 반응 불가능한 대상이었던 점, 3단계(해제) 검증이 값 우연 일치로 거짓 통과 가능했던 점을 고치고 실제 실행으로 통과 확인.
This commit is contained in:
1 parent
6510ce9d9c
commit
6490b339dd
13 files changed
+193
-34
No files matched your search
@@ -13,7 +13,7 @@
|
||||
|
||||
### Added
|
||||
|
||||
- 게시글에 추천·비추천 반응을 남길 수 있는 기능을 추가했습니다. 로그인한 회원은 게시글 상세에서 반응을 남기거나 다른 반응으로 바꾸거나 취소할 수 있고, 각 반응의 개수가 항상 함께 표시됩니다. 본인이 쓴 글에는 반응할 수 없습니다. 게시판 관리 설정에서 반응 사용 여부와 사용할 반응 유형(추천·비추천)을 게시판별로 켜고 끌 수 있으며, 새 게시판을 만들 때 적용될 기본값도 환경설정에서 지정합니다.
|
||||
- 게시글에 추천·비추천 반응을 남길 수 있는 기능을 추가했습니다. 로그인한 회원은 게시글 상세에서 반응을 남기거나 다른 반응으로 바꾸거나 취소할 수 있고, 각 반응의 개수가 항상 함께 표시됩니다. 본인이 쓴 글에는 반응할 수 없으며, 열람 권한이 없어 본문을 볼 수 없는 비밀글에는 반응 버튼이 표시되지 않고 반응도 남길 수 없습니다. 게시판 관리 설정에서 반응 사용 여부와 사용할 반응 유형(추천·비추천)을 게시판별로 켜고 끌 수 있으며, 새 게시판을 만들 때 적용될 기본값도 환경설정에서 지정합니다.
|
||||
- 사이트맵에 담을 게시판·게시글 수의 안전 상한을 지원합니다. 상한을 설정하면 게시판 목록·게시판·게시글 어느 항목이든 그 수를 넘지 않으며, 상한에 걸려 일부가 빠진 경우 기록으로 남습니다.
|
||||
- 게시글·게시판을 공개/비공개로 바꾸거나 삭제하면 사이트맵에 해당 항목만 자동으로 반영됩니다. 전체를 다시 만들지 않고 바뀐 부분만 갱신하므로 게시글이 많은 사이트에서도 빠르게 최신 상태가 유지됩니다.
|
||||
- 게시판 알림 설정 화면에서도 코어와 동일하게 카카오 알림톡 템플릿을 연결할 수 있습니다(비즈뿌리오 플러그인 설치 시).
|
||||
|
||||
@@ -19,7 +19,7 @@ use Illuminate\Http\JsonResponse;
|
||||
class ReactionNotAllowedException extends Exception
|
||||
{
|
||||
/**
|
||||
* @param string $reason 거절 사유 (disabled | inactive_type | self_post)
|
||||
* @param string $reason 거절 사유 (disabled | inactive_type | self_post | secret_denied)
|
||||
* @param string $message 사용자에게 보일 메시지
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -59,6 +59,16 @@ class ReactionNotAllowedException extends Exception
|
||||
return new self('self_post', __('sirsoft-board::messages.reaction.self_post'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 열람 권한이 없는 비밀글 반응 시도에 대한 예외를 생성합니다.
|
||||
*
|
||||
* @return self 비밀글 열람 권한 없음 사유 예외
|
||||
*/
|
||||
public static function secretDenied(): self
|
||||
{
|
||||
return new self('secret_denied', __('sirsoft-board::messages.reaction.secret_denied'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 거절 사유를 반환합니다.
|
||||
*
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
namespace Modules\Sirsoft\Board\Services;
|
||||
|
||||
use App\Enums\PermissionType;
|
||||
use App\Extension\HookManager;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Board\Exceptions\PostNotFoundException;
|
||||
use Modules\Sirsoft\Board\Exceptions\ReactionNotAllowedException;
|
||||
use Modules\Sirsoft\Board\Models\Board;
|
||||
use Modules\Sirsoft\Board\Models\Post;
|
||||
use Modules\Sirsoft\Board\Repositories\Contracts\PostRepositoryInterface;
|
||||
use Modules\Sirsoft\Board\Repositories\Contracts\ReactionRepositoryInterface;
|
||||
use Modules\Sirsoft\Board\Repositories\Contracts\ReactionTypeRepositoryInterface;
|
||||
use Modules\Sirsoft\Board\Traits\ChecksBoardPermission;
|
||||
|
||||
/**
|
||||
* 반응 서비스
|
||||
@@ -21,6 +22,8 @@ use Modules\Sirsoft\Board\Repositories\Contracts\ReactionTypeRepositoryInterface
|
||||
*/
|
||||
class ReactionService
|
||||
{
|
||||
use ChecksBoardPermission;
|
||||
|
||||
/**
|
||||
* 현재 지원하는 반응 대상 타입 (확정 10 — 게시글만, 향후 comment 확장 가능).
|
||||
*/
|
||||
@@ -76,6 +79,14 @@ class ReactionService
|
||||
throw ReactionNotAllowedException::selfPost();
|
||||
}
|
||||
|
||||
// 비밀글 반응 차단 — 본문 열람 권한이 없는 사용자는 반응 불가.
|
||||
// 신고(PostResource::canViewSecretContent)와 동일한 판정을 재사용해,
|
||||
// 본문을 못 보는 사용자가 반응만 남기는 우회를 막는다.
|
||||
// 작성자 본인은 위에서 이미 차단되므로 여기서는 게시판별 비밀글 열람 권한만 본다.
|
||||
if ($post->is_secret && ! $this->canReactToSecretPost($board->slug)) {
|
||||
throw ReactionNotAllowedException::secretDenied();
|
||||
}
|
||||
|
||||
// 요청 유형이 존재하는 활성 유형이면서 게시판이 켠 유형인지 확인 (확정 11)
|
||||
$requestedType = $this->reactionTypeRepository->findById($reactionTypeId);
|
||||
$activeCodes = $board->active_reaction_types ?? [];
|
||||
@@ -150,4 +161,21 @@ class ReactionService
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 비밀글에 반응할 수 있는 열람 권한이 있는지 확인합니다.
|
||||
*
|
||||
* 반응은 사용자(User) 페이지 전용 기능이므로 게시판별 비밀글 읽기 권한
|
||||
* (posts.read-secret) 또는 게시판 매니저 권한만 인정합니다. 작성자 본인은
|
||||
* 호출 이전에 이미 selfPost 로 차단되므로 여기서는 고려하지 않습니다.
|
||||
* `PostResource::canViewSecretContent` 의 게시판 권한 판정과 동일한 기준입니다.
|
||||
*
|
||||
* @param string $slug 대상 게시판 슬러그
|
||||
* @return bool 비밀글 반응 가능 여부
|
||||
*/
|
||||
private function canReactToSecretPost(string $slug): bool
|
||||
{
|
||||
return $this->checkBoardPermission($slug, 'posts.read-secret', PermissionType::User)
|
||||
|| $this->checkBoardPermission($slug, 'manager', PermissionType::User);
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@ return [
|
||||
'disabled' => 'Reactions are disabled for this board.',
|
||||
'inactive_type' => 'This reaction type is not available on this board.',
|
||||
'self_post' => 'You cannot react to your own post.',
|
||||
'secret_denied' => 'You cannot react to a secret post you are not allowed to view.',
|
||||
'login_required' => 'You need to sign in to use this feature.',
|
||||
],
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ return [
|
||||
'disabled' => '이 게시판은 반응 기능이 비활성화되어 있습니다.',
|
||||
'inactive_type' => '이 게시판에서 사용할 수 없는 반응 유형입니다.',
|
||||
'self_post' => '본인 글에는 반응할 수 없습니다.',
|
||||
'secret_denied' => '열람 권한이 없는 비밀글에는 반응할 수 없습니다.',
|
||||
'login_required' => '로그인이 필요한 기능입니다.',
|
||||
],
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Modules\Sirsoft\Board\Tests\BoardTestCase;
|
||||
* 차단, 본인 글 차단, 비로그인 차단을 종단 검증한다 (이슈 #525 §10 테스트 범위).
|
||||
*
|
||||
* @scenario case=guest_react_blocked
|
||||
*
|
||||
* @effects guest_react_returns_401
|
||||
*/
|
||||
class ReactionApiTest extends BoardTestCase
|
||||
@@ -191,6 +192,70 @@ class ReactionApiTest extends BoardTestCase
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* 비밀글에 열람 권한이 없는 사용자는 반응할 수 없다 (422, secret_denied).
|
||||
*
|
||||
* 회귀: 반응 서비스가 비밀글 열람 권한을 검사하지 않으면, 본문(content=null)을
|
||||
* 못 보는 사용자가 추천/비추천만 남기는 우회가 가능하다. 신고(canViewSecretContent)와
|
||||
* 동일하게 열람 권한 없는 비밀글 반응을 서버가 최종 차단해야 한다.
|
||||
*
|
||||
* @scenario case=secret_post_react_blocked
|
||||
*
|
||||
* @effects secret_post_without_permission_returns_422
|
||||
*/
|
||||
public function test_react_blocked_on_secret_post_without_permission(): void
|
||||
{
|
||||
$author = $this->createUser();
|
||||
$reactor = $this->createUser();
|
||||
$postId = $this->createTestPost([
|
||||
'user_id' => $author->id,
|
||||
'is_secret' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($reactor, 'sanctum')
|
||||
->postJson($this->reactUrl($postId), ['reaction_type_id' => $this->likeId])
|
||||
->assertStatus(422)
|
||||
->assertJsonPath('errors.code', 'reaction_not_allowed');
|
||||
|
||||
// 반응 이력이 남지 않아야 한다
|
||||
$this->assertDatabaseMissing('board_reactions', [
|
||||
'user_id' => $reactor->id,
|
||||
'target_id' => $postId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 비밀글 열람 권한(posts.read-secret)이 있는 사용자는 비밀글에도 반응할 수 있다.
|
||||
*
|
||||
* 비밀글 가드가 열람 권한자까지 막지 않는지 확인한다 (신고 판정과 동일 기준).
|
||||
*
|
||||
* @scenario case=secret_post_react_allowed_with_permission
|
||||
*
|
||||
* @effects secret_post_with_read_secret_permission_allows_react
|
||||
*/
|
||||
public function test_react_allowed_on_secret_post_with_read_secret_permission(): void
|
||||
{
|
||||
$this->grantUserRolePermissions(['posts.read-secret']);
|
||||
|
||||
$author = $this->createUser();
|
||||
$reactor = $this->createUser();
|
||||
$postId = $this->createTestPost([
|
||||
'user_id' => $author->id,
|
||||
'is_secret' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($reactor, 'sanctum')
|
||||
->postJson($this->reactUrl($postId), ['reaction_type_id' => $this->likeId])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.action', 'add');
|
||||
|
||||
$this->assertDatabaseHas('board_reactions', [
|
||||
'user_id' => $reactor->id,
|
||||
'target_id' => $postId,
|
||||
'reaction_type_id' => $this->likeId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시글 상세 응답의 reaction_counts 가 유형 ID 키를 보존한다 (JSON 객체, 배열 재인덱싱 금지).
|
||||
*
|
||||
@@ -230,6 +295,7 @@ class ReactionApiTest extends BoardTestCase
|
||||
* 반응 등록/전환/해제 시 활동 로그가 기록된다 (after_react 훅 → 리스너).
|
||||
*
|
||||
* @scenario case=react_logs_activity
|
||||
*
|
||||
* @effects react_logs_add_change_remove_activity
|
||||
*/
|
||||
public function test_react_writes_activity_log(): void
|
||||
|
||||
+18
-9
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
import { test, expect, authenticatePage } from '../../fixtures/board-auth';
|
||||
|
||||
const SLUG = 'notice';
|
||||
const POST_ID = 1;
|
||||
const SLUG = 'free';
|
||||
const POST_ID = 18;
|
||||
const POST_PATH = `/board/${SLUG}/${POST_ID}`;
|
||||
const REACT_API = `**/api/modules/sirsoft-board/boards/${SLUG}/posts/${POST_ID}/react`;
|
||||
|
||||
@@ -26,7 +26,7 @@ const REACT_API = `**/api/modules/sirsoft-board/boards/${SLUG}/posts/${POST_ID}/
|
||||
const LIKE_ID = 1;
|
||||
const DISLIKE_ID = 2;
|
||||
|
||||
test.describe.skip('게시판 반응 등록→전환→해제 흐름 (#525)', () => {
|
||||
test.describe('게시판 반응 등록→전환→해제 흐름 (#525)', () => {
|
||||
// @scenario surface=detail_register_switch_remove
|
||||
// @effects register_inserts_row_and_increments_count, switch_updates_row_and_adjusts_both_counts, remove_deletes_row_and_decrements_count
|
||||
test('추천 등록 → 비추천 전환 → 비추천 해제 시 버튼 하이라이트·개수가 갱신된다', async ({
|
||||
@@ -66,19 +66,28 @@ test.describe.skip('게시판 반응 등록→전환→해제 흐름 (#525)', ()
|
||||
const dislikeButton = page.getByRole('button', { name: /비추천|Not Recommend/ }).first();
|
||||
|
||||
// 1) 추천 등록 → count +1, reaction_type_id = like
|
||||
// 처리 중에는 버튼이 disabled(스피너) 되므로, 응답 도착 후 스피너가 완전히 걷히고
|
||||
// 카운트 텍스트가 갱신될 때까지 기다린 다음 다음 클릭을 보낸다 — 그렇지 않으면 아직
|
||||
// 리렌더 중인 버튼에 클릭이 씹혀 요청이 누락된다.
|
||||
// step 자체를 폴링한다(2·3단계 모두 reaction_type_id=DISLIKE_ID 로 동일하므로,
|
||||
// reactBody 값만 보면 세 번째 요청이 발생하지 않아도 이전 값과 우연히 일치해 통과해버린다).
|
||||
await likeButton.click();
|
||||
await expect.poll(() => reactBody?.reaction_type_id, { timeout: 5_000 }).toBe(LIKE_ID);
|
||||
await expect.poll(() => step, { timeout: 5_000 }).toBe(1);
|
||||
expect((reactBody as Record<string, unknown> | null)?.reaction_type_id).toBe(LIKE_ID);
|
||||
await expect(likeButton).toHaveText(/추천\s*1/, { timeout: 5_000 });
|
||||
await expect(dislikeButton).toBeEnabled({ timeout: 5_000 });
|
||||
|
||||
// 2) 비추천 전환 → like -1 · dislike +1
|
||||
await dislikeButton.click();
|
||||
await expect.poll(() => reactBody?.reaction_type_id, { timeout: 5_000 }).toBe(DISLIKE_ID);
|
||||
await expect.poll(() => step, { timeout: 5_000 }).toBe(2);
|
||||
expect((reactBody as Record<string, unknown> | null)?.reaction_type_id).toBe(DISLIKE_ID);
|
||||
await expect(dislikeButton).toHaveText(/비추천\s*1/, { timeout: 5_000 });
|
||||
await expect(dislikeButton).toBeEnabled({ timeout: 5_000 });
|
||||
|
||||
// 3) 비추천 재클릭 → 해제 (같은 유형 재요청)
|
||||
await dislikeButton.click();
|
||||
await expect.poll(() => reactBody?.reaction_type_id, { timeout: 5_000 }).toBe(DISLIKE_ID);
|
||||
|
||||
// 세 번의 react 호출이 모두 발생 (등록/전환/해제)
|
||||
expect(step).toBe(3);
|
||||
await expect.poll(() => step, { timeout: 5_000 }).toBe(3);
|
||||
expect((reactBody as Record<string, unknown> | null)?.reaction_type_id).toBe(DISLIKE_ID);
|
||||
});
|
||||
|
||||
// @scenario surface=detail_register_switch_remove
|
||||
|
||||
@@ -40,6 +40,9 @@ axes:
|
||||
- react_logs_activity
|
||||
- react_failure_rolls_back
|
||||
- react_pending_disables_button
|
||||
- secret_post_react_blocked
|
||||
- secret_post_react_allowed_with_permission
|
||||
- reaction_area_hidden_on_inaccessible_secret_post
|
||||
|
||||
effects:
|
||||
# 등록/전환/해제 + 카운트 증감 정합성
|
||||
@@ -54,6 +57,10 @@ effects:
|
||||
- inactive_type_react_returns_422
|
||||
- use_reaction_off_react_returns_422
|
||||
- post_not_in_board_returns_404
|
||||
# 비밀글 열람 권한 가드 (신고와 동일 기준)
|
||||
- secret_post_without_permission_returns_422
|
||||
- secret_post_with_read_secret_permission_allows_react
|
||||
- reaction_area_hidden_when_secret_content_inaccessible
|
||||
# 화면 렌더 (확정 09·11)
|
||||
- active_types_always_shown_even_zero_count
|
||||
- reaction_area_hidden_when_no_active_types
|
||||
|
||||
Reference in new issue
Block a user