Fix #106
@@ -65,7 +65,7 @@ object FindArticleVersions {
|
|||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
|
|
||||||
repo.findVersions(it)
|
repo.findVersions(it)
|
||||||
.apply { ac.assert { canView(result, citizenOrNull) } }
|
.apply { ac.canView(result, citizenOrNull).assert() }
|
||||||
.run {
|
.run {
|
||||||
call.respond(
|
call.respond(
|
||||||
toOutput { a: ArticleForListing ->
|
toOutput { a: ArticleForListing ->
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ object FindArticles {
|
|||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
|
|
||||||
repo.findArticles(it)
|
repo.findArticles(it)
|
||||||
.apply { ac.assert { canView(result, citizenOrNull) } }
|
.apply { ac.canView(result, citizenOrNull).assert() }
|
||||||
.let {
|
.let {
|
||||||
call.respond(
|
call.respond(
|
||||||
it.toOutput {
|
it.toOutput {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object GetOneArticle {
|
|||||||
fun Route.getOneArticle(viewRepository: ArticleViewRepository<ArticleForView>, ac: ArticleAccessControl, repo: ArticleRepository) {
|
fun Route.getOneArticle(viewRepository: ArticleViewRepository<ArticleForView>, ac: ArticleAccessControl, repo: ArticleRepository) {
|
||||||
get<ArticleRequest> {
|
get<ArticleRequest> {
|
||||||
val article: ArticleForView = repo.findById(it.article.id) ?: throw NotFoundException("Article ${it.article.id} not found")
|
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(
|
call.respond(
|
||||||
article.let { a ->
|
article.let { a ->
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ object UpsertArticle {
|
|||||||
post<UpsertArticleRequest> {
|
post<UpsertArticleRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val article = call.convertRequestToEntity()
|
val article = call.convertRequestToEntity()
|
||||||
ac.assert { canUpsert(article, citizenOrNull) }
|
ac.canUpsert(article, citizenOrNull).assert()
|
||||||
repo.upsert(article)?.let { a ->
|
repo.upsert(article)?.let { a ->
|
||||||
call.respond(
|
call.respond(
|
||||||
object {
|
object {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ object ChangeMyPassword {
|
|||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val content = call.receiveOrBadRequest<ChangePasswordCitizenRequest.Input>()
|
val content = call.receiveOrBadRequest<ChangePasswordCitizenRequest.Input>()
|
||||||
.apply { validate().badRequestIfNotValid() }
|
.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.findByCredentials(UserPasswordCredential(citizen.user.username, content.oldPassword)) ?: throw BadRequestException("Bad Password")
|
||||||
userRepository.changePassword(
|
userRepository.changePassword(
|
||||||
UserWithPassword(
|
UserWithPassword(
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ object FindCitizens {
|
|||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
val citizens = repo.find(it.page, it.limit, it.sort, it.direction, it.search)
|
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(
|
call.respond(
|
||||||
citizens.toOutput { c: CitizenCreator ->
|
citizens.toOutput { c: CitizenCreator ->
|
||||||
object {
|
object {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetCurrentCitizen {
|
|||||||
if (currentUser === null) {
|
if (currentUser === null) {
|
||||||
call.respond(HttpStatusCode.Unauthorized)
|
call.respond(HttpStatusCode.Unauthorized)
|
||||||
} else {
|
} else {
|
||||||
ac.assert { canView(currentUser, citizenOrNull) }
|
ac.canView(currentUser, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
object {
|
object {
|
||||||
val id: UUID = citizen.id
|
val id: UUID = citizen.id
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ object GetOneCitizen {
|
|||||||
get<CitizenRequest> {
|
get<CitizenRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val citizen = citizenRepository.findById(it.citizen.id) ?: throw NotFoundException("Citizen not found ${it.citizen.id}")
|
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(
|
call.respond(
|
||||||
object {
|
object {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ object CreateCommentArticle {
|
|||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}.let { comment ->
|
}.let { comment ->
|
||||||
ac.assert { canCreate(comment, citizenOrNull) }
|
ac.canCreate(comment, citizenOrNull).assert()
|
||||||
repo.comment(comment)
|
repo.comment(comment)
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ object GetArticleComments {
|
|||||||
|
|
||||||
val comments = repo.findByTarget(it.article, it.page, it.limit, it.sort)
|
val comments = repo.findByTarget(it.article, it.page, it.limit, it.sort)
|
||||||
if (comments.result.isNotEmpty()) {
|
if (comments.result.isNotEmpty()) {
|
||||||
ac.assert { canView(comments.result, citizenOrNull) }
|
ac.canView(comments.result, citizenOrNull).assert()
|
||||||
}
|
}
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetCitizenArticleComments {
|
|||||||
get<CitizenCommentArticleRequest> {
|
get<CitizenCommentArticleRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
repo.findByCitizen(it.citizen).let { comments ->
|
repo.findByCitizen(it.citizen).let { comments ->
|
||||||
ac.assert { canView(comments.result, citizenOrNull) }
|
ac.canView(comments.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
comments.toOutput { comment ->
|
comments.toOutput { comment ->
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ object CreateConstitutionComment {
|
|||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}.let { comment ->
|
}.let { comment ->
|
||||||
ac.assert { canCreate(comment, citizenOrNull) }
|
ac.canCreate(comment, citizenOrNull).assert()
|
||||||
repo.comment(comment)
|
repo.comment(comment)
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetCitizenCommentConstitution {
|
|||||||
get<GetCitizenCommentConstitutionRequest> {
|
get<GetCitizenCommentConstitutionRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val comments = repo.findByCitizen(it.citizen)
|
val comments = repo.findByCitizen(it.citizen)
|
||||||
ac.assert { canView(comments.result, citizenOrNull) }
|
ac.canView(comments.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
comments.toOutput { comment ->
|
comments.toOutput { comment ->
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ object GetConstitutionComment {
|
|||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
|
|
||||||
val comments = repo.findByTarget(it.constitution)
|
val comments = repo.findByTarget(it.constitution)
|
||||||
ac.assert { canView(comments.result, citizenOrNull) }
|
ac.canView(comments.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
comments.toOutput { comment ->
|
comments.toOutput { comment ->
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ object CreateComment {
|
|||||||
parent = parent,
|
parent = parent,
|
||||||
)
|
)
|
||||||
}.let { newComment ->
|
}.let { newComment ->
|
||||||
ac.assert { canCreate(newComment, citizenOrNull) }
|
ac.canCreate(newComment, citizenOrNull).assert()
|
||||||
repo.comment(newComment)
|
repo.comment(newComment)
|
||||||
call.respond(HttpStatusCode.Created, newComment.toOutput())
|
call.respond(HttpStatusCode.Created, newComment.toOutput())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ object EditComment {
|
|||||||
put<EditCommentRequest> {
|
put<EditCommentRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val commentOld = repo.findById(it.comment.id) ?: throw NotFoundException("Comment not found")
|
val commentOld = repo.findById(it.comment.id) ?: throw NotFoundException("Comment not found")
|
||||||
ac.assert { canUpdate(commentOld, citizenOrNull) }
|
ac.canUpdate(commentOld, citizenOrNull).assert()
|
||||||
|
|
||||||
call.receiveOrBadRequest<EditCommentRequest.Input>()
|
call.receiveOrBadRequest<EditCommentRequest.Input>()
|
||||||
.apply { validate().badRequestIfNotValid() }
|
.apply { validate().badRequestIfNotValid() }
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ object GetCommentChildren {
|
|||||||
it.limit
|
it.limit
|
||||||
)
|
)
|
||||||
|
|
||||||
ac.assert { canView(comments.result, citizenOrNull) }
|
ac.canView(comments.result, citizenOrNull).assert()
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object GetOneComment {
|
|||||||
fun Route.getOneComment(repo: CommentRepository, ac: CommentAccessControl) {
|
fun Route.getOneComment(repo: CommentRepository, ac: CommentAccessControl) {
|
||||||
get<CommentRequest> {
|
get<CommentRequest> {
|
||||||
val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found")
|
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(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ object CreateConstitution {
|
|||||||
post<PostConstitutionRequest> {
|
post<PostConstitutionRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
getNewConstitution(call.receiveOrBadRequest(), citizen).let {
|
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")
|
val c = repo.upsert(it) ?: error("Unable to create Constitution")
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.Created,
|
HttpStatusCode.Created,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ object FindConstitutions {
|
|||||||
get<FindConstitutionsRequest> {
|
get<FindConstitutionsRequest> {
|
||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
val constitutions = repo.find(it.page, it.limit, it.sort, it.direction, it.search)
|
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(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
constitutions.toOutput { c ->
|
constitutions.toOutput { c ->
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object GetConstitution {
|
|||||||
fun Route.getConstitution(ac: ConstitutionAccessControl, constitutionRepo: ConstitutionRepository) {
|
fun Route.getConstitution(ac: ConstitutionAccessControl, constitutionRepo: ConstitutionRepository) {
|
||||||
get<GetConstitutionRequest> {
|
get<GetConstitutionRequest> {
|
||||||
val constitution = constitutionRepo.findById(it.constitution.id) ?: throw NotFoundException("Unable to find constitution ${it.constitution.id}")
|
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(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
constitution.let { c ->
|
constitution.let { c ->
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object FollowArticle {
|
|||||||
post<ArticleFollowRequest> {
|
post<ArticleFollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
||||||
ac.assert { canCreate(follow, citizenOrNull) }
|
ac.canCreate(follow, citizenOrNull).assert()
|
||||||
repo.follow(follow)
|
repo.follow(follow)
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object GetFollowArticle {
|
|||||||
fun Route.getFollowArticle(repo: FollowArticleRepository, ac: FollowAccessControl) {
|
fun Route.getFollowArticle(repo: FollowArticleRepository, ac: FollowAccessControl) {
|
||||||
get<ArticleFollowRequest> {
|
get<ArticleFollowRequest> {
|
||||||
repo.findFollow(citizen, it.article)?.let { follow ->
|
repo.findFollow(citizen, it.article)?.let { follow ->
|
||||||
ac.assert { canView(follow, citizenOrNull) }
|
ac.canView(follow, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follow.toOutput()
|
follow.toOutput()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetMyFollowsArticle {
|
|||||||
get<CitizenFollowArticleRequest> {
|
get<CitizenFollowArticleRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follows = repo.findByCitizen(it.citizen)
|
val follows = repo.findByCitizen(it.citizen)
|
||||||
ac.assert { canView(follows.result, citizenOrNull) }
|
ac.canView(follows.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follows.toOutput { f ->
|
follows.toOutput { f ->
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object UnfollowArticle {
|
|||||||
delete<ArticleFollowRequest> {
|
delete<ArticleFollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
||||||
ac.assert { canDelete(follow, citizenOrNull) }
|
ac.canDelete(follow, citizenOrNull).assert()
|
||||||
repo.unfollow(follow)
|
repo.unfollow(follow)
|
||||||
call.respond(HttpStatusCode.NoContent)
|
call.respond(HttpStatusCode.NoContent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object FollowCitizen {
|
|||||||
post<CitizenFollowRequest> {
|
post<CitizenFollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen)
|
||||||
ac.assert { canCreate(follow, citizenOrNull) }
|
ac.canCreate(follow, citizenOrNull).assert()
|
||||||
repo.follow(follow)
|
repo.follow(follow)
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ object GetFollowCitizen {
|
|||||||
fun Route.getFollowCitizen(repo: FollowCitizenRepository, ac: FollowAccessControl) {
|
fun Route.getFollowCitizen(repo: FollowCitizenRepository, ac: FollowAccessControl) {
|
||||||
get<CitizenFollowRequest> {
|
get<CitizenFollowRequest> {
|
||||||
repo.findFollow(citizen, it.citizen)?.let { follow ->
|
repo.findFollow(citizen, it.citizen)?.let { follow ->
|
||||||
ac.assert { canView(follow, citizenOrNull) }
|
ac.canView(follow, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follow.toOutput()
|
follow.toOutput()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetMyFollowsCitizen {
|
|||||||
get<CitizenFollowCitizenRequest> {
|
get<CitizenFollowCitizenRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follows = repo.findByCitizen(it.citizen)
|
val follows = repo.findByCitizen(it.citizen)
|
||||||
ac.assert { canView(follows.result, citizenOrNull) }
|
ac.canView(follows.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follows.toOutput { f ->
|
follows.toOutput { f ->
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object UnfollowCitizen {
|
|||||||
delete<CitizenFollowRequest> {
|
delete<CitizenFollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.citizen, createdBy = this.citizen)
|
||||||
ac.assert { canDelete(follow, citizenOrNull) }
|
ac.canDelete(follow, citizenOrNull).assert()
|
||||||
repo.unfollow(follow)
|
repo.unfollow(follow)
|
||||||
call.respond(HttpStatusCode.NoContent)
|
call.respond(HttpStatusCode.NoContent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object FollowConstitution {
|
|||||||
post<ConstitutionFollowRequest> {
|
post<ConstitutionFollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen)
|
||||||
ac.assert { canCreate(follow, citizenOrNull) }
|
ac.canCreate(follow, citizenOrNull).assert()
|
||||||
repo.follow(follow)
|
repo.follow(follow)
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object GetFollowConstitution {
|
|||||||
fun Route.getFollowConstitution(repo: FollowConstitutionRepository, ac: FollowAccessControl) {
|
fun Route.getFollowConstitution(repo: FollowConstitutionRepository, ac: FollowAccessControl) {
|
||||||
get<ConstitutionFollowRequest> {
|
get<ConstitutionFollowRequest> {
|
||||||
repo.findFollow(citizen, it.constitution)?.let { follow ->
|
repo.findFollow(citizen, it.constitution)?.let { follow ->
|
||||||
ac.assert { canView(follow, citizenOrNull) }
|
ac.canView(follow, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follow.toOutput()
|
follow.toOutput()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object GetMyFollowsConstitution {
|
|||||||
get<CitizenFollowConstitutionRequest> {
|
get<CitizenFollowConstitutionRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follows = repo.findByCitizen(it.citizen)
|
val follows = repo.findByCitizen(it.citizen)
|
||||||
ac.assert { canView(follows.result, citizenOrNull) }
|
ac.canView(follows.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
follows.toOutput { f ->
|
follows.toOutput { f ->
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object UnfollowConstitution {
|
|||||||
delete<ConstitutionUnfollowRequest> {
|
delete<ConstitutionUnfollowRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen)
|
val follow = FollowForUpdate(target = it.constitution, createdBy = this.citizen)
|
||||||
ac.assert { canDelete(follow, citizenOrNull) }
|
ac.canDelete(follow, citizenOrNull).assert()
|
||||||
repo.unfollow(follow)
|
repo.unfollow(follow)
|
||||||
call.respond(HttpStatusCode.NoContent)
|
call.respond(HttpStatusCode.NoContent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ object GetCitizenOpinions {
|
|||||||
get<CitizenOpinions> {
|
get<CitizenOpinions> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val opinionsEntities: List<Opinion<ArticleRef>> = repo.findCitizenOpinionsByTargets(it.citizen, it.id)
|
val opinionsEntities: List<Opinion<ArticleRef>> = repo.findCitizenOpinionsByTargets(it.citizen, it.id)
|
||||||
ac.assert { canView(opinionsEntities, citizenOrNull) }
|
ac.canView(opinionsEntities, citizenOrNull).assert()
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ object GetMyOpinionsArticle {
|
|||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
|
|
||||||
val opinions: Paginated<Opinion<TargetRef>> = repo.findCitizenOpinions(citizen, it.page, it.limit)
|
val opinions: Paginated<Opinion<TargetRef>> = repo.findCitizenOpinions(citizen, it.page, it.limit)
|
||||||
ac.assert { canView(opinions.result, citizenOrNull) }
|
ac.canView(opinions.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
opinions.toOutput { it.toOutput() }
|
opinions.toOutput { it.toOutput() }
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ object GetOpinionChoice {
|
|||||||
fun Route.getOpinionChoice(ac: OpinionChoiceAccessControl, opinionChoiceRepository: OpinionChoiceRepository) {
|
fun Route.getOpinionChoice(ac: OpinionChoiceAccessControl, opinionChoiceRepository: OpinionChoiceRepository) {
|
||||||
get<OpinionChoiceRequest> {
|
get<OpinionChoiceRequest> {
|
||||||
val opinionChoice = opinionChoiceRepository.findOpinionChoiceById(it.opinionChoice.id) ?: throw NotFoundException("OpinionChoice ${it.opinionChoice.id} not found")
|
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(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ object GetOpinionChoices {
|
|||||||
fun Route.getOpinionChoices(repo: OpinionChoiceRepository, ac: OpinionChoiceAccessControl) {
|
fun Route.getOpinionChoices(repo: OpinionChoiceRepository, ac: OpinionChoiceAccessControl) {
|
||||||
get<OpinionChoicesRequest> {
|
get<OpinionChoicesRequest> {
|
||||||
val opinionChoices = repo.findOpinionsChoices(it.targets)
|
val opinionChoices = repo.findOpinionsChoices(it.targets)
|
||||||
ac.assert { canView(opinionChoices, citizenOrNull) }
|
ac.canView(opinionChoices, citizenOrNull).assert()
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ object OpinionArticle {
|
|||||||
createdBy = citizen
|
createdBy = citizen
|
||||||
)
|
)
|
||||||
}.let { opinions ->
|
}.let { opinions ->
|
||||||
ac.assert { canCreate(opinions, citizenOrNull) }
|
ac.canCreate(opinions, citizenOrNull).assert()
|
||||||
repo.updateOpinions(opinions)
|
repo.updateOpinions(opinions)
|
||||||
}.let {
|
}.let {
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ object GetCitizenVotes {
|
|||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
val votes = repo.findCitizenVotesByTargets(it.citizen, it.id)
|
val votes = repo.findCitizenVotesByTargets(it.citizen, it.id)
|
||||||
if (votes.isNotEmpty()) {
|
if (votes.isNotEmpty()) {
|
||||||
ac.assert { canView(votes, citizenOrNull) }
|
ac.canView(votes, citizenOrNull).assert()
|
||||||
}
|
}
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ object GetCitizenVotesOnArticle {
|
|||||||
it.validate().badRequestIfNotValid()
|
it.validate().badRequestIfNotValid()
|
||||||
|
|
||||||
val votes = repo.findByCitizen(it.citizen, it.page, it.limit)
|
val votes = repo.findByCitizen(it.citizen, it.page, it.limit)
|
||||||
ac.assert { canView(votes.result, citizenOrNull) }
|
ac.canView(votes.result, citizenOrNull).assert()
|
||||||
|
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ object PutVoteOnArticle {
|
|||||||
note = input.note,
|
note = input.note,
|
||||||
createdBy = this.citizen
|
createdBy = this.citizen
|
||||||
)
|
)
|
||||||
ac.assert { canCreate(vote, citizenOrNull) }
|
ac.canCreate(vote, citizenOrNull).assert()
|
||||||
val votes = repo.vote(vote)
|
val votes = repo.vote(vote)
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.Created,
|
HttpStatusCode.Created,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ object PutVoteOnComment {
|
|||||||
note = input.note,
|
note = input.note,
|
||||||
createdBy = this.citizen
|
createdBy = this.citizen
|
||||||
)
|
)
|
||||||
ac.assert { canCreate(vote, citizenOrNull) }
|
ac.canCreate(vote, citizenOrNull).assert()
|
||||||
val votes = voteCommentRepo.vote(vote)
|
val votes = voteCommentRepo.vote(vote)
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.Created,
|
HttpStatusCode.Created,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ object PutVoteOnConstitution {
|
|||||||
note = input.note,
|
note = input.note,
|
||||||
createdBy = this.citizen
|
createdBy = this.citizen
|
||||||
)
|
)
|
||||||
ac.assert { canCreate(vote, citizenOrNull) }
|
ac.canCreate(vote, citizenOrNull).assert()
|
||||||
repo.vote(vote)
|
repo.vote(vote)
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ object CreateWorkgroup {
|
|||||||
anonymous ?: true,
|
anonymous ?: true,
|
||||||
)
|
)
|
||||||
}.let { workgroup ->
|
}.let { workgroup ->
|
||||||
ac.assert { canCreate(workgroup, citizenOrNull) }
|
ac.canCreate(workgroup, citizenOrNull).assert()
|
||||||
repo.upsert(workgroup)
|
repo.upsert(workgroup)
|
||||||
}.let { w ->
|
}.let { w ->
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ object DeleteWorkgroup {
|
|||||||
delete<DeleteWorkgroupRequest> {
|
delete<DeleteWorkgroupRequest> {
|
||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||||
ac.assert { canDelete(workgroup, citizenOrNull) }
|
ac.canDelete(workgroup, citizenOrNull).assert()
|
||||||
repo.delete(workgroup)
|
repo.delete(workgroup)
|
||||||
call.respond(HttpStatusCode.NoContent)
|
call.respond(HttpStatusCode.NoContent)
|
||||||
} ?: call.respond(HttpStatusCode.NotFound)
|
} ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ object EditWorkgroup {
|
|||||||
deletedAt = old.deletedAt,
|
deletedAt = old.deletedAt,
|
||||||
members = old.members,
|
members = old.members,
|
||||||
).let { workgroup ->
|
).let { workgroup ->
|
||||||
ac.assert { canUpdate(workgroup, citizenOrNull) }
|
ac.canUpdate(workgroup, citizenOrNull).assert()
|
||||||
repo.upsert(workgroup)
|
repo.upsert(workgroup)
|
||||||
}.let {
|
}.let {
|
||||||
call.respond(HttpStatusCode.OK, it.toOutput())
|
call.respond(HttpStatusCode.OK, it.toOutput())
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ object GetWorkgroup {
|
|||||||
fun Route.getWorkgroup(repo: WorkgroupRepository, ac: WorkgroupAccessControl) {
|
fun Route.getWorkgroup(repo: WorkgroupRepository, ac: WorkgroupAccessControl) {
|
||||||
get<WorkgroupRequest> {
|
get<WorkgroupRequest> {
|
||||||
repo.findById(it.workgroup.id)?.let { workgroup ->
|
repo.findById(it.workgroup.id)?.let { workgroup ->
|
||||||
ac.assert { canView(workgroup, citizenOrNull) }
|
ac.canView(workgroup, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
workgroup.toOutput()
|
workgroup.toOutput()
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ object GetWorkgroups {
|
|||||||
it.search,
|
it.search,
|
||||||
WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members)
|
WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members)
|
||||||
)
|
)
|
||||||
ac.assert { canView(workgroups.result, citizenOrNull) }
|
ac.canView(workgroups.result, citizenOrNull).assert()
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.OK,
|
HttpStatusCode.OK,
|
||||||
workgroups.toOutput { it.toOutputListing() }
|
workgroups.toOutput { it.toOutputListing() }
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ object AddMemberToWorkgroup {
|
|||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||||
call.getMembersFromRequest().let { members ->
|
call.getMembersFromRequest().let { members ->
|
||||||
ac.assert { canAddMembers(workgroup, citizenOrNull) }
|
ac.canAddMembers(workgroup, citizenOrNull).assert()
|
||||||
repo.addMembers(workgroup, members)
|
repo.addMembers(workgroup, members)
|
||||||
}.let { members ->
|
}.let { members ->
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ object DeleteMembersOfWorkgroup {
|
|||||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||||
call.getMembersFromRequest()
|
call.getMembersFromRequest()
|
||||||
.let { members ->
|
.let { members ->
|
||||||
ac.assert { canRemoveMembers(workgroup, citizenOrNull) }
|
ac.canRemoveMembers(workgroup, citizenOrNull).assert()
|
||||||
repo.removeMembers(workgroup, members)
|
repo.removeMembers(workgroup, members)
|
||||||
}.let { members ->
|
}.let { members ->
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ object UpdateMemberOfWorkgroup {
|
|||||||
mustBeAuth()
|
mustBeAuth()
|
||||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||||
call.getMembersFromRequest().let { members ->
|
call.getMembersFromRequest().let { members ->
|
||||||
ac.assert { canUpdateMembers(workgroup, citizenOrNull) }
|
ac.canUpdateMembers(workgroup, citizenOrNull).assert()
|
||||||
repo.updateMembers(workgroup, members)
|
repo.updateMembers(workgroup, members)
|
||||||
}.let { members ->
|
}.let { members ->
|
||||||
call.respond(
|
call.respond(
|
||||||
|
|||||||
Reference in New Issue
Block a user