#68 Clean Entities
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package fr.dcproject.common.dto
|
||||
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import org.joda.time.DateTime
|
||||
import fr.dcproject.common.entity.CreatedAt as EntityCreatedAt
|
||||
|
||||
interface CreatedAt {
|
||||
val createdAt: DateTime
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package fr.dcproject.common.dto
|
||||
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import fr.dcproject.common.entity.Versionable as VersionableEntity
|
||||
import java.util.UUID
|
||||
|
||||
interface Versionable {
|
||||
val versionId: UUID
|
||||
val versionNumber: Int
|
||||
|
||||
class Imp(parent: EntityVersioning<UUID, Int>) : Versionable {
|
||||
class Imp(parent: VersionableEntity) : Versionable {
|
||||
override val versionNumber: Int = parent.versionNumber
|
||||
override val versionId: UUID = parent.versionId
|
||||
}
|
||||
|
||||
28
src/main/kotlin/fr/dcproject/common/entity/Action.kt
Normal file
28
src/main/kotlin/fr/dcproject/common/entity/Action.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
|
||||
interface Created<C : CitizenI> : CreatedAt, CreatedBy<C> {
|
||||
class Imp<C : CitizenI>(createdBy: C) :
|
||||
Created<C>,
|
||||
CreatedBy<C> by CreatedBy.Imp(createdBy),
|
||||
CreatedAt by CreatedAt.Imp()
|
||||
}
|
||||
|
||||
interface Updated<C : CitizenI> : UpdatedAt, UpdatedBy<C> {
|
||||
class Imp<C : CitizenI>(updatedAt: C) :
|
||||
Updated<C>,
|
||||
UpdatedBy<C> by UpdatedBy.Imp(updatedAt),
|
||||
UpdatedAt by UpdatedAt.Imp()
|
||||
}
|
||||
|
||||
interface Deleted<C : CitizenI> : DeletedAt, DeletedBy<C> {
|
||||
override fun isDeleted(): Boolean = (this as DeletedAt).isDeleted()
|
||||
|
||||
class Imp<C : CitizenI>(deletedAt: C) :
|
||||
Deleted<C>,
|
||||
DeletedBy<C> by DeletedBy.Imp(deletedAt),
|
||||
DeletedAt by DeletedAt.Imp() {
|
||||
override fun isDeleted(): Boolean = (this as Deleted<C>).isDeleted()
|
||||
}
|
||||
}
|
||||
25
src/main/kotlin/fr/dcproject/common/entity/ActionBy.kt
Normal file
25
src/main/kotlin/fr/dcproject/common/entity/ActionBy.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
|
||||
interface CreatedBy<T : CitizenI> {
|
||||
val createdBy: T
|
||||
|
||||
class Imp<T : CitizenI>(override val createdBy: T) : CreatedBy<T>
|
||||
}
|
||||
|
||||
interface UpdatedBy<T : CitizenI> {
|
||||
val updatedBy: T
|
||||
|
||||
class Imp<T : CitizenI>(override val updatedBy: T) : UpdatedBy<T>
|
||||
}
|
||||
|
||||
interface DeletedBy<T : CitizenI> {
|
||||
val deletedBy: T?
|
||||
|
||||
fun isDeleted(): Boolean {
|
||||
return deletedBy?.let { true } ?: false
|
||||
}
|
||||
|
||||
class Imp<T : CitizenI>(override val deletedBy: T?) : DeletedBy<T>
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
/**
|
||||
* TODO remove EntityCreatedBy<EntityI>
|
||||
*/
|
||||
interface CreatedBy<T : CitizenI> : EntityCreatedBy<EntityI> {
|
||||
override val createdBy: T
|
||||
}
|
||||
|
||||
class CreatedByImp<T : CitizenI>(override val createdBy: T) : CreatedBy<T>
|
||||
30
src/main/kotlin/fr/dcproject/common/entity/Date.kt
Normal file
30
src/main/kotlin/fr/dcproject/common/entity/Date.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
/* Interface */
|
||||
interface CreatedAt {
|
||||
val createdAt: DateTime
|
||||
class Imp(
|
||||
override val createdAt: DateTime = DateTime.now()
|
||||
) : CreatedAt
|
||||
}
|
||||
interface UpdatedAt {
|
||||
val updatedAt: DateTime
|
||||
class Imp(
|
||||
override val updatedAt: DateTime = DateTime.now()
|
||||
) : UpdatedAt
|
||||
}
|
||||
|
||||
interface DeletedAt {
|
||||
val deletedAt: DateTime?
|
||||
fun isDeleted(): Boolean {
|
||||
return deletedAt?.let {
|
||||
it < DateTime.now()
|
||||
} ?: false
|
||||
}
|
||||
|
||||
class Imp(
|
||||
override val deletedAt: DateTime? = null
|
||||
) : DeletedAt
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
interface EntityI : EntityI {
|
||||
val id: UUID
|
||||
interface EntityI : UuidEntityI {
|
||||
override val id: UUID
|
||||
}
|
||||
|
||||
open class Entity(id: UUID? = null) : EntityI {
|
||||
override val id: UUID = id ?: UUID.randomUUID()
|
||||
}
|
||||
|
||||
@@ -5,25 +5,21 @@ import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.comment.generic.CommentRef
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.dcproject.component.opinion.entity.OpinionRef
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
interface ExtraI<T : TargetI, C : CitizenI> :
|
||||
UuidEntityI,
|
||||
EntityI,
|
||||
HasTarget<T>,
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<C>
|
||||
CreatedAt,
|
||||
CreatedBy<C>
|
||||
|
||||
interface HasTarget<T : TargetI> {
|
||||
val target: T
|
||||
}
|
||||
|
||||
open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, UuidEntity(id) {
|
||||
open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, Entity(id) {
|
||||
|
||||
final override val reference: String
|
||||
get() = if (field != "") field else TargetI.getReference(this)
|
||||
@@ -33,7 +29,7 @@ open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, UuidEn
|
||||
}
|
||||
}
|
||||
|
||||
interface TargetI : UuidEntityI {
|
||||
interface TargetI : EntityI {
|
||||
enum class TargetName(val targetReference: String) {
|
||||
Article("article"),
|
||||
Constitution("constitution"),
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import java.util.UUID
|
||||
|
||||
interface VersionableRef {
|
||||
interface VersionableId {
|
||||
val versionId: UUID
|
||||
|
||||
class Imp(
|
||||
versionId: UUID? = null,
|
||||
) : VersionableId {
|
||||
override val versionId: UUID = versionId ?: UUID.randomUUID()
|
||||
}
|
||||
}
|
||||
|
||||
class VersionableRefImp(
|
||||
interface Versionable : VersionableId {
|
||||
override val versionId: UUID
|
||||
) : VersionableRef
|
||||
val versionNumber: Int
|
||||
|
||||
interface Versionable : VersionableRef, EntityVersioning<UUID, Int> {
|
||||
override val versionId: UUID
|
||||
override val versionNumber: Int
|
||||
class Imp(
|
||||
override val versionNumber: Int,
|
||||
versionId: UUID? = null,
|
||||
) : Versionable {
|
||||
override val versionId: UUID = versionId ?: UUID.randomUUID()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.common.entity.VersionableRef
|
||||
import fr.dcproject.common.entity.Versionable
|
||||
import fr.dcproject.common.entity.VersionableId
|
||||
import fr.dcproject.component.citizen.CitizenCart
|
||||
import fr.dcproject.component.citizen.CitizenCartI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
@@ -16,12 +20,6 @@ import fr.dcproject.component.workgroup.WorkgroupCart
|
||||
import fr.dcproject.component.workgroup.WorkgroupCartI
|
||||
import fr.dcproject.component.workgroup.WorkgroupRef
|
||||
import fr.dcproject.component.workgroup.WorkgroupSimple
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
@@ -42,16 +40,16 @@ data class ArticleForView(
|
||||
) : ArticleRef(id),
|
||||
ArticleAuthI<CitizenRef>,
|
||||
ArticleWithTitleI,
|
||||
EntityVersioning<UUID, Int>,
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp(deletedAt),
|
||||
VersionableRef,
|
||||
Versionable,
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
DeletedAt by DeletedAt.Imp(deletedAt),
|
||||
VersionableId,
|
||||
Opinionable,
|
||||
Votable by VotableImp() {
|
||||
val lastVersion: Boolean = false
|
||||
}
|
||||
|
||||
interface ArticleForUpdateI<C : CitizenRef> : ArticleI, ArticleWithTitleI, VersionableRef, TargetI, CreatedBy<C> {
|
||||
interface ArticleForUpdateI<C : CitizenRef> : ArticleI, ArticleWithTitleI, VersionableId, TargetI, CreatedBy<C> {
|
||||
val anonymous: Boolean
|
||||
val content: String
|
||||
val description: String
|
||||
@@ -74,7 +72,7 @@ class ArticleForUpdate(
|
||||
) : ArticleRef(id),
|
||||
ArticleForUpdateI<CitizenRef>,
|
||||
ArticleAuthI<CitizenRef>,
|
||||
VersionableRef {
|
||||
VersionableId {
|
||||
val tags: List<String> = tags.distinct()
|
||||
}
|
||||
|
||||
@@ -99,7 +97,7 @@ open class ArticleRef(
|
||||
id: UUID? = null
|
||||
) : ArticleI, TargetRef(id)
|
||||
|
||||
interface ArticleI : UuidEntityI, TargetI
|
||||
interface ArticleI : EntityI, TargetI
|
||||
|
||||
interface ArticleWithTitleI : ArticleI {
|
||||
val title: String
|
||||
@@ -108,6 +106,6 @@ interface ArticleWithTitleI : ArticleI {
|
||||
interface ArticleAuthI<U : CitizenI> :
|
||||
ArticleI,
|
||||
CreatedBy<U>,
|
||||
EntityDeletedAt {
|
||||
DeletedAt {
|
||||
val draft: Boolean
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.VersionableRef
|
||||
import fr.dcproject.common.entity.VersionableId
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
@@ -28,7 +28,7 @@ class ArticleAccessControl(private val articleRepo: ArticleRepository) : AccessC
|
||||
fun <S> canUpsert(subject: S, citizen: CitizenI?): AccessResponse
|
||||
where S : ArticleI,
|
||||
S : CreatedBy<*>,
|
||||
S : VersionableRef {
|
||||
S : VersionableId {
|
||||
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) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import fr.dcproject.common.entity.VersionableRef
|
||||
import fr.dcproject.common.entity.VersionableId
|
||||
import fr.dcproject.common.utils.contentToString
|
||||
import fr.dcproject.common.utils.getJsonField
|
||||
import fr.dcproject.common.utils.toIso
|
||||
@@ -16,7 +16,7 @@ import java.util.UUID
|
||||
/**
|
||||
* Wrapper for manage views with elasticsearch
|
||||
*/
|
||||
class ArticleViewManager <A> (private val restClient: RestClient) : ViewManager<A> where A : VersionableRef, A : ArticleI {
|
||||
class ArticleViewManager <A> (private val restClient: RestClient) : ViewManager<A> where A : VersionableId, A : ArticleI {
|
||||
/**
|
||||
* Add view on article to elasticsearch
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package fr.dcproject.component.auth
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
import fr.dcproject.component.auth.UserI.Roles
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import io.ktor.auth.Principal
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
@@ -26,8 +24,8 @@ open class User(
|
||||
var blockedAt: DateTime? = null,
|
||||
var roles: List<Roles> = emptyList()
|
||||
) : UserRef(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
UpdatedAt by UpdatedAt.Imp()
|
||||
|
||||
interface UserWithPasswordI {
|
||||
val id: UUID
|
||||
@@ -42,9 +40,9 @@ class UserWithPassword(
|
||||
|
||||
open class UserRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : UserI, UuidEntity(id)
|
||||
) : UserI, Entity(id)
|
||||
|
||||
interface UserI : UuidEntityI, Principal {
|
||||
interface UserI : EntityI, Principal {
|
||||
enum class Roles { ROLE_USER, ROLE_ADMIN }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package fr.dcproject.component.citizen
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.component.auth.User
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.auth.UserI
|
||||
import fr.dcproject.component.auth.UserRef
|
||||
import fr.dcproject.component.citizen.CitizenI.Name
|
||||
import fr.dcproject.component.workgroup.WorkgroupSimple
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.Serializable
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
@@ -26,7 +24,7 @@ class CitizenForCreate(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
) : CitizenI,
|
||||
CitizenRefWithUser(id, user),
|
||||
EntityCreatedAt by EntityCreatedAtImp()
|
||||
CreatedAt by CreatedAt.Imp()
|
||||
|
||||
class Citizen(
|
||||
override val id: UUID = UUID.randomUUID(),
|
||||
@@ -42,8 +40,8 @@ class Citizen(
|
||||
CitizenWithUserI,
|
||||
CitizenRef(id),
|
||||
CitizenCartI,
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp(deletedAt) {
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
DeletedAt by DeletedAt.Imp(deletedAt) {
|
||||
var workgroups: List<WorkgroupAndRoles> = emptyList()
|
||||
|
||||
class WorkgroupAndRoles(
|
||||
@@ -64,7 +62,7 @@ data class CitizenBasic(
|
||||
override val deletedAt: DateTime? = null
|
||||
) : CitizenBasicI,
|
||||
CitizenRefWithUser(id, user),
|
||||
EntityDeletedAt by EntityDeletedAtImp(deletedAt)
|
||||
DeletedAt by DeletedAt.Imp(deletedAt)
|
||||
|
||||
@Deprecated("")
|
||||
open class CitizenSimple(
|
||||
@@ -92,10 +90,10 @@ open class CitizenRefWithUser(
|
||||
|
||||
open class CitizenRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : UuidEntity(id),
|
||||
) : Entity(id),
|
||||
CitizenI
|
||||
|
||||
interface CitizenI : UuidEntityI {
|
||||
interface CitizenI : EntityI {
|
||||
data class Name(
|
||||
override val firstName: String,
|
||||
override val lastName: String,
|
||||
@@ -111,7 +109,7 @@ interface CitizenI : UuidEntityI {
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
interface CitizenBasicI : CitizenWithUserI, CitizenWithEmail, EntityDeletedAt {
|
||||
interface CitizenBasicI : CitizenWithUserI, CitizenWithEmail, DeletedAt {
|
||||
val name: Name
|
||||
val birthday: DateTime
|
||||
val voteAnonymous: Boolean
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fr.dcproject.component.citizen
|
||||
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
|
||||
class CitizenAccessControl : AccessControl() {
|
||||
fun <S> canView(subjects: List<S>, connectedCitizen: CitizenI?): AccessResponse where S : CitizenI, S : EntityDeletedAt =
|
||||
fun <S> canView(subjects: List<S>, connectedCitizen: CitizenI?): AccessResponse where S : CitizenI, S : DeletedAt =
|
||||
canAll(subjects) { canView(it, connectedCitizen) }
|
||||
|
||||
fun <S> canView(subject: S, connectedCitizen: CitizenI?): AccessResponse where S : CitizenI, S : EntityDeletedAt {
|
||||
fun <S> canView(subject: S, connectedCitizen: CitizenI?): AccessResponse where S : CitizenI, S : DeletedAt {
|
||||
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()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.comment.article
|
||||
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
@@ -9,7 +10,6 @@ import fr.dcproject.component.comment.generic.CommentForView
|
||||
import fr.dcproject.component.comment.generic.CommentRepositoryAbs
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
class CommentArticleRepository(requester: Requester) : CommentRepositoryAbs<ArticleForView>(requester) {
|
||||
@@ -36,7 +36,7 @@ class CommentArticleRepository(requester: Requester) : CommentRepositoryAbs<Arti
|
||||
}
|
||||
|
||||
override fun findByTarget(
|
||||
target: UuidEntityI,
|
||||
target: EntityI,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
sort: Sort
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.comment.constitution
|
||||
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
@@ -9,7 +10,6 @@ import fr.dcproject.component.comment.generic.CommentRepositoryAbs
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
class CommentConstitutionRepository(requester: Requester) : CommentRepositoryAbs<ConstitutionRef>(requester) {
|
||||
@@ -36,7 +36,7 @@ class CommentConstitutionRepository(requester: Requester) : CommentRepositoryAbs
|
||||
}
|
||||
|
||||
override fun findByTarget(
|
||||
target: UuidEntityI,
|
||||
target: EntityI,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
sort: CommentArticleRepository.Sort
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package fr.dcproject.component.comment.generic
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.ExtraI
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.vote.entity.Votable
|
||||
import fr.dcproject.component.vote.entity.VotableImp
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
@@ -31,9 +27,9 @@ class CommentForView<T : TargetI, C : CitizenRef>(
|
||||
CommentWithParentI<T>,
|
||||
CommentForUpdate<T, C>(id, createdBy, target, content, parent, deletedAt),
|
||||
CommentWithTargetI<T>,
|
||||
EntityCreatedBy<C> by EntityCreatedByImp(createdBy),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp(),
|
||||
CreatedBy<C> by CreatedBy.Imp(createdBy),
|
||||
UpdatedAt by UpdatedAt.Imp(),
|
||||
DeletedAt by DeletedAt.Imp(),
|
||||
Votable by VotableImp(),
|
||||
TargetI {
|
||||
constructor(
|
||||
@@ -59,9 +55,9 @@ open class CommentForUpdate<T : TargetI, C : CitizenRef>(
|
||||
CommentWithParentI<T>,
|
||||
ExtraI<T, C>,
|
||||
CommentWithTargetI<T>,
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<C>,
|
||||
EntityDeletedAt,
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
CreatedBy<C>,
|
||||
DeletedAt,
|
||||
TargetI {
|
||||
constructor(
|
||||
createdBy: C,
|
||||
@@ -82,7 +78,7 @@ open class CommentParent<T : TargetI>(
|
||||
) : CommentRef(id),
|
||||
CommentParentI<T>
|
||||
|
||||
interface CommentParentI<T : TargetI> : CommentI, EntityDeletedAt, CommentWithTargetI<T>
|
||||
interface CommentParentI<T : TargetI> : CommentI, DeletedAt, CommentWithTargetI<T>
|
||||
|
||||
interface CommentWithTargetI<T : TargetI> : CommentI, TargetI, HasTarget<T>
|
||||
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
package fr.dcproject.component.comment.generic
|
||||
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
|
||||
class CommentAccessControl : AccessControl() {
|
||||
fun <S> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse
|
||||
where S : CommentI,
|
||||
S : EntityDeletedAt = canAll(subjects) { canView(it, citizen) }
|
||||
S : DeletedAt = canAll(subjects) { canView(it, citizen) }
|
||||
|
||||
fun <S> canView(subject: S, citizen: CitizenI?): AccessResponse
|
||||
where S : CommentI,
|
||||
S : EntityDeletedAt = when {
|
||||
S : DeletedAt = when {
|
||||
subject.isDeleted() -> denied("Your cannot view a deleted comment", "comment.view.deleted")
|
||||
else -> granted()
|
||||
}
|
||||
|
||||
fun <S, CR : CitizenI> canCreate(subject: S, citizen: CitizenI?): AccessResponse
|
||||
where S : CommentI,
|
||||
S : EntityCreatedBy<CR>,
|
||||
S : CreatedBy<CR>,
|
||||
S : CommentWithParentI<*>,
|
||||
S : HasTarget<*> = when {
|
||||
citizen == null -> denied("You must be connected to create user", "comment.create.notConnected")
|
||||
subject.createdBy.id != citizen.id -> denied("You cannot create a comment with other user than yours", "comment.create.wrongUser")
|
||||
subject.parent?.isDeleted() ?: false -> denied("You cannot create a comment on deleted parent", "comment.create.deletedParent")
|
||||
subject.target.let { it is EntityDeletedAt && it.isDeleted() } -> denied("You cannot create a comment on deleted target", "comment.create.deletedTarget")
|
||||
subject.target.let { it is DeletedAt && it.isDeleted() } -> denied("You cannot create a comment on deleted target", "comment.create.deletedTarget")
|
||||
else -> granted()
|
||||
}
|
||||
|
||||
fun <S, CR : CitizenI> canUpdate(subject: S, citizen: CitizenI?): AccessResponse
|
||||
where S : CommentI,
|
||||
S : EntityCreatedBy<CR> = when {
|
||||
S : CreatedBy<CR> = when {
|
||||
citizen == null -> denied("You must be connected to update comment", "comment.update.notConnected")
|
||||
citizen.id != subject.createdBy.id -> denied("You cannot update another user of yours", "comment.update.notYours")
|
||||
else -> granted()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.comment.generic
|
||||
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
@@ -7,7 +8,6 @@ import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.comment.article.CommentArticleRepository
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import java.util.UUID
|
||||
|
||||
@@ -44,7 +44,7 @@ abstract class CommentRepositoryAbs<T : TargetI>(override var requester: Request
|
||||
}
|
||||
|
||||
open fun findByTarget(
|
||||
target: UuidEntityI,
|
||||
target: EntityI,
|
||||
page: Int = 1,
|
||||
limit: Int = 50,
|
||||
sort: CommentArticleRepository.Sort = CommentArticleRepository.Sort.CREATED_AT
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package fr.dcproject.component.constitution
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.common.entity.VersionableId
|
||||
import fr.dcproject.component.article.ArticleForListing
|
||||
import fr.dcproject.component.article.ArticleI
|
||||
import fr.dcproject.component.citizen.CitizenSimple
|
||||
import fr.dcproject.component.citizen.CitizenWithUserI
|
||||
import fr.dcproject.component.constitution.ConstitutionSimple.TitleSimple
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityVersioning
|
||||
import java.util.UUID
|
||||
|
||||
class Constitution(
|
||||
@@ -54,10 +50,10 @@ open class ConstitutionSimple<Cr : CitizenWithUserI, T : TitleSimple<*>>(
|
||||
override val createdBy: Cr,
|
||||
versionId: UUID = UUID.randomUUID()
|
||||
) : ConstitutionRef(id),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(versionId = versionId, versionNumber = 0),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Cr> by EntityCreatedByImp(createdBy),
|
||||
EntityDeletedAt by EntityDeletedAtImp() {
|
||||
VersionableId by VersionableId.Imp(versionId),
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
CreatedBy<Cr> by CreatedBy.Imp(createdBy),
|
||||
DeletedAt by DeletedAt.Imp() {
|
||||
|
||||
init {
|
||||
titles.forEachIndexed { index, title ->
|
||||
@@ -76,7 +72,7 @@ open class ConstitutionSimple<Cr : CitizenWithUserI, T : TitleSimple<*>>(
|
||||
open class ConstitutionRef(id: UUID? = null) : ConstitutionS(id ?: UUID.randomUUID()) {
|
||||
open class TitleRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : UuidEntity(id)
|
||||
) : Entity(id)
|
||||
}
|
||||
|
||||
sealed class ConstitutionS(id: UUID = UUID.randomUUID()) : TargetRef(id), TargetI
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package fr.dcproject.component.constitution
|
||||
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
|
||||
class ConstitutionAccessControl : AccessControl() {
|
||||
fun canCreate(subject: ConstitutionS, citizen: CitizenI?): AccessResponse = when {
|
||||
@@ -15,18 +15,18 @@ class ConstitutionAccessControl : AccessControl() {
|
||||
fun <S : ConstitutionSimple<*, *>> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse =
|
||||
canAll(subjects) { canView(it, citizen) }
|
||||
|
||||
fun <S> canView(subject: S, citizen: CitizenI?): AccessResponse where S : EntityDeletedAt, S : ConstitutionS = when {
|
||||
fun <S> canView(subject: S, citizen: CitizenI?): AccessResponse where S : DeletedAt, S : ConstitutionS = when {
|
||||
subject.isDeleted() -> denied("You cannot view a deleted constitution", "constitution.view.deleted")
|
||||
else -> granted()
|
||||
}
|
||||
|
||||
fun <S> canDelete(subject: S, citizen: CitizenI?): AccessResponse where S : EntityCreatedBy<CitizenI>, S : ConstitutionRef = when {
|
||||
fun <S> canDelete(subject: S, citizen: CitizenI?): AccessResponse where S : CreatedBy<CitizenI>, S : ConstitutionRef = when {
|
||||
citizen == null -> denied("You must be connected to delete constitution", "constitution.delete.notConnected")
|
||||
subject.createdBy.id != citizen.id -> denied("You cannot delete the constitution of other citizen", "constitution.delete.otherCitizen")
|
||||
else -> granted()
|
||||
}
|
||||
|
||||
fun <S> canUpdate(subject: S, citizen: CitizenI?): AccessResponse where S : EntityCreatedBy<CitizenI>, S : ConstitutionRef = when {
|
||||
fun <S> canUpdate(subject: S, citizen: CitizenI?): AccessResponse where S : CreatedBy<CitizenI>, S : ConstitutionRef = when {
|
||||
citizen == null -> denied("You must be connected to update constitution", "constitution.update.notConnected")
|
||||
subject.createdBy.id != citizen.id -> denied("You cannot update the constitution of other citizen", "constitution.update.otherCitizen")
|
||||
else -> granted()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.constitution.routes
|
||||
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.common.utils.receiveOrBadRequest
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
@@ -13,7 +14,6 @@ import fr.dcproject.component.constitution.ConstitutionSimple
|
||||
import fr.dcproject.component.constitution.ConstitutionSimple.TitleSimple
|
||||
import fr.dcproject.component.constitution.routes.CreateConstitution.PostConstitutionRequest.Input
|
||||
import fr.dcproject.component.constitution.routes.CreateConstitution.PostConstitutionRequest.Input.Title
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import io.ktor.application.call
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
@@ -45,7 +45,7 @@ object CreateConstitution {
|
||||
var name: String,
|
||||
var rank: Int? = null,
|
||||
var articles: MutableList<ArticleRef> = mutableListOf()
|
||||
) : UuidEntity(id)
|
||||
) : Entity(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package fr.dcproject.component.follow
|
||||
|
||||
import fr.dcproject.common.entity.Created
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.ExtraI
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.component.citizen.CitizenBasic
|
||||
import fr.dcproject.component.citizen.CitizenBasicI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
@Deprecated("")
|
||||
@@ -28,8 +26,7 @@ open class FollowSimple<T : TargetI, C : CitizenI>(
|
||||
override var target: T
|
||||
) : ExtraI<T, C>,
|
||||
FollowRef(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<C> by EntityCreatedByImp(createdBy)
|
||||
Created<C> by Created.Imp(createdBy)
|
||||
|
||||
class FollowForUpdate<T : TargetI, C : CitizenI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
@@ -37,10 +34,10 @@ class FollowForUpdate<T : TargetI, C : CitizenI>(
|
||||
override val createdBy: C
|
||||
) : FollowRef(id),
|
||||
HasTarget<T>,
|
||||
EntityCreatedBy<C> by EntityCreatedByImp<C>(createdBy)
|
||||
CreatedBy<C> by CreatedBy.Imp<C>(createdBy)
|
||||
|
||||
open class FollowRef(
|
||||
override val id: UUID
|
||||
) : FollowI
|
||||
|
||||
interface FollowI : UuidEntityI
|
||||
interface FollowI : EntityI
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.follow
|
||||
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
@@ -8,7 +9,6 @@ import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@@ -71,7 +71,7 @@ sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requ
|
||||
)
|
||||
|
||||
fun findFollowsByTarget(
|
||||
target: UuidEntity,
|
||||
target: Entity,
|
||||
bulkSize: Int = 300
|
||||
): Flow<FollowSimple<IN, CitizenRef>> = flow {
|
||||
var nextPage = 1
|
||||
@@ -85,7 +85,7 @@ sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requ
|
||||
}
|
||||
|
||||
abstract fun findFollowsByTarget(
|
||||
target: UuidEntity,
|
||||
target: Entity,
|
||||
page: Int = 1,
|
||||
limit: Int = 300
|
||||
): Paginated<FollowSimple<IN, CitizenRef>>
|
||||
@@ -108,7 +108,7 @@ class FollowArticleRepository(requester: Requester) : FollowRepository<ArticleRe
|
||||
}
|
||||
|
||||
override fun findFollowsByTarget(
|
||||
target: UuidEntity,
|
||||
target: Entity,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowSimple<ArticleRef, CitizenRef>> {
|
||||
@@ -139,7 +139,7 @@ class FollowConstitutionRepository(requester: Requester) : FollowRepository<Cons
|
||||
}
|
||||
|
||||
override fun findFollowsByTarget(
|
||||
target: UuidEntity,
|
||||
target: Entity,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowSimple<ConstitutionRef, CitizenRef>> {
|
||||
|
||||
@@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import com.fasterxml.jackson.datatype.joda.JodaModule
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import org.joda.time.DateTime
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
@@ -47,7 +47,7 @@ open class Notification(
|
||||
}
|
||||
|
||||
open class EntityNotification(
|
||||
val target: UuidEntity,
|
||||
val target: Entity,
|
||||
type: String,
|
||||
val action: String
|
||||
) : Notification(type)
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.sendgrid.helpers.mail.Mail
|
||||
import com.sendgrid.helpers.mail.objects.Content
|
||||
import com.sendgrid.helpers.mail.objects.Email
|
||||
import fr.dcproject.common.email.Mailer
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.article.ArticleRepository
|
||||
import fr.dcproject.component.article.ArticleWithTitleI
|
||||
@@ -11,7 +12,6 @@ import fr.dcproject.component.citizen.CitizenBasicI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.citizen.CitizenRepository
|
||||
import fr.dcproject.component.follow.FollowSimple
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
class NotificationEmailSender(
|
||||
@@ -43,7 +43,7 @@ class NotificationEmailSender(
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateHtmlContent(citizen: CitizenBasicI, target: UuidEntityI): String? {
|
||||
private fun generateHtmlContent(citizen: CitizenBasicI, target: EntityI): String? {
|
||||
return when (target) {
|
||||
is ArticleWithTitleI -> """
|
||||
Hello ${citizen.name.getFullName()},<br/>
|
||||
@@ -53,7 +53,7 @@ class NotificationEmailSender(
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateContent(citizen: CitizenBasicI, target: UuidEntityI): String {
|
||||
private fun generateContent(citizen: CitizenBasicI, target: EntityI): String {
|
||||
return when (target) {
|
||||
is ArticleWithTitleI -> """
|
||||
Hello ${citizen.name.getFullName()},
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package fr.dcproject.component.opinion
|
||||
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.opinion.entity.OpinionI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
|
||||
class OpinionAccessControl : AccessControl() {
|
||||
|
||||
@@ -17,21 +17,21 @@ class OpinionAccessControl : AccessControl() {
|
||||
val target = subject.target
|
||||
return when {
|
||||
citizen == null -> denied("You must be connected to make an opinion", "opinion.create.notConnected")
|
||||
target is EntityDeletedAt && target.isDeleted() -> denied("You cannot make opinion on deleted target", "opinion.create.deletedTarget")
|
||||
target is DeletedAt && target.isDeleted() -> denied("You cannot make opinion on deleted target", "opinion.create.deletedTarget")
|
||||
else -> granted()
|
||||
}
|
||||
}
|
||||
|
||||
fun <S, SS : List<S>, C : CitizenI> canView(subjects: SS, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> =
|
||||
fun <S, SS : List<S>, C : CitizenI> canView(subjects: SS, citizen: CitizenI?): AccessResponse where S : OpinionI, S : CreatedBy<C> =
|
||||
canAll(subjects) { canView(it, citizen) }
|
||||
|
||||
fun <S, C : CitizenI> canView(subject: S, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> = when {
|
||||
fun <S, C : CitizenI> canView(subject: S, citizen: CitizenI?): AccessResponse where S : OpinionI, S : CreatedBy<C> = when {
|
||||
citizen == null -> denied("You must be connected to delete opinion", "opinion.delete.notConnected")
|
||||
subject.createdBy.id != citizen.id -> denied("You cannot view opinions of other citizen", "opinion.view.otherCitizen")
|
||||
else -> granted()
|
||||
}
|
||||
|
||||
fun <S, C : CitizenI> canDelete(subject: S, citizen: CitizenI?): AccessResponse where S : EntityCreatedBy<C>, S : OpinionI = when {
|
||||
fun <S, C : CitizenI> canDelete(subject: S, citizen: CitizenI?): AccessResponse where S : CreatedBy<C>, S : OpinionI = when {
|
||||
citizen == null -> denied("You must be connected to delete opinion", "opinion.delete.notConnected")
|
||||
subject.createdBy.id != citizen.id -> denied("You can only delete your opinions", "opinion.delete.notYours")
|
||||
else -> granted()
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package fr.dcproject.component.opinion.entity
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.ExtraI
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
@@ -9,11 +12,6 @@ import fr.dcproject.component.citizen.CitizenBasic
|
||||
import fr.dcproject.component.citizen.CitizenBasicI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
@Deprecated("")
|
||||
@@ -24,8 +22,8 @@ open class Opinion<T : TargetI>(
|
||||
val choice: OpinionChoice
|
||||
) : OpinionRef(id),
|
||||
ExtraI<T, CitizenBasicI>,
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy) {
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
CreatedBy<CitizenBasicI> by CreatedBy.Imp(createdBy) {
|
||||
|
||||
fun getName(): String = choice.name
|
||||
}
|
||||
@@ -45,10 +43,10 @@ data class OpinionForUpdate<T : TargetI>(
|
||||
override val createdBy: CitizenRef
|
||||
) : OpinionRef(id),
|
||||
HasTarget<T>,
|
||||
EntityCreatedBy<CitizenI> by EntityCreatedByImp(createdBy)
|
||||
CreatedBy<CitizenI> by CreatedBy.Imp(createdBy)
|
||||
|
||||
open class OpinionRef(
|
||||
override val id: UUID
|
||||
) : OpinionI, TargetRef(id)
|
||||
|
||||
interface OpinionI : UuidEntityI
|
||||
interface OpinionI : EntityI
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package fr.dcproject.component.opinion.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import java.util.UUID
|
||||
|
||||
class OpinionChoice(
|
||||
@@ -13,12 +11,12 @@ class OpinionChoice(
|
||||
val name: String,
|
||||
val target: List<String>?
|
||||
) : OpinionChoiceRef(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp()
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
DeletedAt by DeletedAt.Imp()
|
||||
|
||||
open class OpinionChoiceRef(
|
||||
id: UUID?
|
||||
) : OpinionChoiceI,
|
||||
UuidEntity(id ?: UUID.randomUUID())
|
||||
Entity(id ?: UUID.randomUUID())
|
||||
|
||||
interface OpinionChoiceI : UuidEntityI
|
||||
interface OpinionChoiceI : EntityI
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.dcproject.component.views.entity
|
||||
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
|
||||
class ViewAggregation(
|
||||
val total: Int,
|
||||
val unique: Int
|
||||
) : EntityI,
|
||||
EntityUpdatedAt by EntityUpdatedAtImp() {
|
||||
UpdatedAt by UpdatedAt.Imp() {
|
||||
constructor() : this(0, 0)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package fr.dcproject.component.vote
|
||||
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.vote.entity.VoteForUpdateI
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.dcproject.component.vote.entity.Vote as VoteEntity
|
||||
|
||||
class VoteAccessControl : AccessControl() {
|
||||
fun <S> canCreate(subject: VoteForUpdateI<S, *>, citizen: CitizenI?): AccessResponse where S : EntityDeletedAt, S : TargetI = when {
|
||||
fun <S> canCreate(subject: VoteForUpdateI<S, *>, citizen: CitizenI?): AccessResponse where S : DeletedAt, S : TargetI = when {
|
||||
citizen == null -> denied("You must be connected for vote", "vote.create.connected")
|
||||
subject.target.isDeleted() -> denied("You cannot vote on deleted target", "vote.create.isDeleted")
|
||||
else -> granted()
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package fr.dcproject.component.vote.entity
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.ExtraI
|
||||
import fr.dcproject.common.entity.HasTarget
|
||||
import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
import fr.dcproject.component.citizen.CitizenBasic
|
||||
import fr.dcproject.component.citizen.CitizenBasicI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
@Deprecated("")
|
||||
@@ -24,9 +21,9 @@ class Vote<T : TargetI>(
|
||||
var anonymous: Boolean = true
|
||||
) : ExtraI<T, CitizenBasicI>,
|
||||
VoteRef(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp() {
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
CreatedBy<CitizenBasicI> by CreatedBy.Imp(createdBy),
|
||||
UpdatedAt by UpdatedAt.Imp() {
|
||||
init {
|
||||
if (note > 1 && note < -1) {
|
||||
error("note must be 1, 0 or -1")
|
||||
@@ -41,9 +38,9 @@ class VoteForUpdate<T : TargetI, C : CitizenI>(
|
||||
override val createdBy: C
|
||||
) : VoteRef(id),
|
||||
VoteForUpdateI<T, C>,
|
||||
EntityCreatedBy<C> by EntityCreatedByImp<C>(createdBy)
|
||||
CreatedBy<C> by CreatedBy.Imp<C>(createdBy)
|
||||
|
||||
interface VoteForUpdateI<T : TargetI, C : CitizenI> : VoteI, HasTarget<T>, EntityCreatedBy<C> {
|
||||
interface VoteForUpdateI<T : TargetI, C : CitizenI> : VoteI, HasTarget<T>, CreatedBy<C> {
|
||||
override val id: UUID
|
||||
val note: Int
|
||||
override val target: T
|
||||
@@ -54,4 +51,4 @@ open class VoteRef(
|
||||
override val id: UUID
|
||||
) : VoteI
|
||||
|
||||
interface VoteI : UuidEntityI
|
||||
interface VoteI : EntityI
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package fr.dcproject.component.vote.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
|
||||
class VoteAggregation(
|
||||
val up: Int,
|
||||
@@ -10,7 +8,7 @@ class VoteAggregation(
|
||||
val down: Int,
|
||||
val total: Int,
|
||||
val score: Int
|
||||
) : EntityI,
|
||||
EntityUpdatedAt by EntityUpdatedAtImp() {
|
||||
) : fr.postgresjson.entity.EntityI,
|
||||
UpdatedAt by UpdatedAt.Imp() {
|
||||
constructor() : this(0, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
package fr.dcproject.component.workgroup
|
||||
|
||||
import fr.dcproject.common.entity.CreatedAt
|
||||
import fr.dcproject.common.entity.CreatedBy
|
||||
import fr.dcproject.common.entity.DeletedAt
|
||||
import fr.dcproject.common.entity.Entity
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.dcproject.common.entity.UpdatedAt
|
||||
import fr.dcproject.component.auth.UserI
|
||||
import fr.dcproject.component.citizen.CitizenBasicI
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenWithUserI
|
||||
import fr.dcproject.component.workgroup.WorkgroupWithMembersI.Member
|
||||
import fr.dcproject.component.workgroup.WorkgroupWithMembersI.Member.Role
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityCreatedByImp
|
||||
import fr.postgresjson.entity.EntityDeletedAt
|
||||
import fr.postgresjson.entity.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import fr.postgresjson.entity.Serializable
|
||||
import java.util.UUID
|
||||
|
||||
@Deprecated("")
|
||||
@@ -37,8 +33,8 @@ data class Workgroup <C : CitizenBasicI>(
|
||||
anonymous,
|
||||
createdBy
|
||||
),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
UpdatedAt by UpdatedAt.Imp()
|
||||
|
||||
@Deprecated("")
|
||||
open class WorkgroupSimple<Z : CitizenI>(
|
||||
@@ -49,22 +45,22 @@ open class WorkgroupSimple<Z : CitizenI>(
|
||||
open var anonymous: Boolean = true,
|
||||
createdBy: Z
|
||||
) : WorkgroupRef(id),
|
||||
EntityCreatedBy<Z> by EntityCreatedByImp(createdBy),
|
||||
EntityDeletedAt by EntityDeletedAtImp()
|
||||
CreatedBy<Z> by CreatedBy.Imp(createdBy),
|
||||
DeletedAt by DeletedAt.Imp()
|
||||
|
||||
class WorkgroupCart(
|
||||
override val id: UUID,
|
||||
override val name: String
|
||||
) : WorkgroupCartI
|
||||
|
||||
interface WorkgroupCartI : UuidEntityI {
|
||||
interface WorkgroupCartI : EntityI {
|
||||
val name: String
|
||||
}
|
||||
open class WorkgroupRef(
|
||||
id: UUID? = null
|
||||
) : UuidEntity(id ?: UUID.randomUUID()), WorkgroupI
|
||||
) : Entity(id ?: UUID.randomUUID()), WorkgroupI
|
||||
|
||||
interface WorkgroupWithAuthI<Z : CitizenWithUserI> : WorkgroupWithMembersI<Z>, EntityCreatedBy<Z>, EntityDeletedAt {
|
||||
interface WorkgroupWithAuthI<Z : CitizenWithUserI> : WorkgroupWithMembersI<Z>, CreatedBy<Z>, DeletedAt {
|
||||
val anonymous: Boolean
|
||||
|
||||
fun isMember(user: UserI): Boolean = members.isMember(user)
|
||||
@@ -83,7 +79,7 @@ interface WorkgroupWithMembersI<Z : CitizenI> : WorkgroupI {
|
||||
class Member<C : CitizenI> (
|
||||
val citizen: C,
|
||||
val roles: List<Role> = emptyList()
|
||||
) : EntityI {
|
||||
) : fr.postgresjson.entity.EntityI {
|
||||
enum class Role {
|
||||
MASTER,
|
||||
MANAGER,
|
||||
@@ -113,4 +109,4 @@ fun <Z : CitizenWithUserI> List<Member<Z>>.getRoles(user: UserI): List<Role> =
|
||||
fun <Z : CitizenWithUserI> List<Member<Z>>.getRoles(citizen: CitizenI): List<Role> =
|
||||
firstOrNull { it.citizen.id == citizen.id }?.roles ?: emptyList()
|
||||
|
||||
interface WorkgroupI : UuidEntityI
|
||||
interface WorkgroupI : EntityI
|
||||
|
||||
Reference in New Issue
Block a user