Remove sub directories

This commit is contained in:
2020-05-12 10:07:01 +02:00
parent 678a2f48d2
commit 4504600268
77 changed files with 1 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
package fr.dcproject.security.voter
import fr.dcproject.user
import fr.ktorVoter.ActionI
import fr.ktorVoter.Vote
import fr.ktorVoter.Voter
import io.ktor.application.ApplicationCall
import fr.dcproject.entity.Follow as FollowEntity
import fr.dcproject.entity.User as UserEntity
class FollowVoter : Voter {
enum class Action : ActionI {
CREATE,
DELETE,
VIEW
}
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
return (action is Action)
.and(subject is FollowEntity<*>?)
}
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
val user = call.user
if (action == Action.CREATE) {
return if (user != null) Vote.GRANTED
else Vote.DENIED
}
if (action == Action.DELETE) {
return if (user != null) Vote.GRANTED
else Vote.DENIED
}
if (action == Action.VIEW) {
if (subject is FollowEntity<*>) {
return voteView(user, subject)
}
return Vote.DENIED
}
return Vote.ABSTAIN
}
private fun voteView(user: UserEntity?, subject: FollowEntity<*>): Vote {
return if ((user != null && subject.createdBy.user.id == user.id) || !subject.createdBy.followAnonymous) Vote.GRANTED
else Vote.DENIED
}
}