#68 Clean follow Entity

This commit is contained in:
2021-03-01 22:44:17 +01:00
parent 66dcff8f46
commit 8d93fc8b3c
11 changed files with 78 additions and 53 deletions

View File

@@ -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")
}