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) {
|
fun requireMember(propertyId: UUID, userId: UUID) {
|
||||||
val user = appUserRepo.findById(userId).orElse(null)
|
val user = appUserRepo.findById(userId).orElse(null)
|
||||||
if (user?.superAdmin == true) return
|
if (user == null) {
|
||||||
if (!repo.existsByIdPropertyIdAndIdUserId(propertyId, userId))
|
throw AccessDeniedException("No access to property (user not found)")
|
||||||
throw AccessDeniedException("No access to property")
|
}
|
||||||
|
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) {
|
fun requireAnyRole(propertyId: UUID, userId: UUID, vararg roles: Role) {
|
||||||
val user = appUserRepo.findById(userId).orElse(null)
|
val user = appUserRepo.findById(userId).orElse(null)
|
||||||
if (user?.superAdmin == true) return
|
if (user == null) {
|
||||||
if (!repo.hasAnyRole(propertyId, userId, roles.toSet()))
|
throw AccessDeniedException("Missing role (user not found)")
|
||||||
throw AccessDeniedException("Missing role")
|
}
|
||||||
|
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