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:
2020-02-12 14:46:36 +01:00
parent ec6e39b130
commit 4a2d18ff87
24 changed files with 411 additions and 45 deletions

View 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
}
}