Remove org model; make AppUser global with super admin
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:
@@ -1,5 +1,6 @@
|
||||
package com.android.trisolarisserver.component
|
||||
|
||||
import com.android.trisolarisserver.repo.AppUserRepo
|
||||
import com.android.trisolarisserver.repo.PropertyUserRepo
|
||||
import com.android.trisolarisserver.models.property.Role
|
||||
import org.springframework.security.access.AccessDeniedException
|
||||
@@ -8,14 +9,19 @@ import java.util.UUID
|
||||
|
||||
@Component
|
||||
class PropertyAccess(
|
||||
private val repo: PropertyUserRepo
|
||||
private val repo: PropertyUserRepo,
|
||||
private val appUserRepo: AppUserRepo
|
||||
) {
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user