This commit is contained in:
2021-01-14 22:53:48 +01:00
parent 91ab800272
commit caadc2a969
29 changed files with 50 additions and 56 deletions

View File

@@ -19,7 +19,6 @@ import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
import java.util.* import java.util.*
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@Location("/articles/{articleId}") @Location("/articles/{articleId}")
class ArticleRequest(val articleId: UUID) : KoinComponent { class ArticleRequest(val articleId: UUID) : KoinComponent {

View File

@@ -23,7 +23,6 @@ class CommentChildrenRequest(
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
} }
@KtorExperimentalAPI @KtorExperimentalAPI
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
fun Route.getChildrenComments(repo: CommentRepository) { fun Route.getChildrenComments(repo: CommentRepository) {

View File

@@ -16,7 +16,6 @@ import io.ktor.util.*
@Location("/comments/{comment}") @Location("/comments/{comment}")
class CommentRequest(val comment: CommentRef) class CommentRequest(val comment: CommentRef)
@KtorExperimentalAPI @KtorExperimentalAPI
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
fun Route.getOneComment(repo: CommentRepository) { fun Route.getOneComment(repo: CommentRepository) {

View File

@@ -12,4 +12,3 @@ interface Versionable {
override val versionId: UUID = parent.versionId override val versionId: UUID = parent.versionId
} }
} }

View File

@@ -40,7 +40,6 @@ interface VoteForUpdateI<T: TargetI, C: CitizenI> : VoteI, AsTarget<T>, EntityCr
override val createdBy: C override val createdBy: C
} }
open class VoteRef( open class VoteRef(
override val id: UUID override val id: UUID
) : VoteI ) : VoteI

View File

@@ -20,8 +20,8 @@ class ConstitutionVoter : Voter<ApplicationCall> {
} }
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI { override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
if(!((action is Action || action is CommentVoter.Action || action is VoteVoter.Action) if (!((action is Action || action is CommentVoter.Action || action is VoteVoter.Action) &&
&& (subject is ConstitutionSimple<*, *>? || subject is VoteEntity<*> || subject is CommentForView<*, *>))) return abstain() (subject is ConstitutionSimple<*, *>? || subject is VoteEntity<*> || subject is CommentForView<*, *>))) return abstain()
val user = context.user val user = context.user
if (action == Action.CREATE && user != null) { if (action == Action.CREATE && user != null) {

View File

@@ -11,8 +11,8 @@ class OpinionChoiceVoter : Voter<ApplicationCall> {
} }
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI { override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
if (!((action is Action) if (!((action is Action) &&
&& (subject is OpinionChoice?))) return abstain() (subject is OpinionChoice?))) return abstain()
if (action == Action.VIEW) { if (action == Action.VIEW) {
if (subject is OpinionChoice) { if (subject is OpinionChoice) {

View File

@@ -17,8 +17,8 @@ class OpinionVoter : Voter<ApplicationCall> {
} }
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI { override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
if (!((action is Action) if (!((action is Action) &&
&& (subject is Opinion<*>? || subject is ArticleAuthI<*>))) return abstain() (subject is Opinion<*>? || subject is ArticleAuthI<*>))) return abstain()
val user = context.user val user = context.user
if (action == Action.CREATE) { if (action == Action.CREATE) {

View File

@@ -27,8 +27,8 @@ class WorkgroupVoter : Voter<ApplicationCall> {
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI { override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
if ((action is Action && subject == null)) throw NoSubjectDefinedException(action) if ((action is Action && subject == null)) throw NoSubjectDefinedException(action)
if (!((action is Action || action is ActionMembers) if (!((action is Action || action is ActionMembers) &&
&& (subject is WorkgroupI? || (subject is List<*> && subject.first() is WorkgroupI)))) return abstain() (subject is WorkgroupI? || (subject is List<*> && subject.first() is WorkgroupI)))) return abstain()
val user = context.user val user = context.user
if (action == Action.CREATE) { if (action == Action.CREATE) {
@@ -38,7 +38,6 @@ class WorkgroupVoter : Voter<ApplicationCall> {
} }
} }
if (action == Action.VIEW) { if (action == Action.VIEW) {
if (subject is WorkgroupWithAuthI<*>) { if (subject is WorkgroupWithAuthI<*>) {
return if (subject.isDeleted()) denied("You cannot view a deleted workgroup", "workgroup.view.deleted") return if (subject.isDeleted()) denied("You cannot view a deleted workgroup", "workgroup.view.deleted")

View File

@@ -134,7 +134,7 @@ class ArticleVoterTest {
} }
@Test @Test
fun `can update article if yours`(): Unit { fun `can update article if yours`() {
val article = getArticle(tesla) val article = getArticle(tesla)
ArticleVoter(getRepo(article)) ArticleVoter(getRepo(article))
.canUpsert(article, tesla) .canUpsert(article, tesla)
@@ -142,7 +142,7 @@ class ArticleVoterTest {
} }
@Test @Test
fun `can not update article if not yours`(): Unit { fun `can not update article if not yours`() {
val article = getArticle(tesla) val article = getArticle(tesla)
ArticleVoter(getRepo(article)) ArticleVoter(getRepo(article))
.canUpsert(article, einstein) .canUpsert(article, einstein)

View File

@@ -125,7 +125,7 @@ internal class CommentVoterTest {
} }
@Test @Test
fun `can be view the comment`(): Unit { fun `can be view the comment`() {
listOf(CommentVoter()).run { listOf(CommentVoter()).run {
mockk<ApplicationCall> { mockk<ApplicationCall> {
every { citizenOrNull } returns tesla every { citizenOrNull } returns tesla

View File

@@ -168,7 +168,7 @@ internal class VoteVoterTest {
} }
@Test @Test
fun `can be vote an article`(): Unit { fun `can be vote an article`() {
listOf(VoteVoter()).run { listOf(VoteVoter()).run {
mockk<ApplicationCall> { mockk<ApplicationCall> {
every { citizenOrNull } returns tesla every { citizenOrNull } returns tesla