Skip to content

Commit 559b753

Browse files
committed
cache RoleService.isSupervisor
1 parent 0702851 commit 559b753

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/kotlin/ch/uzh/ifi/access/config/CacheConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CacheConfig {
2424
"RoleService.getUserResourceById",
2525
"RoleService.getOnlineCount",
2626
"RoleService.getUserId",
27+
"RoleService.isSupervisor",
2728
"PointsService.calculateTaskPoints",
2829
"PointsService.calculateAssignmentPoints",
2930
"PointsService.getMaxPoints",

src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class RoleService(
228228
searchNames.forEach {
229229
cacheManager.getCache("RoleService.findUserByAllCriteria")?.evict(it);
230230
cacheManager.getCache("RoleService.getRegistrationIDCandidates")?.evict(it);
231+
// TODO: probably should also evict isSupervisor here, but it's an edge case
231232
}
232233
// check all courses if the user has been registered under one of the possible identifiers
233234
val roles = proxy.getUserRoles(searchNames)
@@ -250,6 +251,7 @@ class RoleService(
250251
}
251252
}
252253

254+
@CacheEvict("RoleService.isSupervisor", allEntries = true)
253255
fun updateRoleUsers(course: Course, toRemove: List<String>, toAdd: List<String>, role: Role) {
254256
val roleName = role.withCourse(course.slug)
255257
val realmRoleRepresentation = getRoleByName(roleName).toRepresentation()
@@ -326,7 +328,12 @@ class RoleService(
326328
val registrationID = getCurrentUsername()
327329
val user = proxy.findUserByAllCriteria(registrationID)
328330
?: throw Exception("User with registrationID $registrationID not found")
331+
return proxy.isSupervisor(courseSlug, user)
329332

333+
}
334+
335+
@Cacheable("RoleService.isSupervisor", key = "#courseSlug + '-' + #user.id")
336+
fun isSupervisor(courseSlug: String, user: UserRepresentation): Boolean {
330337
val roles = user.toResource().roles().realmLevel().listEffective()
331338
return roles.any { listOf("${courseSlug}-supervisor", "supervisor").contains(it.name) }
332339
}

0 commit comments

Comments
 (0)