refactor Voter

This commit is contained in:
2019-08-30 14:01:53 +02:00
parent 16b71fb1e6
commit bc75f5d9e2
3 changed files with 15 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
package fr.dcproject.security.voter
import fr.dcproject.entity.Article
import fr.dcproject.entity.User
import io.ktor.application.ApplicationCall
import fr.dcproject.entity.Article as ArticleEntity
class ArticleVoter: Voter {
enum class Action: ActionI {
@@ -34,14 +34,18 @@ class ArticleVoter: Voter {
return Vote.GRANTED
}
if (action == Action.DELETE && user is User && subject is Article && subject.createdBy?.userId == user.id) {
if (action == Action.DELETE && user is User && subject is ArticleEntity && subject.createdBy?.userId == user.id) {
return Vote.GRANTED
}
if (action == Action.UPDATE && user is User && subject is Article && subject.createdBy?.userId == user.id) {
if (action == Action.UPDATE && user is User && subject is ArticleEntity && subject.createdBy?.userId == user.id) {
return Vote.GRANTED
}
if (action is Action) {
return Vote.DENIED
}
return Vote.ABSTAIN
}
}

View File

@@ -37,6 +37,10 @@ class CitizenVoter: Voter {
return Vote.GRANTED
}
if (action is Action) {
return Vote.DENIED
}
return Vote.ABSTAIN
}
}

View File

@@ -33,6 +33,10 @@ class CommentVoter: Voter {
return Vote.DENIED
}
if (action is Action) {
return Vote.DENIED
}
return Vote.ABSTAIN
}
}