Create route for Opinions
create OpinionRepository create OpinionVoter create OpinionChoiceRef create extention String.toUUID() and List<String>.toUUID() create OpinionAggregation create interface RequestBuilderWithCreator for create entity by request rename opinion_list to opinion_choice create sql function find_citizen_opinions fix sql function find_citizen_opinions_by_target_id fix sql funciton find_opinion_choices
This commit is contained in:
53
src/main/kotlin/fr/dcproject/security/voter/OpinionVoter.kt
Normal file
53
src/main/kotlin/fr/dcproject/security/voter/OpinionVoter.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
package fr.dcproject.security.voter
|
||||
|
||||
import fr.dcproject.entity.Opinion
|
||||
import io.ktor.application.ApplicationCall
|
||||
|
||||
class OpinionVoter : Voter {
|
||||
enum class Action : ActionI {
|
||||
CREATE,
|
||||
VIEW,
|
||||
DELETE
|
||||
}
|
||||
|
||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||
return (action is Action)
|
||||
.and(subject is Opinion<*>? || subject is List<*>)
|
||||
}
|
||||
|
||||
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.VIEW) {
|
||||
if (subject is Opinion<*>) {
|
||||
return Vote.GRANTED
|
||||
}
|
||||
if (subject is List<*>) {
|
||||
subject.forEach {
|
||||
if (it !is Opinion<*>) {
|
||||
return Vote.DENIED
|
||||
}
|
||||
}
|
||||
return Vote.GRANTED
|
||||
}
|
||||
return Vote.DENIED
|
||||
}
|
||||
|
||||
if (action == Action.DELETE) {
|
||||
return if (subject is Opinion<*>
|
||||
&& user != null
|
||||
&& subject.createdBy.user.id == user.id)
|
||||
Vote.GRANTED
|
||||
else Vote.DENIED
|
||||
}
|
||||
|
||||
if (action is Action) {
|
||||
return Vote.DENIED
|
||||
}
|
||||
|
||||
return Vote.ABSTAIN
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user