Skip to content

Commit 576aee9

Browse files
committed
[BE] [FIX] 출석 세션 오너 관련 수정
1 parent 9852543 commit 576aee9

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

backend/src/main/java/org/sejongisc/backend/attendance/controller/SessionUserController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ public ResponseEntity<SessionUserResponse> addUserToSession(
9696
## 동작 설명
9797
- 세션에서 특정 사용자를 제거
9898
- 해당 사용자가 이 세션에서 가졌던 모든 출석 기록(`Attendance`)을 함께 삭제
99+
- `OWNER`는 제거할 수 없습니다.
99100
100101
## 에러 코드
101102
- **`SESSION_NOT_FOUND`**: 해당 출석 세션이 존재하지 않습니다.
102103
- **`NOT_SESSION_OWNER`**: 세션 소유자 권한이 없습니다.
104+
- **`CANNOT_MODIFY_OWNER`**: 세션 소유자는 제거할 수 없습니다.
103105
104106
""")
105107
@DeleteMapping("/{sessionId}/users/{userId}")
@@ -206,6 +208,7 @@ public ResponseEntity<Void> addAllUsers(
206208
207209
## 동작 설명
208210
- 특정 사용자의 역할을 `MANAGER`로 격상시킵니다.
211+
- `OWNER`의 역할은 변경할 수 없습니다.
209212
""")
210213
@PostMapping("/{sessionId}/admins/{userId}")
211214
public ResponseEntity<Void> addAdminToSession(
@@ -230,7 +233,7 @@ public ResponseEntity<Void> addAdminToSession(
230233
231234
## 동작 설명
232235
- 특정 사용자의 역할을 `PARTICIPANT`로 강등시킵니다.
233-
- `OWNER`는 강등될 수 없습니다.
236+
- `OWNER`의 역할은 변경할 수 없습니다.
234237
""")
235238
@DeleteMapping("/{sessionId}/admins/{userId}")
236239
public ResponseEntity<Void> removeAdminFromSession(

backend/src/main/java/org/sejongisc/backend/attendance/service/SessionUserService.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public void removeUserFromSession(UUID sessionId, UUID targetUserId, UUID actorU
106106
attendanceSessionRepository.findById(sessionId)
107107
.orElseThrow(() -> new CustomException(ErrorCode.SESSION_NOT_FOUND));
108108

109+
SessionUser targetSessionUser = getSessionUser(sessionId, targetUserId);
110+
ensureTargetIsNotOwner(targetSessionUser);
111+
109112
// SessionUser 삭제
110113
sessionUserRepository.deleteByAttendanceSession_AttendanceSessionIdAndUser_UserId(sessionId, targetUserId);
111114

@@ -205,23 +208,28 @@ private void createAbsentForPastRounds(UUID sessionId, User user) {
205208
@Transactional
206209
public void addAdmin(UUID sessionId, UUID targetUserId, UUID actorUserId) {
207210
authorizationService.ensureOwner(sessionId, actorUserId);
208-
SessionUser su = sessionUserRepository
209-
.findByAttendanceSession_AttendanceSessionIdAndUser_UserId(sessionId, targetUserId)
210-
.orElseThrow(() -> new CustomException(ErrorCode.TARGET_NOT_SESSION_MEMBER));
211+
SessionUser su = getSessionUser(sessionId, targetUserId);
212+
ensureTargetIsNotOwner(su);
211213
su.changeRole(SessionRole.MANAGER);
212214
}
213215

214216
@Transactional
215217
public void removeAdmin(UUID sessionId, UUID targetUserId, UUID actorUserId) {
216218
authorizationService.ensureOwner(sessionId, actorUserId);
217-
SessionUser su = sessionUserRepository
219+
SessionUser su = getSessionUser(sessionId, targetUserId);
220+
ensureTargetIsNotOwner(su);
221+
su.changeRole(SessionRole.PARTICIPANT);
222+
}
223+
224+
private SessionUser getSessionUser(UUID sessionId, UUID targetUserId) {
225+
return sessionUserRepository
218226
.findByAttendanceSession_AttendanceSessionIdAndUser_UserId(sessionId, targetUserId)
219227
.orElseThrow(() -> new CustomException(ErrorCode.TARGET_NOT_SESSION_MEMBER));
228+
}
220229

221-
// OWNER를 강제로 내릴지 여부는 정책
222-
if (su.getSessionRole() == SessionRole.OWNER) {
223-
throw new CustomException(ErrorCode.CANNOT_DEMOTE_OWNER);
230+
private void ensureTargetIsNotOwner(SessionUser sessionUser) {
231+
if (sessionUser.getSessionRole() == SessionRole.OWNER) {
232+
throw new CustomException(ErrorCode.CANNOT_MODIFY_OWNER);
224233
}
225-
su.changeRole(SessionRole.PARTICIPANT);
226234
}
227235
}

backend/src/main/java/org/sejongisc/backend/common/exception/ErrorCode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public enum ErrorCode {
182182

183183
TARGET_NOT_SESSION_MEMBER(HttpStatus.BAD_REQUEST, "대상 사용자가 출석 세션의 멤버가 아닙니다."),
184184

185-
CANNOT_DEMOTE_OWNER(HttpStatus.BAD_REQUEST, "출석 세션 소유자는 강등할 수 없습니다."),
185+
CANNOT_MODIFY_OWNER(HttpStatus.BAD_REQUEST, "출석 세션 소유자는 변경하거나 제거할 수 없습니다."),
186186

187187
UNAUTHENTICATED(HttpStatus.UNAUTHORIZED, "인증되지 않은 사용자입니다."),
188188

@@ -197,4 +197,4 @@ public enum ErrorCode {
197197
this.status = status;
198198
this.message = message;
199199
}
200-
}
200+
}

0 commit comments

Comments
 (0)