#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

@@ -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