Refactor Voter
This commit is contained in:
@@ -28,13 +28,8 @@ class ArticleVoter: Voter {
|
|||||||
return Vote.GRANTED
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == CommentVoter.Action.CREATE) {
|
if (action is CommentVoter.Action) return voteForComment(action)
|
||||||
return Vote.GRANTED
|
if (action is VoteVoter.Action) return voteForVote(action, subject)
|
||||||
}
|
|
||||||
|
|
||||||
if (action == CommentVoter.Action.VIEW) {
|
|
||||||
return Vote.GRANTED
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subject is ArticleEntity) {
|
if (subject is ArticleEntity) {
|
||||||
if (action == Action.DELETE && user is User && subject.createdBy?.userId == user.id) {
|
if (action == Action.DELETE && user is User && subject.createdBy?.userId == user.id) {
|
||||||
@@ -48,6 +43,14 @@ class ArticleVoter: Voter {
|
|||||||
return Vote.DENIED
|
return Vote.DENIED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action is Action) {
|
||||||
|
return Vote.DENIED
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vote.ABSTAIN
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun voteForVote(action: VoteVoter.Action, subject: Any?): Vote {
|
||||||
if (action == VoteVoter.Action.CREATE && subject is VoteEntity<*>) {
|
if (action == VoteVoter.Action.CREATE && subject is VoteEntity<*>) {
|
||||||
val target = subject.target
|
val target = subject.target
|
||||||
if (target !is ArticleEntity) {
|
if (target !is ArticleEntity) {
|
||||||
@@ -57,9 +60,16 @@ class ArticleVoter: Voter {
|
|||||||
return Vote.DENIED
|
return Vote.DENIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Vote.ABSTAIN
|
||||||
|
}
|
||||||
|
|
||||||
if (action is Action) {
|
private fun voteForComment(action: CommentVoter.Action): Vote {
|
||||||
return Vote.DENIED
|
if (action == CommentVoter.Action.CREATE) {
|
||||||
|
return Vote.GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == CommentVoter.Action.VIEW) {
|
||||||
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
return Vote.ABSTAIN
|
return Vote.ABSTAIN
|
||||||
|
|||||||
@@ -27,14 +27,6 @@ class ConstitutionVoter: Voter {
|
|||||||
return Vote.GRANTED
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == CommentVoter.Action.CREATE) {
|
|
||||||
return Vote.GRANTED
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == CommentVoter.Action.VIEW) {
|
|
||||||
return Vote.GRANTED
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == Action.DELETE && user is User && subject is ConstitutionEntity && subject.createdBy?.userId == user.id) {
|
if (action == Action.DELETE && user is User && subject is ConstitutionEntity && subject.createdBy?.userId == user.id) {
|
||||||
return Vote.GRANTED
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
@@ -43,6 +35,17 @@ class ConstitutionVoter: Voter {
|
|||||||
return Vote.GRANTED
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action is CommentVoter.Action) return voteForComment(action)
|
||||||
|
if (action is VoteVoter.Action) return voteForVote(action, subject)
|
||||||
|
|
||||||
|
if (action is Action) {
|
||||||
|
return Vote.DENIED
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vote.ABSTAIN
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun voteForVote(action: VoteVoter.Action, subject: Any?): Vote {
|
||||||
if (action == VoteVoter.Action.CREATE && subject is VoteEntity<*>) {
|
if (action == VoteVoter.Action.CREATE && subject is VoteEntity<*>) {
|
||||||
val target = subject.target
|
val target = subject.target
|
||||||
if (target !is ConstitutionEntity) {
|
if (target !is ConstitutionEntity) {
|
||||||
@@ -52,9 +55,16 @@ class ConstitutionVoter: Voter {
|
|||||||
return Vote.DENIED
|
return Vote.DENIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Vote.ABSTAIN
|
||||||
|
}
|
||||||
|
|
||||||
if (action is Action) {
|
private fun voteForComment(action: CommentVoter.Action): Vote {
|
||||||
return Vote.DENIED
|
if (action == CommentVoter.Action.CREATE) {
|
||||||
|
return Vote.GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == CommentVoter.Action.VIEW) {
|
||||||
|
return Vote.GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
return Vote.ABSTAIN
|
return Vote.ABSTAIN
|
||||||
|
|||||||
Reference in New Issue
Block a user