#68 Clean follow Entity
This commit is contained in:
5
.idea/gradle.xml
generated
5
.idea/gradle.xml
generated
@@ -4,8 +4,8 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="delegatedBuild" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="delegatedBuild" value="true" />
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
@@ -13,7 +13,6 @@
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -164,6 +164,14 @@ tasks.withType<Jar> {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
sourceCompatibility = "11"
|
||||
targetCompatibility = "11"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
mergeServiceFiles("META-INF/services")
|
||||
archiveFileName.set("${archiveBaseName.get()}-latest-all.${archiveExtension.get()}")
|
||||
|
||||
@@ -27,6 +27,15 @@ open class User(
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
UpdatedAt by UpdatedAt.Imp()
|
||||
|
||||
class UserCreator(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override val username: String,
|
||||
) : UserRef(id), UserWithUsername
|
||||
|
||||
interface UserWithUsername {
|
||||
val username: String
|
||||
}
|
||||
|
||||
interface UserWithPasswordI {
|
||||
val id: UUID
|
||||
val password: String
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.UserCreator
|
||||
import fr.dcproject.component.auth.UserForCreate
|
||||
import fr.dcproject.component.auth.UserI
|
||||
import fr.dcproject.component.auth.UserRef
|
||||
@@ -50,6 +51,28 @@ class Citizen(
|
||||
)
|
||||
}
|
||||
|
||||
data class CitizenCreator(
|
||||
override var id: UUID = UUID.randomUUID(),
|
||||
override var name: Name,
|
||||
override var email: String,
|
||||
override var voteAnonymous: Boolean = true,
|
||||
override var followAnonymous: Boolean = true,
|
||||
override val user: UserCreator,
|
||||
override val deletedAt: DateTime? = null
|
||||
) : CitizenCreatorI,
|
||||
CitizenRefWithUser(id, user),
|
||||
DeletedAt by DeletedAt.Imp(deletedAt)
|
||||
|
||||
interface CitizenCreatorI : CitizenWithUserI, CitizenWithEmail, CitizenCartI, DeletedAt {
|
||||
override val id: UUID
|
||||
override val name: Name
|
||||
override val email: String
|
||||
val voteAnonymous: Boolean
|
||||
val followAnonymous: Boolean
|
||||
override val user: UserCreator
|
||||
override val deletedAt: DateTime?
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
data class CitizenBasic(
|
||||
override var id: UUID = UUID.randomUUID(),
|
||||
|
||||
@@ -6,27 +6,18 @@ 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.CitizenCreator
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import java.util.UUID
|
||||
|
||||
@Deprecated("")
|
||||
class Follow<T : TargetI>(
|
||||
open class FollowForView<T : TargetI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override val createdBy: CitizenBasic,
|
||||
override val createdBy: CitizenCreator,
|
||||
override var target: T
|
||||
) : ExtraI<T, CitizenBasicI>,
|
||||
FollowSimple<T, CitizenBasicI>(id, createdBy, target)
|
||||
|
||||
@Deprecated("")
|
||||
open class FollowSimple<T : TargetI, C : CitizenI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override val createdBy: C,
|
||||
override var target: T
|
||||
) : ExtraI<T, C>,
|
||||
) : ExtraI<T, CitizenRef>,
|
||||
FollowRef(id),
|
||||
Created<C> by Created.Imp(createdBy)
|
||||
Created<CitizenRef> by Created.Imp(createdBy)
|
||||
|
||||
class FollowForUpdate<T : TargetI, C : CitizenI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
|
||||
@@ -3,7 +3,6 @@ package fr.dcproject.component.follow
|
||||
import fr.dcproject.common.security.AccessControl
|
||||
import fr.dcproject.common.security.AccessResponse
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.follow.Follow as FollowEntity
|
||||
|
||||
class FollowAccessControl : AccessControl() {
|
||||
fun canCreate(subject: FollowI, citizen: CitizenI?): AccessResponse {
|
||||
@@ -16,10 +15,10 @@ class FollowAccessControl : AccessControl() {
|
||||
else granted()
|
||||
}
|
||||
|
||||
fun <S : FollowEntity<*>> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse =
|
||||
fun <S : FollowForView<*>> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse =
|
||||
canAll(subjects) { canView(it, citizen) }
|
||||
|
||||
fun canView(subject: FollowEntity<*>, citizen: CitizenI?): AccessResponse {
|
||||
fun canView(subject: FollowForView<*>, citizen: CitizenI?): AccessResponse {
|
||||
return if ((citizen != null && subject.createdBy.id == citizen.id) || !subject.createdBy.followAnonymous) granted()
|
||||
else denied("You cannot view an anonymous follow", "follow.view.anonymous")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
@@ -14,21 +13,20 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import java.util.UUID
|
||||
import fr.dcproject.component.constitution.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.component.follow.Follow as FollowEntity
|
||||
|
||||
sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requester: Requester) : RepositoryI {
|
||||
open fun findByCitizen(
|
||||
citizen: CitizenI,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<OUT>> =
|
||||
): Paginated<FollowForView<OUT>> =
|
||||
findByCitizen(citizen.id, page, limit)
|
||||
|
||||
open fun findByCitizen(
|
||||
citizenId: UUID,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<OUT>> {
|
||||
): Paginated<FollowForView<OUT>> {
|
||||
return requester
|
||||
.getFunction("find_follows_by_citizen")
|
||||
.select(
|
||||
@@ -61,7 +59,7 @@ sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requ
|
||||
open fun findFollow(
|
||||
citizen: CitizenI,
|
||||
target: TargetRef
|
||||
): FollowEntity<OUT>? =
|
||||
): FollowForView<OUT>? =
|
||||
requester
|
||||
.getFunction("find_follow")
|
||||
.selectOne(
|
||||
@@ -73,7 +71,7 @@ sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requ
|
||||
fun findFollowsByTarget(
|
||||
target: Entity,
|
||||
bulkSize: Int = 300
|
||||
): Flow<FollowSimple<IN, CitizenRef>> = flow {
|
||||
): Flow<FollowForView<IN>> = flow {
|
||||
var nextPage = 1
|
||||
do {
|
||||
val paginate = findFollowsByTarget(target, nextPage, bulkSize)
|
||||
@@ -88,7 +86,7 @@ sealed class FollowRepository<IN : TargetRef, OUT : TargetRef>(override var requ
|
||||
target: Entity,
|
||||
page: Int = 1,
|
||||
limit: Int = 300
|
||||
): Paginated<FollowSimple<IN, CitizenRef>>
|
||||
): Paginated<FollowForView<IN>>
|
||||
}
|
||||
|
||||
class FollowArticleRepository(requester: Requester) : FollowRepository<ArticleRef, ArticleForView>(requester) {
|
||||
@@ -96,7 +94,7 @@ class FollowArticleRepository(requester: Requester) : FollowRepository<ArticleRe
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowEntity<ArticleForView>> {
|
||||
): Paginated<FollowForView<ArticleForView>> {
|
||||
return requester.run {
|
||||
getFunction("find_follows_article_by_citizen")
|
||||
.select(
|
||||
@@ -111,7 +109,7 @@ class FollowArticleRepository(requester: Requester) : FollowRepository<ArticleRe
|
||||
target: Entity,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowSimple<ArticleRef, CitizenRef>> {
|
||||
): Paginated<FollowForView<ArticleRef>> {
|
||||
return requester
|
||||
.getFunction("find_follows_article_by_target")
|
||||
.select(
|
||||
@@ -127,7 +125,7 @@ class FollowConstitutionRepository(requester: Requester) : FollowRepository<Cons
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowEntity<ConstitutionEntity>> {
|
||||
): Paginated<FollowForView<ConstitutionEntity>> {
|
||||
return requester.run {
|
||||
getFunction("find_follows_constitution_by_citizen")
|
||||
.select(
|
||||
@@ -142,7 +140,7 @@ class FollowConstitutionRepository(requester: Requester) : FollowRepository<Cons
|
||||
target: Entity,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowSimple<ConstitutionRef, CitizenRef>> {
|
||||
): Paginated<FollowForView<ConstitutionRef>> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@ import com.rabbitmq.client.Consumer
|
||||
import com.rabbitmq.client.DefaultConsumer
|
||||
import com.rabbitmq.client.Envelope
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.follow.FollowArticleRepository
|
||||
import fr.dcproject.component.follow.FollowConstitutionRepository
|
||||
import fr.dcproject.component.follow.FollowSimple
|
||||
import fr.dcproject.component.follow.FollowForView
|
||||
import io.ktor.utils.io.errors.IOException
|
||||
import io.lettuce.core.RedisClient
|
||||
import io.lettuce.core.api.async.RedisAsyncCommands
|
||||
@@ -108,6 +107,6 @@ class NotificationConsumer(
|
||||
private class DecodedMessage(
|
||||
val event: EntityNotification,
|
||||
val rawMessage: String,
|
||||
val follow: FollowSimple<out TargetRef, CitizenRef>
|
||||
val follow: FollowForView<out TargetRef>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@ import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.component.article.ArticleRepository
|
||||
import fr.dcproject.component.article.ArticleWithTitleI
|
||||
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.dcproject.component.follow.FollowForView
|
||||
import java.util.UUID
|
||||
|
||||
class NotificationEmailSender(
|
||||
@@ -20,7 +19,7 @@ class NotificationEmailSender(
|
||||
private val citizenRepo: CitizenRepository,
|
||||
private val articleRepo: ArticleRepository
|
||||
) {
|
||||
fun sendEmail(follow: FollowSimple<out TargetRef, CitizenRef>) {
|
||||
fun sendEmail(follow: FollowForView<out TargetRef>) {
|
||||
val citizen = citizenRepo.findById(follow.createdBy.id) ?: noCitizen(follow.createdBy.id)
|
||||
val target = when (follow.target.reference) {
|
||||
"article" ->
|
||||
|
||||
@@ -5,9 +5,12 @@ import com.rabbitmq.client.ShutdownSignalException
|
||||
import fr.dcproject.application.Configuration
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
import fr.dcproject.component.auth.UserCreator
|
||||
import fr.dcproject.component.citizen.CitizenCreator
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.citizen.CitizenRef
|
||||
import fr.dcproject.component.follow.FollowArticleRepository
|
||||
import fr.dcproject.component.follow.FollowSimple
|
||||
import fr.dcproject.component.follow.FollowForView
|
||||
import fr.dcproject.component.notification.ArticleUpdateNotification
|
||||
import fr.dcproject.component.notification.NotificationConsumer
|
||||
import fr.dcproject.component.notification.NotificationEmailSender
|
||||
@@ -78,8 +81,8 @@ class NotificationConsumerTest {
|
||||
val rabbitFactory: ConnectionFactory = ConnectionFactory().apply { setUri(config.rabbitmq) }
|
||||
val followArticleRepo = mockk<FollowArticleRepository> {
|
||||
every { findFollowsByTarget(any()) } returns flow {
|
||||
FollowSimple(
|
||||
createdBy = CitizenRef(),
|
||||
FollowForView(
|
||||
createdBy = CitizenCreator(name = CitizenI.Name("John", "Doe"), email = "john.doe@dc-project.com", user = UserCreator(username = "john-doe")),
|
||||
target = ArticleRef(),
|
||||
).let { emit(it) }
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import fr.dcproject.common.security.AccessDecision.DENIED
|
||||
import fr.dcproject.common.security.AccessDecision.GRANTED
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.auth.User
|
||||
import fr.dcproject.component.auth.UserCreator
|
||||
import fr.dcproject.component.auth.UserI
|
||||
import fr.dcproject.component.citizen.Citizen
|
||||
import fr.dcproject.component.citizen.CitizenBasic
|
||||
import fr.dcproject.component.citizen.CitizenCart
|
||||
import fr.dcproject.component.citizen.CitizenCreator
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.follow.Follow
|
||||
import fr.dcproject.component.follow.FollowAccessControl
|
||||
import fr.dcproject.component.follow.FollowForView
|
||||
import org.amshove.kluent.`should be`
|
||||
import org.joda.time.DateTime
|
||||
import org.junit.jupiter.api.Tag
|
||||
@@ -25,12 +26,10 @@ import java.util.UUID
|
||||
@Execution(CONCURRENT)
|
||||
@Tags(Tag("security"), Tag("unit"))
|
||||
internal class `Follow Access Control` {
|
||||
private val tesla = CitizenBasic(
|
||||
user = User(
|
||||
private val tesla = CitizenCreator(
|
||||
user = UserCreator(
|
||||
username = "nicolas-tesla",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
birthday = DateTime.now(),
|
||||
email = "tesla@best.com",
|
||||
name = CitizenI.Name("Nicolas", "Tesla"),
|
||||
followAnonymous = false
|
||||
@@ -46,13 +45,11 @@ internal class `Follow Access Control` {
|
||||
followAnonymous = false
|
||||
)
|
||||
|
||||
private val einstein = CitizenBasic(
|
||||
private val einstein = CitizenCreator(
|
||||
id = UUID.fromString("319f1226-8f47-4df3-babd-2c7671ad0fbc"),
|
||||
user = User(
|
||||
user = UserCreator(
|
||||
username = "albert-einstein",
|
||||
roles = listOf(UserI.Roles.ROLE_USER)
|
||||
),
|
||||
birthday = DateTime.now(),
|
||||
email = "einstein@best.com",
|
||||
name = CitizenI.Name("Albert", "Einstein"),
|
||||
followAnonymous = true
|
||||
@@ -86,12 +83,12 @@ internal class `Follow Access Control` {
|
||||
title = "Super article"
|
||||
)
|
||||
|
||||
private val follow1 = Follow(
|
||||
private val follow1 = FollowForView(
|
||||
createdBy = tesla,
|
||||
target = article1
|
||||
)
|
||||
|
||||
private val followAnon = Follow(
|
||||
private val followAnon = FollowForView(
|
||||
createdBy = einstein,
|
||||
target = article1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user