Improve property access denial reasons
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
This commit is contained in:
@@ -14,15 +14,25 @@ class PropertyAccess(
|
||||
) {
|
||||
fun requireMember(propertyId: UUID, userId: UUID) {
|
||||
val user = appUserRepo.findById(userId).orElse(null)
|
||||
if (user?.superAdmin == true) return
|
||||
if (!repo.existsByIdPropertyIdAndIdUserId(propertyId, userId))
|
||||
throw AccessDeniedException("No access to property")
|
||||
if (user == null) {
|
||||
throw AccessDeniedException("No access to property (user not found)")
|
||||
}
|
||||
if (user.superAdmin) {
|
||||
return
|
||||
}
|
||||
if (!repo.existsByIdPropertyIdAndIdUserId(propertyId, userId)) {
|
||||
throw AccessDeniedException("No access to property (not a member)")
|
||||
}
|
||||
}
|
||||
|
||||
fun requireAnyRole(propertyId: UUID, userId: UUID, vararg roles: Role) {
|
||||
val user = appUserRepo.findById(userId).orElse(null)
|
||||
if (user?.superAdmin == true) return
|
||||
if (!repo.hasAnyRole(propertyId, userId, roles.toSet()))
|
||||
throw AccessDeniedException("Missing role")
|
||||
if (user == null) {
|
||||
throw AccessDeniedException("Missing role (user not found)")
|
||||
}
|
||||
if (user.superAdmin) return
|
||||
if (!repo.hasAnyRole(propertyId, userId, roles.toSet())) {
|
||||
throw AccessDeniedException("Missing role (no matching roles)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user