feature #8: Add security for Vote Article
This commit is contained in:
28
src/main/kotlin/fr/dcproject/security/voter/VoteVoter.kt
Normal file
28
src/main/kotlin/fr/dcproject/security/voter/VoteVoter.kt
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user