#68 Clean Entities
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user