feature #8: Add security for Vote Article

This commit is contained in:
2019-08-30 14:34:24 +02:00
parent 3e21884b38
commit d1999d84ca
5 changed files with 77 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
package fr.dcproject.security.voter
import io.ktor.application.ApplicationCall
import fr.dcproject.entity.Vote as VoteEntity
class VoteVoter: Voter {
enum class Action: ActionI {
CREATE,
VIEW
}
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
return action is Action && subject is VoteEntity<*>?
}
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
val user = call.user
if (action == Action.CREATE && user != null) {
return Vote.GRANTED
}
if (action == Action.VIEW) {
return Vote.GRANTED
}
return Vote.ABSTAIN
}
}