#42 Add tests for WorkgroupVoter

This commit is contained in:
2020-03-17 14:53:56 +01:00
parent c0becd8fbd
commit 890c84c762
3 changed files with 211 additions and 16 deletions

View File

@@ -6,7 +6,7 @@ import fr.postgresjson.entity.mutable.EntityDeletedAtImp
import java.util.*
class Workgroup(
id: UUID?,
id: UUID? = null,
name: String,
description: String,
logo: String? = null,
@@ -28,7 +28,7 @@ class Workgroup(
EntityUpdatedAt by EntityUpdatedAtImp()
open class WorkgroupSimple<Z : CitizenRef>(
id: UUID?,
id: UUID? = null,
var name: String,
var description: String,
var logo: String? = null,
@@ -40,7 +40,7 @@ open class WorkgroupSimple<Z : CitizenRef>(
EntityDeletedAt by EntityDeletedAtImp()
open class WorkgroupRef(
id: UUID?
id: UUID? = null
) : UuidEntity(id ?: UUID.randomUUID()), WorkgroupI
interface WorkgroupWithAuthI<Z : CitizenWithUserI> : WorkgroupWithMembersI<Z>, EntityCreatedBy<Z>, EntityDeletedAt {

View File

@@ -15,7 +15,7 @@ class WorkgroupVoter : Voter {
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
return (action is Action)
.and(subject is List<*> || subject is WorkgroupI?)
.and(subject is WorkgroupI?)
}
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
@@ -31,14 +31,6 @@ class WorkgroupVoter : Voter {
else if (subject.anonymous && user != null && subject.isMember(user)) Vote.GRANTED
else Vote.DENIED
}
if (subject is List<*>) {
subject.forEach {
if (it !is WorkgroupWithAuthI<*> || it.isDeleted()) {
return Vote.DENIED
}
}
return Vote.GRANTED
}
return Vote.DENIED
}
@@ -52,10 +44,9 @@ class WorkgroupVoter : Voter {
}
return Vote.DENIED
}
if (action is Action) {
return Vote.DENIED
} else if (subject !is WorkgroupWithAuthI<*> && (action == Action.DELETE || action == Action.UPDATE)) {
throw object :
VoterException("Unable to define if your are granted, the subject must implement 'WorkgroupWithAuthI'") {}
}
return Vote.ABSTAIN