Skip to content

Commit

Permalink
refactor: Fix checks order in Group update method (DEV-3292) (#3198)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 committed Apr 19, 2024
1 parent 3e08df7 commit bc22ade
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -43,7 +43,7 @@ class GroupsResponderADMSpec extends CoreSpec {
}
}

"asked about a group identified by 'iri' " should {
"asked about a group identified by IRI " should {
"return group info if the group is known " in {
val iri = GroupIri.unsafeFrom(imagesReviewerGroup.id)
val response = UnsafeZioRun.runOrThrow(groupService(_.findById(iri)))
Expand Down Expand Up @@ -152,7 +152,7 @@ class GroupsResponderADMSpec extends CoreSpec {
group.selfjoin should equal(false)
}

"return 'NotFoundException' if a not-existing group IRI is submitted during update" in {
"return 'ForbiddenException' if a not-existing group IRI is submitted during update" in {
val groupIri = "http://rdfh.ch/groups/0000/notexisting"
val exit = UnsafeZioRun.run(
groupRestService(
Expand All @@ -171,9 +171,9 @@ class GroupsResponderADMSpec extends CoreSpec {
),
),
)
assertFailsWithA[NotFoundException](
assertFailsWithA[ForbiddenException](
exit,
s"Group <$groupIri> not found.",
s"Group with IRI '$groupIri' not found",
)
}

Expand Down
Expand Up @@ -62,13 +62,13 @@ final case class GroupRestService(

def putGroup(iri: GroupIri, request: GroupUpdateRequest, user: User): Task[GroupGetResponseADM] =
for {
_ <- auth.ensureSystemAdminOrProjectAdminOfGroup(user, iri)
_ <- ZIO
.fail(BadRequestException("No data would be changed. Aborting update request."))
.when(List(request.name, request.descriptions, request.status, request.selfjoin).flatten.isEmpty)
groupToUpdate <- groupService
.findById(iri)
.someOrFail(NotFoundException(s"Group <${iri.value}> not found."))
_ <- auth.ensureSystemAdminOrProjectAdminOfGroup(user, iri)
internal <- groupService.updateGroup(groupToUpdate, request).map(GroupGetResponseADM.apply)
external <- format.toExternalADM(internal)
} yield external
Expand Down

0 comments on commit bc22ade

Please sign in to comment.