Big refactoring #77
@@ -19,7 +19,6 @@ import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import java.util.*
|
||||
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@Location("/articles/{articleId}")
|
||||
class ArticleRequest(val articleId: UUID) : KoinComponent {
|
||||
|
||||
@@ -23,7 +23,6 @@ class CommentChildrenRequest(
|
||||
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
||||
}
|
||||
|
||||
|
||||
@KtorExperimentalAPI
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.getChildrenComments(repo: CommentRepository) {
|
||||
|
||||
@@ -16,7 +16,6 @@ import io.ktor.util.*
|
||||
@Location("/comments/{comment}")
|
||||
class CommentRequest(val comment: CommentRef)
|
||||
|
||||
|
||||
@KtorExperimentalAPI
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.getOneComment(repo: CommentRepository) {
|
||||
|
||||
@@ -12,4 +12,3 @@ interface Versionable {
|
||||
override val versionId: UUID = parent.versionId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ interface VoteForUpdateI<T: TargetI, C: CitizenI> : VoteI, AsTarget<T>, EntityCr
|
||||
override val createdBy: C
|
||||
}
|
||||
|
||||
|
||||
open class VoteRef(
|
||||
override val id: UUID
|
||||
) : VoteI
|
||||
|
||||
@@ -20,8 +20,8 @@ class ConstitutionVoter : Voter<ApplicationCall> {
|
||||
}
|
||||
|
||||
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
|
||||
if(!((action is Action || action is CommentVoter.Action || action is VoteVoter.Action)
|
||||
&& (subject is ConstitutionSimple<*, *>? || subject is VoteEntity<*> || subject is CommentForView<*, *>))) return abstain()
|
||||
if (!((action is Action || action is CommentVoter.Action || action is VoteVoter.Action) &&
|
||||
(subject is ConstitutionSimple<*, *>? || subject is VoteEntity<*> || subject is CommentForView<*, *>))) return abstain()
|
||||
|
||||
val user = context.user
|
||||
if (action == Action.CREATE && user != null) {
|
||||
|
||||
@@ -11,8 +11,8 @@ class OpinionChoiceVoter : Voter<ApplicationCall> {
|
||||
}
|
||||
|
||||
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
|
||||
if (!((action is Action)
|
||||
&& (subject is OpinionChoice?))) return abstain()
|
||||
if (!((action is Action) &&
|
||||
(subject is OpinionChoice?))) return abstain()
|
||||
|
||||
if (action == Action.VIEW) {
|
||||
if (subject is OpinionChoice) {
|
||||
|
||||
@@ -17,8 +17,8 @@ class OpinionVoter : Voter<ApplicationCall> {
|
||||
}
|
||||
|
||||
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
|
||||
if (!((action is Action)
|
||||
&& (subject is Opinion<*>? || subject is ArticleAuthI<*>))) return abstain()
|
||||
if (!((action is Action) &&
|
||||
(subject is Opinion<*>? || subject is ArticleAuthI<*>))) return abstain()
|
||||
|
||||
val user = context.user
|
||||
if (action == Action.CREATE) {
|
||||
|
||||
@@ -27,8 +27,8 @@ class WorkgroupVoter : Voter<ApplicationCall> {
|
||||
|
||||
override fun invoke(action: Any, context: ApplicationCall, subject: Any?): VoterResponseI {
|
||||
if ((action is Action && subject == null)) throw NoSubjectDefinedException(action)
|
||||
if (!((action is Action || action is ActionMembers)
|
||||
&& (subject is WorkgroupI? || (subject is List<*> && subject.first() is WorkgroupI)))) return abstain()
|
||||
if (!((action is Action || action is ActionMembers) &&
|
||||
(subject is WorkgroupI? || (subject is List<*> && subject.first() is WorkgroupI)))) return abstain()
|
||||
|
||||
val user = context.user
|
||||
if (action == Action.CREATE) {
|
||||
@@ -38,7 +38,6 @@ class WorkgroupVoter : Voter<ApplicationCall> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (action == Action.VIEW) {
|
||||
if (subject is WorkgroupWithAuthI<*>) {
|
||||
return if (subject.isDeleted()) denied("You cannot view a deleted workgroup", "workgroup.view.deleted")
|
||||
|
||||
@@ -134,7 +134,7 @@ class ArticleVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can update article if yours`(): Unit {
|
||||
fun `can update article if yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleVoter(getRepo(article))
|
||||
.canUpsert(article, tesla)
|
||||
@@ -142,7 +142,7 @@ class ArticleVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can not update article if not yours`(): Unit {
|
||||
fun `can not update article if not yours`() {
|
||||
val article = getArticle(tesla)
|
||||
ArticleVoter(getRepo(article))
|
||||
.canUpsert(article, einstein)
|
||||
|
||||
@@ -125,7 +125,7 @@ internal class CommentVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can be view the comment`(): Unit {
|
||||
fun `can be view the comment`() {
|
||||
listOf(CommentVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { citizenOrNull } returns tesla
|
||||
|
||||
@@ -168,7 +168,7 @@ internal class VoteVoterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can be vote an article`(): Unit {
|
||||
fun `can be vote an article`() {
|
||||
listOf(VoteVoter()).run {
|
||||
mockk<ApplicationCall> {
|
||||
every { citizenOrNull } returns tesla
|
||||
|
||||
Reference in New Issue
Block a user