Skip to content

Commit 1366b10

Browse files
fix: allow professor reserve room 8L (#366)
1 parent efccd3e commit 1366b10

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/main/kotlin/com/wafflestudio/csereal/common/utils/Utils.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ fun isCurrentUserStaff(): Boolean {
5050
return "ROLE_STAFF" in getCurrentUserRoles()
5151
}
5252

53+
fun isCurrentUserStaffOrProfessor(): Boolean {
54+
val roles = getCurrentUserRoles()
55+
return "ROLE_STAFF" in roles || "ROLE_PROFESSOR" in roles
56+
}
57+
5358
fun getCurrentUserRoles(): List<String> {
5459
val authentication = SecurityContextHolder.getContext().authentication ?: /* for test */ return listOf("ROLE_STAFF")
5560
return authentication.authorities.map { it.authority }

src/main/kotlin/com/wafflestudio/csereal/core/reservation/service/ReservationService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.reservation.service
22

33
import com.wafflestudio.csereal.common.CserealException
44
import com.wafflestudio.csereal.common.utils.isCurrentUserStaff
5+
import com.wafflestudio.csereal.common.utils.isCurrentUserStaffOrProfessor
56
import com.wafflestudio.csereal.core.reservation.database.*
67
import com.wafflestudio.csereal.core.reservation.dto.ReservationDto
78
import com.wafflestudio.csereal.core.reservation.dto.ReserveRequest
@@ -40,7 +41,12 @@ class ReservationServiceImpl(
4041
roomRepository.findRoomById(reserveRequest.roomId) ?: throw CserealException.Csereal404("Room Not Found")
4142

4243
// 현재 일반 예약 권한으로 교수회의실 제외한 세미나실만 예약 가능 (행정실 요청)
43-
if (!isCurrentUserStaff() && (reserveRequest.roomId == 8L || room.type != RoomType.SEMINAR)) {
44+
if (!isCurrentUserStaff() && room.type != RoomType.SEMINAR) {
45+
throw CserealException.Csereal403("예약 불가. 행정실 문의 바람")
46+
}
47+
48+
// 세미나실 중 교수회의실은 스태프 또는 교수만 예약 가능
49+
if (!isCurrentUserStaffOrProfessor() && reserveRequest.roomId == 8L) {
4450
throw CserealException.Csereal403("예약 불가. 행정실 문의 바람")
4551
}
4652

src/main/kotlin/com/wafflestudio/csereal/core/user/service/CustomOidcUserService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class CustomOidcUserService(
5151
if ("professor" in groups || "graduate" in groups) {
5252
authorities.add(SimpleGrantedAuthority("ROLE_RESERVATION"))
5353
}
54+
if ("professor" in groups) {
55+
authorities.add(SimpleGrantedAuthority("ROLE_PROFESSOR"))
56+
}
5457
if ("student-council" in groups) {
5558
authorities.add(SimpleGrantedAuthority("ROLE_COUNCIL"))
5659
}

0 commit comments

Comments
 (0)