Improve property access denial reasons
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s

This commit is contained in:
androidlover5842
2026-01-27 01:26:06 +05:30
parent ce75e9536c
commit d32c89d768

View File

@@ -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)")
}
} }
} }