getting started
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.android.trisolarisserver.component
|
||||
|
||||
import com.android.trisolarisserver.db.repo.PropertyUserRepo
|
||||
import com.android.trisolarisserver.models.property.Role
|
||||
import org.springframework.security.access.AccessDeniedException
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.UUID
|
||||
|
||||
@Component
|
||||
class PropertyAccess(
|
||||
private val repo: PropertyUserRepo
|
||||
) {
|
||||
fun requireMember(propertyId: UUID, userId: UUID) {
|
||||
if (!repo.existsByIdPropertyIdAndIdUserId(propertyId, userId))
|
||||
throw AccessDeniedException("No access to property")
|
||||
}
|
||||
|
||||
fun requireAnyRole(propertyId: UUID, userId: UUID, vararg roles: Role) {
|
||||
if (!repo.hasAnyRole(propertyId, userId, roles.toSet()))
|
||||
throw AccessDeniedException("Missing role")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user