klint
This commit is contained in:
@@ -6,7 +6,7 @@ import fr.postgresjson.entity.*
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
data class ArticleForView (
|
||||
data class ArticleForView(
|
||||
override val id: UUID = UUID.randomUUID(),
|
||||
override val title: String,
|
||||
val anonymous: Boolean = true,
|
||||
@@ -32,7 +32,7 @@ data class ArticleForView (
|
||||
val lastVersion: Boolean = false
|
||||
}
|
||||
|
||||
interface ArticleForUpdateI<C: CitizenRef> : ArticleI, ArticleWithTitleI, VersionableRef, TargetI, CreatedBy<C> {
|
||||
interface ArticleForUpdateI<C : CitizenRef> : ArticleI, ArticleWithTitleI, VersionableRef, TargetI, CreatedBy<C> {
|
||||
val anonymous: Boolean
|
||||
val content: String
|
||||
val description: String
|
||||
@@ -40,7 +40,7 @@ interface ArticleForUpdateI<C: CitizenRef> : ArticleI, ArticleWithTitleI, Versio
|
||||
val workgroup: WorkgroupRef?
|
||||
}
|
||||
|
||||
class ArticleForUpdate (
|
||||
class ArticleForUpdate(
|
||||
id: UUID? = null,
|
||||
override val title: String,
|
||||
override val anonymous: Boolean = true,
|
||||
|
||||
@@ -6,17 +6,17 @@ import fr.dcproject.entity.VersionableRef
|
||||
import fr.dcproject.voter.Voter
|
||||
import fr.dcproject.voter.VoterResponse
|
||||
|
||||
class ArticleVoter(private val articleRepo: ArticleRepository): Voter() {
|
||||
fun <S: ArticleAuthI<*>> canView(subjects: List<S>, citizen: CitizenI?): VoterResponse =
|
||||
class ArticleVoter(private val articleRepo: ArticleRepository) : Voter() {
|
||||
fun <S : ArticleAuthI<*>> canView(subjects: List<S>, citizen: CitizenI?): VoterResponse =
|
||||
canAll(subjects) { canView(it, citizen) }
|
||||
|
||||
fun <S: ArticleAuthI<*>> canView(subject: S, citizen: CitizenI?): VoterResponse {
|
||||
fun <S : ArticleAuthI<*>> canView(subject: S, citizen: CitizenI?): VoterResponse {
|
||||
return if (subject.isDeleted()) denied("Article is deleted", "article.deleted")
|
||||
else if (subject.draft && (citizen == null || subject.createdBy.id != citizen.id)) denied("Article is draft, but it's not yours", "article.draft.not.yours")
|
||||
else granted()
|
||||
}
|
||||
|
||||
fun <S: CreatedBy<*>> canDelete(subject: S, citizen: CitizenI?): VoterResponse {
|
||||
fun <S : CreatedBy<*>> canDelete(subject: S, citizen: CitizenI?): VoterResponse {
|
||||
if (citizen == null) return denied("You must be connected to create article", "article.create.notConnected")
|
||||
return if (subject.createdBy.id == citizen.id) {
|
||||
granted()
|
||||
@@ -26,9 +26,9 @@ class ArticleVoter(private val articleRepo: ArticleRepository): Voter() {
|
||||
}
|
||||
|
||||
fun <S> canUpsert(subject: S, citizen: CitizenI?): VoterResponse
|
||||
where S: ArticleI,
|
||||
S: CreatedBy<*>,
|
||||
S: VersionableRef {
|
||||
where S : ArticleI,
|
||||
S : CreatedBy<*>,
|
||||
S : VersionableRef {
|
||||
if (citizen == null) return denied("You must be connected to create article", "article.create.notConnected")
|
||||
/* The new Article must by created by the same citizen of the connected citizen */
|
||||
if (subject.createdBy.id == citizen.id) {
|
||||
|
||||
@@ -37,7 +37,7 @@ private fun ArticleRepository.findArticles(request: ArticlesRequest): Paginated<
|
||||
)
|
||||
}
|
||||
|
||||
fun Route.findArticles (repo: ArticleRepository, voter: ArticleVoter) {
|
||||
fun Route.findArticles(repo: ArticleRepository, voter: ArticleVoter) {
|
||||
get<ArticlesRequest> {
|
||||
repo.findArticles(it)
|
||||
.apply { voter.assert { canView(result, citizenOrNull) } }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -5,21 +5,21 @@ import fr.dcproject.voter.VoterResponse
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
|
||||
class CitizenVoter : Voter() {
|
||||
fun <S> canView(subjects: List<S>, connectedCitizen: CitizenI?): VoterResponse where S : CitizenI, S: EntityDeletedAt =
|
||||
fun <S> canView(subjects: List<S>, connectedCitizen: CitizenI?): VoterResponse where S : CitizenI, S : EntityDeletedAt =
|
||||
canAll(subjects) { canView(it, connectedCitizen) }
|
||||
|
||||
fun <S> canView(subject: S, connectedCitizen: CitizenI?): VoterResponse where S : CitizenI, S: EntityDeletedAt {
|
||||
fun <S> canView(subject: S, connectedCitizen: CitizenI?): VoterResponse where S : CitizenI, S : EntityDeletedAt {
|
||||
if (connectedCitizen == null) return denied("You must be connected to view citizen", "citizen.view.connected")
|
||||
return if (subject.isDeleted()) denied("You cannot view a deleted citizen", "citizen.view.deleted")
|
||||
else granted()
|
||||
}
|
||||
|
||||
fun <S: CitizenI> canUpdate(subject: S, connectedCitizen: CitizenI?): VoterResponse {
|
||||
fun <S : CitizenI> canUpdate(subject: S, connectedCitizen: CitizenI?): VoterResponse {
|
||||
if (connectedCitizen == null) return denied("You must be connected to update Citizen", "citizen.update.notConnected")
|
||||
return if (subject.id == connectedCitizen.id) granted() else denied("You can only update your citizen", "citizen.update.notYours")
|
||||
}
|
||||
|
||||
fun <S: CitizenI> canChangePassword(subject: S, connectedCitizen: CitizenI?): VoterResponse {
|
||||
fun <S : CitizenI> canChangePassword(subject: S, connectedCitizen: CitizenI?): VoterResponse {
|
||||
if (connectedCitizen == null) return denied("You must be connected to change your password", "citizen.changePassword.notConnected")
|
||||
return if (subject.id == connectedCitizen.id) granted() else denied("You can only change your password", "citizen.password.notYours")
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class CommentForView<T : TargetI, C : CitizenRef>(
|
||||
)
|
||||
}
|
||||
|
||||
open class CommentForUpdate<T : TargetI, C: CitizenRef>(
|
||||
open class CommentForUpdate<T : TargetI, C : CitizenRef>(
|
||||
override val id: UUID = UUID.randomUUID(),
|
||||
override val createdBy: C,
|
||||
override val target: T,
|
||||
@@ -61,14 +61,14 @@ open class CommentForUpdate<T : TargetI, C: CitizenRef>(
|
||||
)
|
||||
}
|
||||
|
||||
open class CommentParent<T: TargetI>(
|
||||
open class CommentParent<T : TargetI>(
|
||||
override val id: UUID,
|
||||
override val deletedAt: DateTime?,
|
||||
override val target: T
|
||||
) : CommentRef(id),
|
||||
CommentParentI<T>
|
||||
|
||||
interface CommentParentI<T: TargetI> : CommentI, EntityDeletedAt, CommentWithTargetI<T>
|
||||
interface CommentParentI<T : TargetI> : CommentI, EntityDeletedAt, CommentWithTargetI<T>
|
||||
|
||||
interface CommentWithTargetI<T : TargetI> : CommentI, TargetI, AsTarget<T>
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ abstract class CommentRepositoryAbs<T : TargetI>(override var requester: Request
|
||||
}
|
||||
}
|
||||
|
||||
fun <I : T, C: CitizenRef> comment(comment: CommentForUpdate<I, C>) {
|
||||
fun <I : T, C : CitizenRef> comment(comment: CommentForUpdate<I, C>) {
|
||||
requester
|
||||
.getFunction("comment")
|
||||
.sendQuery(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user