Create OpinionChoice

This commit is contained in:
2020-02-11 23:03:12 +01:00
parent 42781565dd
commit ec6e39b130
8 changed files with 127 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
package fr.dcproject.security.voter
import fr.dcproject.entity.OpinionChoice
import io.ktor.application.ApplicationCall
class OpinionChoiceVoter : Voter {
enum class Action : ActionI {
VIEW
}
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
return (action is Action)
.and(subject is OpinionChoice? || subject is List<*>)
}
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
if (action == Action.VIEW) {
if (subject is OpinionChoice) {
return Vote.GRANTED
}
if (subject is List<*>) {
subject.forEach {
if (it !is OpinionChoice) {
return Vote.DENIED
}
}
return Vote.GRANTED
}
return Vote.DENIED
}
return Vote.ABSTAIN
}
}