diff --git a/src/main/java/com/gdghost/question/QuestionController.java b/src/main/java/com/gdghost/question/QuestionController.java index 0de7d49..60d8d7a 100644 --- a/src/main/java/com/gdghost/question/QuestionController.java +++ b/src/main/java/com/gdghost/question/QuestionController.java @@ -66,7 +66,7 @@ public CursorPage list(@AuthenticationPrincipal AuthMember me, } @Operation(summary = "질문 상세", description = "답변 트리 포함(채택 먼저, 나머지 오래된 순, depth 3까지). " - + "조회수는 부원당 하루 1회, 글쓴이 본인은 세지 않는다. 없거나 삭제 · 숨김이면 404. routing은 전달 현황, 없으면 null. 익명 질문은 reasons 빈 배열 + reasonsHidden.") + + "조회수는 부원당 하루 1회, 글쓴이 본인은 세지 않는다. 없거나 삭제 · 숨김이면 404. routing은 전달 현황, 없으면 null. 익명 질문은 reasonsHidden, 받은 본인 줄이 아니면 to null + reasons 빈 배열(운영진 단계는 그대로).") @GetMapping("/{questionId}") public QuestionDetail detail(@AuthenticationPrincipal AuthMember me, @PathVariable long questionId) { return questionService.detail(me.id(), questionId); diff --git a/src/main/java/com/gdghost/question/QuestionRouting.java b/src/main/java/com/gdghost/question/QuestionRouting.java index b7344e0..fa817d4 100644 --- a/src/main/java/com/gdghost/question/QuestionRouting.java +++ b/src/main/java/com/gdghost/question/QuestionRouting.java @@ -3,7 +3,7 @@ import java.time.Instant; import java.util.List; -/** 질문 상세의 전달 현황. 익명 질문은 reasons를 비우고 reasonsHidden = true */ +/** 질문 상세의 전달 현황. 익명 질문은 reasonsHidden = true, 내 줄이 아니면 to = null · reasons 비움(운영진 단계 제외) */ public record QuestionRouting(List deliveries, boolean reasonsHidden, Mine mine) { public record Delivery(String stage, String state, To to, List reasons, Instant sentAt) { diff --git a/src/main/java/com/gdghost/routing/QuestionRoutingAdapter.java b/src/main/java/com/gdghost/routing/QuestionRoutingAdapter.java index eb1ff77..691fd9d 100644 --- a/src/main/java/com/gdghost/routing/QuestionRoutingAdapter.java +++ b/src/main/java/com/gdghost/routing/QuestionRoutingAdapter.java @@ -76,8 +76,12 @@ public QuestionRouting view(long questionId, boolean anonymous, long viewerId) { return null; } List deliveries = rows.stream() - .map(row -> new QuestionRouting.Delivery(row.stage(), state(row, anonymous, viewerId), - new QuestionRouting.To(nickname(row)), anonymous ? List.of() : reasons(row), row.sentAt())) + .map(row -> { + boolean hide = hidden(row, anonymous, viewerId); + return new QuestionRouting.Delivery(row.stage(), state(row, anonymous, viewerId), + hide ? null : new QuestionRouting.To(nickname(row)), hide ? List.of() : reasons(row), + row.sentAt()); + }) .toList(); QuestionRouting.Mine mine = rows.stream() .filter(row -> row.memberId() == viewerId && !"STAFF".equals(row.stage())) @@ -87,6 +91,14 @@ public QuestionRouting view(long questionId, boolean anonymous, long viewerId) { return new QuestionRouting(deliveries, anonymous, mine); } + /** + * 익명 질문에서 받은 사람 이름 · 사유를 보이면 익명 답변을 쓴 사람이 좁혀진다. 글쓴이(지목한 사람 포함)에게도 가리고 + * 받은 본인에게만 보여 준다. 운영진 단계는 개인이 아니라 그대로 + */ + private static boolean hidden(RoutingReader.Delivery row, boolean anonymous, long viewerId) { + return anonymous && row.memberId() != viewerId && !"STAFF".equals(row.stage()); + } + /** 익명 질문에서 '답변함'을 보이면 익명 답변을 쓴 사람이 드러난다. 본인에게만 그대로 보여 준다 */ private static String state(RoutingReader.Delivery row, boolean anonymous, long viewerId) { boolean hide = anonymous && "ANSWERED".equals(row.state()) && row.memberId() != viewerId; diff --git a/src/test/java/com/gdghost/routing/RoutingIntegrationTest.java b/src/test/java/com/gdghost/routing/RoutingIntegrationTest.java index dae7981..9ea46f6 100644 --- a/src/test/java/com/gdghost/routing/RoutingIntegrationTest.java +++ b/src/test/java/com/gdghost/routing/RoutingIntegrationTest.java @@ -436,6 +436,7 @@ INSERT INTO routing (question_id, member_id, stage, state, sent_at) VALUES (?, ? mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(author))) .andExpect(jsonPath("$.routing.reasonsHidden").value(true)) .andExpect(jsonPath("$.routing.deliveries[0].state").value("SENT")) + .andExpect(jsonPath("$.routing.deliveries[0].to").isEmpty()) .andExpect(jsonPath("$.routing.deliveries[0].reasons").isEmpty()); mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(receiver))) .andExpect(jsonPath("$.routing.deliveries[0].state").value("ANSWERED")) @@ -443,6 +444,41 @@ INSERT INTO routing (question_id, member_id, stage, state, sent_at) VALUES (?, ? .andExpect(jsonPath("$.routing.mine.canPass").value(false)); } + @Test + void 익명_질문은_받은_사람_이름과_사유를_본인에게만_보여_준다() throws Exception { + TestMember target = candidate("인턴"); + TestMember other = fixtures.member(); + long question = fixtures.question(author.id(), true); + age(question, hours(3)); + + route(DAY); + + for (TestMember viewer : List.of(author, other)) { + mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(viewer))) + .andExpect(jsonPath("$.routing.deliveries[0].stage").value("MEMBER")) + .andExpect(jsonPath("$.routing.deliveries[0].state").value("SENT")) + .andExpect(jsonPath("$.routing.deliveries[0].to").isEmpty()) + .andExpect(jsonPath("$.routing.deliveries[0].reasons").isEmpty()); + } + mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(target))) + .andExpect(jsonPath("$.routing.reasonsHidden").value(true)) + .andExpect(jsonPath("$.routing.deliveries[0].to.nickname").value(target.nickname())) + .andExpect(jsonPath("$.routing.deliveries[0].reasons[0]").value("경험: 인턴")); + } + + @Test + void 익명_지목_질문은_글쓴이에게도_받은_사람_이름을_가린다() throws Exception { + TestMember target = fixtures.member(); + long question = fixtures.question(author.id(), true); + direct(question, target.id(), DAY); + + mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(author))) + .andExpect(jsonPath("$.routing.deliveries[0].stage").value("DIRECT")) + .andExpect(jsonPath("$.routing.deliveries[0].to").isEmpty()); + mvc.perform(get("/api/v1/questions/{id}", question).cookie(fixtures.loginCookie(target))) + .andExpect(jsonPath("$.routing.deliveries[0].to.nickname").value(target.nickname())); + } + @Test void 익명_질문은_질문자_규칙을_쓰지_않는다() { jdbc.update("UPDATE member SET department = '컴퓨터공학과', generation = 5 WHERE id = ?", author.id());