From 03350db56f7a95dff50563635b4059d5cd1de98e Mon Sep 17 00:00:00 2001 From: Fabrice Date: Thu, 3 Mar 2022 19:46:49 +0100 Subject: [PATCH] change ac.assert { can*() } to as.can*().assert() --- .../dcproject/component/article/routes/FindArticleVersions.kt | 2 +- .../fr/dcproject/component/article/routes/FindArticles.kt | 2 +- .../fr/dcproject/component/article/routes/GetOneArticle.kt | 2 +- .../fr/dcproject/component/article/routes/UpsertArticle.kt | 2 +- .../fr/dcproject/component/citizen/routes/ChangeMyPassword.kt | 2 +- .../fr/dcproject/component/citizen/routes/FindCitizens.kt | 2 +- .../fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt | 2 +- .../fr/dcproject/component/citizen/routes/GetOneCitizen.kt | 2 +- .../component/comment/article/routes/CreateCommentArticle.kt | 2 +- .../component/comment/article/routes/GetArticleComments.kt | 2 +- .../comment/article/routes/GetCitizenArticleComments.kt | 2 +- .../comment/constitution/routes/CreateConstitutionComment.kt | 2 +- .../constitution/routes/GetCitizenCommentConstitution.kt | 2 +- .../comment/constitution/routes/GetConstitutionComment.kt | 2 +- .../dcproject/component/comment/generic/routes/CreateComment.kt | 2 +- .../dcproject/component/comment/generic/routes/EditComment.kt | 2 +- .../component/comment/generic/routes/GetCommentChildren.kt | 2 +- .../dcproject/component/comment/generic/routes/GetOneComment.kt | 2 +- .../component/constitution/routes/CreateConstitution.kt | 2 +- .../component/constitution/routes/FindConstitutions.kt | 2 +- .../dcproject/component/constitution/routes/GetConstitution.kt | 2 +- .../dcproject/component/follow/routes/article/FollowArticle.kt | 2 +- .../component/follow/routes/article/GetFollowArticle.kt | 2 +- .../component/follow/routes/article/GetMyFollowsArticle.kt | 2 +- .../component/follow/routes/article/UnfollowArticle.kt | 2 +- .../dcproject/component/follow/routes/citizen/FollowCitizen.kt | 2 +- .../component/follow/routes/citizen/GetFollowCitizen.kt | 2 +- .../component/follow/routes/citizen/GetMyFollowsCitizen.kt | 2 +- .../component/follow/routes/citizen/UnfollowCitizen.kt | 2 +- .../component/follow/routes/constitution/FollowConstitution.kt | 2 +- .../follow/routes/constitution/GetFollowConstitution.kt | 2 +- .../follow/routes/constitution/GetMyFollowsConstitution.kt | 2 +- .../follow/routes/constitution/UnfollowConstitution.kt | 2 +- .../fr/dcproject/component/opinion/routes/GetCitizenOpinions.kt | 2 +- .../dcproject/component/opinion/routes/GetMyOpinionsArticle.kt | 2 +- .../fr/dcproject/component/opinion/routes/GetOpinionChoice.kt | 2 +- .../fr/dcproject/component/opinion/routes/GetOpinionChoices.kt | 2 +- .../fr/dcproject/component/opinion/routes/OpinionArticle.kt | 2 +- .../fr/dcproject/component/vote/routes/GetCitizenVotes.kt | 2 +- .../dcproject/component/vote/routes/GetCitizenVotesOnArticle.kt | 2 +- .../fr/dcproject/component/vote/routes/PutVoteOnArticle.kt | 2 +- .../fr/dcproject/component/vote/routes/PutVoteOnComment.kt | 2 +- .../fr/dcproject/component/vote/routes/PutVoteOnConstitution.kt | 2 +- .../fr/dcproject/component/workgroup/routes/CreateWorkgroup.kt | 2 +- .../fr/dcproject/component/workgroup/routes/DeleteWorkgroup.kt | 2 +- .../fr/dcproject/component/workgroup/routes/EditWorkgroup.kt | 2 +- .../fr/dcproject/component/workgroup/routes/GetWorkgroup.kt | 2 +- .../fr/dcproject/component/workgroup/routes/GetWorkgroups.kt | 2 +- .../component/workgroup/routes/members/AddMemberToWorkgroup.kt | 2 +- .../workgroup/routes/members/DeleteMembersOfWorkgroup.kt | 2 +- .../workgroup/routes/members/UpdateMemberOfWorkgroup.kt | 2 +- 51 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticleVersions.kt b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticleVersions.kt index 83092b3..b6a79aa 100644 --- a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticleVersions.kt +++ b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticleVersions.kt @@ -65,7 +65,7 @@ object FindArticleVersions { it.validate().badRequestIfNotValid() repo.findVersions(it) - .apply { ac.assert { canView(result, citizenOrNull) } } + .apply { ac.canView(result, citizenOrNull).assert() } .run { call.respond( toOutput { a: ArticleForListing -> diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt index a0a4518..a1cb212 100644 --- a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt +++ b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt @@ -76,7 +76,7 @@ object FindArticles { it.validate().badRequestIfNotValid() repo.findArticles(it) - .apply { ac.assert { canView(result, citizenOrNull) } } + .apply { ac.canView(result, citizenOrNull).assert() } .let { call.respond( it.toOutput { diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt b/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt index 50e1e04..03727ec 100644 --- a/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt @@ -27,7 +27,7 @@ object GetOneArticle { fun Route.getOneArticle(viewRepository: ArticleViewRepository, ac: ArticleAccessControl, repo: ArticleRepository) { get { val article: ArticleForView = repo.findById(it.article.id) ?: throw NotFoundException("Article ${it.article.id} not found") - ac.assert { canView(article, citizenOrNull) } + ac.canView(article, citizenOrNull).assert() call.respond( article.let { a -> diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/UpsertArticle.kt b/src/main/kotlin/fr/dcproject/component/article/routes/UpsertArticle.kt index 82ddb83..6106382 100644 --- a/src/main/kotlin/fr/dcproject/component/article/routes/UpsertArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/article/routes/UpsertArticle.kt @@ -83,7 +83,7 @@ object UpsertArticle { post { mustBeAuth() val article = call.convertRequestToEntity() - ac.assert { canUpsert(article, citizenOrNull) } + ac.canUpsert(article, citizenOrNull).assert() repo.upsert(article)?.let { a -> call.respond( object { diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/ChangeMyPassword.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/ChangeMyPassword.kt index cca3586..2cf870e 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/ChangeMyPassword.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/ChangeMyPassword.kt @@ -42,7 +42,7 @@ object ChangeMyPassword { mustBeAuth() val content = call.receiveOrBadRequest() .apply { validate().badRequestIfNotValid() } - ac.assert { canChangePassword(it.citizen, citizenOrNull) } + ac.canChangePassword(it.citizen, citizenOrNull).assert() userRepository.findByCredentials(UserPasswordCredential(citizen.user.username, content.oldPassword)) ?: throw BadRequestException("Bad Password") userRepository.changePassword( UserWithPassword( diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt index 872c090..a23b489 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt @@ -55,7 +55,7 @@ object FindCitizens { mustBeAuth() it.validate().badRequestIfNotValid() val citizens = repo.find(it.page, it.limit, it.sort, it.direction, it.search) - ac.assert { canView(citizens.result, citizenOrNull) } + ac.canView(citizens.result, citizenOrNull).assert() call.respond( citizens.toOutput { c: CitizenCreator -> object { diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt index 4ede796..4de6439 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt @@ -28,7 +28,7 @@ object GetCurrentCitizen { if (currentUser === null) { call.respond(HttpStatusCode.Unauthorized) } else { - ac.assert { canView(currentUser, citizenOrNull) } + ac.canView(currentUser, citizenOrNull).assert() call.respond( object { val id: UUID = citizen.id diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetOneCitizen.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetOneCitizen.kt index e49a25b..e78d1a3 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetOneCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetOneCitizen.kt @@ -29,7 +29,7 @@ object GetOneCitizen { get { mustBeAuth() val citizen = citizenRepository.findById(it.citizen.id) ?: throw NotFoundException("Citizen not found ${it.citizen.id}") - ac.assert { canView(citizen, citizenOrNull) } + ac.canView(citizen, citizenOrNull).assert() call.respond( object { diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt index 493f9aa..79f1588 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt @@ -51,7 +51,7 @@ object CreateCommentArticle { content = content ) }.let { comment -> - ac.assert { canCreate(comment, citizenOrNull) } + ac.canCreate(comment, citizenOrNull).assert() repo.comment(comment) call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt index 3ec2e88..7a337c6 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt @@ -58,7 +58,7 @@ object GetArticleComments { val comments = repo.findByTarget(it.article, it.page, it.limit, it.sort) if (comments.result.isNotEmpty()) { - ac.assert { canView(comments.result, citizenOrNull) } + ac.canView(comments.result, citizenOrNull).assert() } call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt index 7aa6d1d..35c7df0 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt @@ -28,7 +28,7 @@ object GetCitizenArticleComments { get { mustBeAuth() repo.findByCitizen(it.citizen).let { comments -> - ac.assert { canView(comments.result, citizenOrNull) } + ac.canView(comments.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, comments.toOutput { comment -> diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt index 0b700f0..f9d3e9b 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt @@ -53,7 +53,7 @@ object CreateConstitutionComment { content = content ) }.let { comment -> - ac.assert { canCreate(comment, citizenOrNull) } + ac.canCreate(comment, citizenOrNull).assert() repo.comment(comment) call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt index 9d9b3e2..80a52dd 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt @@ -28,7 +28,7 @@ object GetCitizenCommentConstitution { get { mustBeAuth() val comments = repo.findByCitizen(it.citizen) - ac.assert { canView(comments.result, citizenOrNull) } + ac.canView(comments.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, comments.toOutput { comment -> diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt index 47d417e..f265069 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt @@ -57,7 +57,7 @@ object GetConstitutionComment { it.validate().badRequestIfNotValid() val comments = repo.findByTarget(it.constitution) - ac.assert { canView(comments.result, citizenOrNull) } + ac.canView(comments.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, comments.toOutput { comment -> diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/CreateComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/CreateComment.kt index 6158794..3066e9e 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/CreateComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/CreateComment.kt @@ -54,7 +54,7 @@ object CreateComment { parent = parent, ) }.let { newComment -> - ac.assert { canCreate(newComment, citizenOrNull) } + ac.canCreate(newComment, citizenOrNull).assert() repo.comment(newComment) call.respond(HttpStatusCode.Created, newComment.toOutput()) } diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt index b4e1522..9a2c1d2 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt @@ -42,7 +42,7 @@ object EditComment { put { mustBeAuth() val commentOld = repo.findById(it.comment.id) ?: throw NotFoundException("Comment not found") - ac.assert { canUpdate(commentOld, citizenOrNull) } + ac.canUpdate(commentOld, citizenOrNull).assert() call.receiveOrBadRequest() .apply { validate().badRequestIfNotValid() } diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt index a478f0d..a019018 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt @@ -39,7 +39,7 @@ object GetCommentChildren { it.limit ) - ac.assert { canView(comments.result, citizenOrNull) } + ac.canView(comments.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt index ae3314c..c2d5bd4 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt @@ -27,7 +27,7 @@ object GetOneComment { fun Route.getOneComment(repo: CommentRepository, ac: CommentAccessControl) { get { val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found") - ac.assert { canView(comment, citizenOrNull) } + ac.canView(comment, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt index cb4e11f..d635689 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt @@ -89,7 +89,7 @@ object CreateConstitution { post { mustBeAuth() getNewConstitution(call.receiveOrBadRequest(), citizen).let { - ac.assert { canCreate(it, citizenOrNull) } + ac.canCreate(it, citizenOrNull).assert() val c = repo.upsert(it) ?: error("Unable to create Constitution") call.respond( HttpStatusCode.Created, diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt index c570753..55caf9f 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt @@ -54,7 +54,7 @@ object FindConstitutions { get { it.validate().badRequestIfNotValid() val constitutions = repo.find(it.page, it.limit, it.sort, it.direction, it.search) - ac.assert { canView(constitutions.result, citizenOrNull) } + ac.canView(constitutions.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, constitutions.toOutput { c -> diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt index 64ea816..1b987e0 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt @@ -27,7 +27,7 @@ object GetConstitution { fun Route.getConstitution(ac: ConstitutionAccessControl, constitutionRepo: ConstitutionRepository) { get { val constitution = constitutionRepo.findById(it.constitution.id) ?: throw NotFoundException("Unable to find constitution ${it.constitution.id}") - ac.assert { canView(constitution, citizenOrNull) } + ac.canView(constitution, citizenOrNull).assert() call.respond( HttpStatusCode.OK, constitution.let { c -> diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/FollowArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/FollowArticle.kt index f9d82e4..a1fa54a 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/FollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/FollowArticle.kt @@ -28,7 +28,7 @@ object FollowArticle { post { mustBeAuth() val follow = FollowForUpdate(target = it.article, createdBy = this.citizen) - ac.assert { canCreate(follow, citizenOrNull) } + ac.canCreate(follow, citizenOrNull).assert() repo.follow(follow) call.respond(HttpStatusCode.Created) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt index b2e2bed..3ad0f91 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt @@ -27,7 +27,7 @@ object GetFollowArticle { fun Route.getFollowArticle(repo: FollowArticleRepository, ac: FollowAccessControl) { get { repo.findFollow(citizen, it.article)?.let { follow -> - ac.assert { canView(follow, citizenOrNull) } + ac.canView(follow, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follow.toOutput() diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetMyFollowsArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetMyFollowsArticle.kt index ea40bec..29678b5 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetMyFollowsArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetMyFollowsArticle.kt @@ -28,7 +28,7 @@ object GetMyFollowsArticle { get { mustBeAuth() val follows = repo.findByCitizen(it.citizen) - ac.assert { canView(follows.result, citizenOrNull) } + ac.canView(follows.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follows.toOutput { f -> diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/UnfollowArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/UnfollowArticle.kt index e90b797..eca97ce 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/UnfollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/UnfollowArticle.kt @@ -28,7 +28,7 @@ object UnfollowArticle { delete { mustBeAuth() val follow = FollowForUpdate(target = it.article, createdBy = this.citizen) - ac.assert { canDelete(follow, citizenOrNull) } + ac.canDelete(follow, citizenOrNull).assert() repo.unfollow(follow) call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/FollowCitizen.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/FollowCitizen.kt index a84aa3b..9e01114 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/FollowCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/FollowCitizen.kt @@ -28,7 +28,7 @@ object FollowCitizen { post { mustBeAuth() val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen) - ac.assert { canCreate(follow, citizenOrNull) } + ac.canCreate(follow, citizenOrNull).assert() repo.follow(follow) call.respond(HttpStatusCode.Created) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt index b41a18d..2f57717 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt @@ -26,7 +26,7 @@ object GetFollowCitizen { fun Route.getFollowCitizen(repo: FollowCitizenRepository, ac: FollowAccessControl) { get { repo.findFollow(citizen, it.citizen)?.let { follow -> - ac.assert { canView(follow, citizenOrNull) } + ac.canView(follow, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follow.toOutput() diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetMyFollowsCitizen.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetMyFollowsCitizen.kt index 24c35ef..46da666 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetMyFollowsCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetMyFollowsCitizen.kt @@ -28,7 +28,7 @@ object GetMyFollowsCitizen { get { mustBeAuth() val follows = repo.findByCitizen(it.citizen) - ac.assert { canView(follows.result, citizenOrNull) } + ac.canView(follows.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follows.toOutput { f -> diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/UnfollowCitizen.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/UnfollowCitizen.kt index 8b47903..711c883 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/UnfollowCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/UnfollowCitizen.kt @@ -28,7 +28,7 @@ object UnfollowCitizen { delete { mustBeAuth() val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen) - ac.assert { canDelete(follow, citizenOrNull) } + ac.canDelete(follow, citizenOrNull).assert() repo.unfollow(follow) call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/FollowConstitution.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/FollowConstitution.kt index cba056c..4c0e925 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/FollowConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/FollowConstitution.kt @@ -28,7 +28,7 @@ object FollowConstitution { post { mustBeAuth() val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen) - ac.assert { canCreate(follow, citizenOrNull) } + ac.canCreate(follow, citizenOrNull).assert() repo.follow(follow) call.respond(HttpStatusCode.Created) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt index 3908e5d..ca36941 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt @@ -27,7 +27,7 @@ object GetFollowConstitution { fun Route.getFollowConstitution(repo: FollowConstitutionRepository, ac: FollowAccessControl) { get { repo.findFollow(citizen, it.constitution)?.let { follow -> - ac.assert { canView(follow, citizenOrNull) } + ac.canView(follow, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follow.toOutput() diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetMyFollowsConstitution.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetMyFollowsConstitution.kt index 6a11a2e..3540837 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetMyFollowsConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetMyFollowsConstitution.kt @@ -28,7 +28,7 @@ object GetMyFollowsConstitution { get { mustBeAuth() val follows = repo.findByCitizen(it.citizen) - ac.assert { canView(follows.result, citizenOrNull) } + ac.canView(follows.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, follows.toOutput { f -> diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/UnfollowConstitution.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/UnfollowConstitution.kt index f892e3c..28bcb6a 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/UnfollowConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/UnfollowConstitution.kt @@ -28,7 +28,7 @@ object UnfollowConstitution { delete { mustBeAuth() val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen) - ac.assert { canDelete(follow, citizenOrNull) } + ac.canDelete(follow, citizenOrNull).assert() repo.unfollow(follow) call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetCitizenOpinions.kt b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetCitizenOpinions.kt index 3857944..58c840f 100644 --- a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetCitizenOpinions.kt +++ b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetCitizenOpinions.kt @@ -34,7 +34,7 @@ object GetCitizenOpinions { get { mustBeAuth() val opinionsEntities: List> = repo.findCitizenOpinionsByTargets(it.citizen, it.id) - ac.assert { canView(opinionsEntities, citizenOrNull) } + ac.canView(opinionsEntities, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetMyOpinionsArticle.kt b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetMyOpinionsArticle.kt index fe28926..2380950 100644 --- a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetMyOpinionsArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetMyOpinionsArticle.kt @@ -55,7 +55,7 @@ object GetMyOpinionsArticle { it.validate().badRequestIfNotValid() val opinions: Paginated> = repo.findCitizenOpinions(citizen, it.page, it.limit) - ac.assert { canView(opinions.result, citizenOrNull) } + ac.canView(opinions.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, opinions.toOutput { it.toOutput() } diff --git a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoice.kt b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoice.kt index 809b10a..a814424 100644 --- a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoice.kt +++ b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoice.kt @@ -25,7 +25,7 @@ object GetOpinionChoice { fun Route.getOpinionChoice(ac: OpinionChoiceAccessControl, opinionChoiceRepository: OpinionChoiceRepository) { get { val opinionChoice = opinionChoiceRepository.findOpinionChoiceById(it.opinionChoice.id) ?: throw NotFoundException("OpinionChoice ${it.opinionChoice.id} not found") - ac.assert { canView(it.opinionChoice, citizenOrNull) } + ac.canView(it.opinionChoice, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoices.kt b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoices.kt index e440516..a65439c 100644 --- a/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoices.kt +++ b/src/main/kotlin/fr/dcproject/component/opinion/routes/GetOpinionChoices.kt @@ -20,7 +20,7 @@ object GetOpinionChoices { fun Route.getOpinionChoices(repo: OpinionChoiceRepository, ac: OpinionChoiceAccessControl) { get { val opinionChoices = repo.findOpinionsChoices(it.targets) - ac.assert { canView(opinionChoices, citizenOrNull) } + ac.canView(opinionChoices, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/opinion/routes/OpinionArticle.kt b/src/main/kotlin/fr/dcproject/component/opinion/routes/OpinionArticle.kt index 210671d..6198694 100644 --- a/src/main/kotlin/fr/dcproject/component/opinion/routes/OpinionArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/opinion/routes/OpinionArticle.kt @@ -43,7 +43,7 @@ object OpinionArticle { createdBy = citizen ) }.let { opinions -> - ac.assert { canCreate(opinions, citizenOrNull) } + ac.canCreate(opinions, citizenOrNull).assert() repo.updateOpinions(opinions) }.let { call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotes.kt b/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotes.kt index d4920ee..64eb7e2 100644 --- a/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotes.kt +++ b/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotes.kt @@ -30,7 +30,7 @@ object GetCitizenVotes { mustBeAuth() val votes = repo.findCitizenVotesByTargets(it.citizen, it.id) if (votes.isNotEmpty()) { - ac.assert { canView(votes, citizenOrNull) } + ac.canView(votes, citizenOrNull).assert() } call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotesOnArticle.kt b/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotesOnArticle.kt index 102300b..caacd61 100644 --- a/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotesOnArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/vote/routes/GetCitizenVotesOnArticle.kt @@ -49,7 +49,7 @@ object GetCitizenVotesOnArticle { it.validate().badRequestIfNotValid() val votes = repo.findByCitizen(it.citizen, it.page, it.limit) - ac.assert { canView(votes.result, citizenOrNull) } + ac.canView(votes.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, diff --git a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnArticle.kt b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnArticle.kt index 0b169e0..9e8c1ae 100644 --- a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnArticle.kt @@ -51,7 +51,7 @@ object PutVoteOnArticle { note = input.note, createdBy = this.citizen ) - ac.assert { canCreate(vote, citizenOrNull) } + ac.canCreate(vote, citizenOrNull).assert() val votes = repo.vote(vote) call.respond( HttpStatusCode.Created, diff --git a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnComment.kt b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnComment.kt index cf65882..b77ccc3 100644 --- a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnComment.kt +++ b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnComment.kt @@ -52,7 +52,7 @@ object PutVoteOnComment { note = input.note, createdBy = this.citizen ) - ac.assert { canCreate(vote, citizenOrNull) } + ac.canCreate(vote, citizenOrNull).assert() val votes = voteCommentRepo.vote(vote) call.respond( HttpStatusCode.Created, diff --git a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnConstitution.kt b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnConstitution.kt index 0cb6a8d..b51ef67 100644 --- a/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/vote/routes/PutVoteOnConstitution.kt @@ -51,7 +51,7 @@ object PutVoteOnConstitution { note = input.note, createdBy = this.citizen ) - ac.assert { canCreate(vote, citizenOrNull) } + ac.canCreate(vote, citizenOrNull).assert() repo.vote(vote) call.respond(HttpStatusCode.Created) } diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/CreateWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/CreateWorkgroup.kt index fcec099..08ce634 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/CreateWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/CreateWorkgroup.kt @@ -66,7 +66,7 @@ object CreateWorkgroup { anonymous ?: true, ) }.let { workgroup -> - ac.assert { canCreate(workgroup, citizenOrNull) } + ac.canCreate(workgroup, citizenOrNull).assert() repo.upsert(workgroup) }.let { w -> call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/DeleteWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/DeleteWorkgroup.kt index cb6788d..751e864 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/DeleteWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/DeleteWorkgroup.kt @@ -23,7 +23,7 @@ object DeleteWorkgroup { delete { mustBeAuth() repo.findById(it.workgroupId)?.let { workgroup -> - ac.assert { canDelete(workgroup, citizenOrNull) } + ac.canDelete(workgroup, citizenOrNull).assert() repo.delete(workgroup) call.respond(HttpStatusCode.NoContent) } ?: call.respond(HttpStatusCode.NotFound) diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/EditWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/EditWorkgroup.kt index 7a80327..95f911c 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/EditWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/EditWorkgroup.kt @@ -65,7 +65,7 @@ object EditWorkgroup { deletedAt = old.deletedAt, members = old.members, ).let { workgroup -> - ac.assert { canUpdate(workgroup, citizenOrNull) } + ac.canUpdate(workgroup, citizenOrNull).assert() repo.upsert(workgroup) }.let { call.respond(HttpStatusCode.OK, it.toOutput()) diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroup.kt index f242406..d73b3ef 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroup.kt @@ -24,7 +24,7 @@ object GetWorkgroup { fun Route.getWorkgroup(repo: WorkgroupRepository, ac: WorkgroupAccessControl) { get { repo.findById(it.workgroup.id)?.let { workgroup -> - ac.assert { canView(workgroup, citizenOrNull) } + ac.canView(workgroup, citizenOrNull).assert() call.respond( HttpStatusCode.OK, workgroup.toOutput() diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroups.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroups.kt index be8a606..7265e7d 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroups.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/GetWorkgroups.kt @@ -69,7 +69,7 @@ object GetWorkgroups { it.search, WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members) ) - ac.assert { canView(workgroups.result, citizenOrNull) } + ac.canView(workgroups.result, citizenOrNull).assert() call.respond( HttpStatusCode.OK, workgroups.toOutput { it.toOutputListing() } diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/AddMemberToWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/AddMemberToWorkgroup.kt index b52cc14..14f14f9 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/AddMemberToWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/AddMemberToWorkgroup.kt @@ -47,7 +47,7 @@ object AddMemberToWorkgroup { mustBeAuth() repo.findById(it.workgroupId)?.let { workgroup -> call.getMembersFromRequest().let { members -> - ac.assert { canAddMembers(workgroup, citizenOrNull) } + ac.canAddMembers(workgroup, citizenOrNull).assert() repo.addMembers(workgroup, members) }.let { members -> call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/DeleteMembersOfWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/DeleteMembersOfWorkgroup.kt index 0e65328..ecd51bb 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/DeleteMembersOfWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/DeleteMembersOfWorkgroup.kt @@ -39,7 +39,7 @@ object DeleteMembersOfWorkgroup { repo.findById(it.workgroupId)?.let { workgroup -> call.getMembersFromRequest() .let { members -> - ac.assert { canRemoveMembers(workgroup, citizenOrNull) } + ac.canRemoveMembers(workgroup, citizenOrNull).assert() repo.removeMembers(workgroup, members) }.let { members -> call.respond( diff --git a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/UpdateMemberOfWorkgroup.kt b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/UpdateMemberOfWorkgroup.kt index a4bc6ea..03f788f 100644 --- a/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/UpdateMemberOfWorkgroup.kt +++ b/src/main/kotlin/fr/dcproject/component/workgroup/routes/members/UpdateMemberOfWorkgroup.kt @@ -45,7 +45,7 @@ object UpdateMemberOfWorkgroup { mustBeAuth() repo.findById(it.workgroupId)?.let { workgroup -> call.getMembersFromRequest().let { members -> - ac.assert { canUpdateMembers(workgroup, citizenOrNull) } + ac.canUpdateMembers(workgroup, citizenOrNull).assert() repo.updateMembers(workgroup, members) }.let { members -> call.respond(