From 34fd51a6417d5f593edb681e5ae9b714bcd30b96 Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Mon, 5 Feb 2024 15:48:56 +0100 Subject: [PATCH] refactor: Admin groups cleanup (#3011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian Kleinbölting --- .../admin/GroupsResponderADMSpec.scala | 94 ++++++++----------- .../groupsmessages/GroupsMessagesADM.scala | 25 ----- .../responders/admin/GroupsResponderADM.scala | 91 ++++++------------ .../knora/webapi/routing/RouteUtilADM.scala | 1 - .../slice/admin/api/GroupsEndpoints.scala | 4 +- .../admin/api/GroupsEndpointsHandler.scala | 8 +- .../admin/api/service/GroupsRestService.scala | 12 ++- 7 files changed, 81 insertions(+), 154 deletions(-) diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala index c81f49e553..cef9e89d29 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala @@ -9,56 +9,43 @@ import org.apache.pekko.actor.Status.Failure import java.util.UUID -import dsp.errors.BadRequestException -import dsp.errors.DuplicateValueException -import dsp.errors.NotFoundException +import dsp.errors.* import dsp.valueobjects.Group.* import dsp.valueobjects.V2 import org.knora.webapi.* import org.knora.webapi.messages.admin.responder.groupsmessages.* -import org.knora.webapi.messages.admin.responder.usersmessages.GroupMembersGetResponseADM -import org.knora.webapi.messages.admin.responder.usersmessages.UserInformationTypeADM +import org.knora.webapi.messages.admin.responder.usersmessages.* import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2 -import org.knora.webapi.sharedtestdata.SharedTestDataADM +import org.knora.webapi.routing.UnsafeZioRun +import org.knora.webapi.sharedtestdata.SharedTestDataADM.* import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri import org.knora.webapi.util.MutableTestIri /** - * This spec is used to test the messages received by the [[org.knora.webapi.responders.admin.GroupsResponderADMSpec]] actor. + * This spec is used to test the messages received by the [[GroupsResponderADMSpec]] actor. */ class GroupsResponderADMSpec extends CoreSpec { - private val imagesProject = SharedTestDataADM.imagesProject - private val imagesReviewerGroup = SharedTestDataADM.imagesReviewerGroup - "The GroupsResponder " when { "asked about all groups" should { "return a list" in { - appActor ! GroupsGetRequestADM() - - val response = expectMsgType[GroupsGetResponseADM](timeout) - response.groups.nonEmpty should be(true) - response.groups.size should be(2) + val groups = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupsGetADM) + assert(groups.nonEmpty) + assert(groups.size == 2) } } "asked about a group identified by 'iri' " should { "return group info if the group is known " in { - appActor ! GroupGetRequestADM( - groupIri = imagesReviewerGroup.id - ) - - expectMsg(GroupGetResponseADM(imagesReviewerGroup)) + val group = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupGetADM(imagesReviewerGroup.id)) + assert(group.nonEmpty) + assert(group.map(_.id).contains(imagesReviewerGroup.id)) } - "return 'NotFoundException' when the group is unknown " in { - appActor ! GroupGetRequestADM( - groupIri = "http://rdfh.ch/groups/notexisting" - ) - - expectMsgPF(timeout) { case msg: Failure => - msg.cause.isInstanceOf[NotFoundException] should ===(true) - } + "return 'None' when the group is unknown " in { + val iri = "http://rdfh.ch/groups/notexisting" + val response = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupGetADM(iri)) + assert(response.isEmpty) } } @@ -80,16 +67,16 @@ class GroupsResponderADMSpec extends CoreSpec { ) ) .fold(e => throw e.head, v => v), - project = ProjectIri.unsafeFrom(SharedTestDataADM.imagesProjectIri), + project = ProjectIri.unsafeFrom(imagesProjectIri), status = GroupStatus.active, selfjoin = GroupSelfJoin.make(false).fold(e => throw e.head, v => v) ), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) - val received: GroupOperationResponseADM = expectMsgType[GroupOperationResponseADM](timeout) - val newGroupInfo = received.group + val received: GroupGetResponseADM = expectMsgType[GroupGetResponseADM](timeout) + val newGroupInfo = received.group newGroupInfo.name should equal("NewGroup") newGroupInfo.descriptions should equal( @@ -111,11 +98,11 @@ class GroupsResponderADMSpec extends CoreSpec { descriptions = GroupDescriptions .make(Seq(V2.StringLiteralV2(value = "NewGroupDescription", language = Some("en")))) .fold(e => throw e.head, v => v), - project = ProjectIri.unsafeFrom(SharedTestDataADM.imagesProjectIri), + project = ProjectIri.unsafeFrom(imagesProjectIri), status = GroupStatus.active, selfjoin = GroupSelfJoin.make(false).fold(e => throw e.head, v => v) ), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) @@ -137,12 +124,12 @@ class GroupsResponderADMSpec extends CoreSpec { .fold(e => throw e.head, v => v) ) ), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) - val received: GroupOperationResponseADM = expectMsgType[GroupOperationResponseADM](timeout) - val updatedGroupInfo = received.group + val received: GroupGetResponseADM = expectMsgType[GroupGetResponseADM](timeout) + val updatedGroupInfo = received.group updatedGroupInfo.name should equal("UpdatedGroupName") updatedGroupInfo.descriptions should equal( @@ -164,7 +151,7 @@ class GroupsResponderADMSpec extends CoreSpec { .fold(e => throw e.head, v => v) ) ), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) @@ -184,7 +171,7 @@ class GroupsResponderADMSpec extends CoreSpec { .fold(e => throw e.head, v => v) ) ), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) @@ -200,41 +187,38 @@ class GroupsResponderADMSpec extends CoreSpec { "used to query members" should { "return all members of a group identified by IRI" in { - appActor ! GroupMembersGetRequestADM( - groupIri = SharedTestDataADM.imagesReviewerGroup.id, - requestingUser = SharedTestDataADM.rootUser - ) - - val received: GroupMembersGetResponseADM = expectMsgType[GroupMembersGetResponseADM](timeout) + val iri = (GroupIri.unsafeFrom(imagesReviewerGroup.id)) + val received = + UnsafeZioRun.runOrThrow(GroupsResponderADM.groupMembersGetRequest(iri, rootUser)) received.members.map(_.id) should contain allElementsOf Seq( - SharedTestDataADM.multiuserUser.ofType(UserInformationTypeADM.Restricted), - SharedTestDataADM.imagesReviewerUser.ofType(UserInformationTypeADM.Restricted) + multiuserUser.ofType(UserInformationTypeADM.Restricted), + imagesReviewerUser.ofType(UserInformationTypeADM.Restricted) ).map(_.id) } "remove all members when group is deactivated" in { appActor ! GroupMembersGetRequestADM( - groupIri = SharedTestDataADM.imagesReviewerGroup.id, - requestingUser = SharedTestDataADM.rootUser + groupIri = imagesReviewerGroup.id, + requestingUser = rootUser ) val membersBeforeStatusChange: GroupMembersGetResponseADM = expectMsgType[GroupMembersGetResponseADM](timeout) membersBeforeStatusChange.members.size shouldBe 2 appActor ! GroupChangeStatusRequestADM( - groupIri = SharedTestDataADM.imagesReviewerGroup.id, + groupIri = imagesReviewerGroup.id, changeGroupRequest = ChangeGroupApiRequestADM(status = Some(false)), - requestingUser = SharedTestDataADM.imagesUser01, + requestingUser = imagesUser01, apiRequestID = UUID.randomUUID ) - val statusChangeResponse = expectMsgType[GroupOperationResponseADM](timeout) + val statusChangeResponse = expectMsgType[GroupGetResponseADM](timeout) statusChangeResponse.group.status shouldBe false appActor ! GroupMembersGetRequestADM( - groupIri = SharedTestDataADM.imagesReviewerGroup.id, - requestingUser = SharedTestDataADM.rootUser + groupIri = imagesReviewerGroup.id, + requestingUser = rootUser ) val noMembers: GroupMembersGetResponseADM = expectMsgType[GroupMembersGetResponseADM](timeout) @@ -244,7 +228,7 @@ class GroupsResponderADMSpec extends CoreSpec { "return 'NotFound' when the group IRI is unknown" in { appActor ! GroupMembersGetRequestADM( groupIri = "http://rdfh.ch/groups/notexisting", - requestingUser = SharedTestDataADM.rootUser + requestingUser = rootUser ) expectMsgPF(timeout) { case msg: Failure => diff --git a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/groupsmessages/GroupsMessagesADM.scala b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/groupsmessages/GroupsMessagesADM.scala index 158f3544d9..f7493b4f1f 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/groupsmessages/GroupsMessagesADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/groupsmessages/GroupsMessagesADM.scala @@ -18,7 +18,6 @@ import org.knora.webapi.IRI import org.knora.webapi.core.RelayedMessage import org.knora.webapi.messages.ResponderRequest.KnoraRequestADM import org.knora.webapi.messages.admin.responder.AdminKnoraResponseADM -import org.knora.webapi.messages.admin.responder.KnoraResponseADM import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectADM import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectsADMJsonProtocol import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2 @@ -104,11 +103,6 @@ sealed trait GroupsResponderRequestADM extends KnoraRequestADM with RelayedMessa */ case class GroupsGetADM() extends GroupsResponderRequestADM -/** - * Get all information about all groups. - */ -case class GroupsGetRequestADM() extends GroupsResponderRequestADM - /** * Get everything about a single group identified through its IRI. A successful response will be * an [[Option[GroupADM] ]], which will be `None` if the group was not found. @@ -117,14 +111,6 @@ case class GroupsGetRequestADM() extends GroupsResponderRequestADM */ case class GroupGetADM(groupIri: IRI) extends GroupsResponderRequestADM -/** - * Get everything about a single group identified through its IRI. The response will be a - * [[GroupGetResponseADM]], or an error if the group was not found. - * - * @param groupIri IRI of the group. - */ -case class GroupGetRequestADM(groupIri: IRI) extends GroupsResponderRequestADM - /** * Get everything about a multiple groups identified by their IRIs. The response will be a * [[Set[GroupGetResponseADM] ]], or an error if one or more groups was not found. @@ -205,15 +191,6 @@ case class GroupGetResponseADM(group: GroupADM) extends AdminKnoraResponseADM wi def toJsValue = groupResponseADMFormat.write(this) } -/** - * Represents an answer to a group creating/modifying operation. - * - * @param group the new group information of the created/modified group. - */ -case class GroupOperationResponseADM(group: GroupADM) extends KnoraResponseADM with GroupsADMJsonProtocol { - def toJsValue = groupOperationResponseADMFormat.write(this) -} - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Components of messages @@ -257,6 +234,4 @@ trait GroupsADMJsonProtocol extends SprayJsonSupport with DefaultJsonProtocol wi jsonFormat(CreateGroupApiRequestADM, "id", "name", "descriptions", "project", "status", "selfjoin") implicit val changeGroupApiRequestADMFormat: RootJsonFormat[ChangeGroupApiRequestADM] = jsonFormat(ChangeGroupApiRequestADM, "name", "descriptions", "status", "selfjoin") - implicit val groupOperationResponseADMFormat: RootJsonFormat[GroupOperationResponseADM] = - jsonFormat(GroupOperationResponseADM, "group") } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala index 8f91acb8b7..9f2499c4ff 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala @@ -41,10 +41,7 @@ import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.model.UserIri import org.knora.webapi.store.triplestore.api.TriplestoreService -import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Ask -import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Construct -import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Select -import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update +import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.* import org.knora.webapi.util.ZioHelper /** @@ -60,13 +57,6 @@ trait GroupsResponderADM { */ def groupsGetADM: Task[Seq[GroupADM]] - /** - * Gets all the groups and returns them as a [[GroupsGetResponseADM]]. - * - * @return all the groups as a [[GroupsGetResponseADM]]. - */ - def groupsGetRequestADM: Task[GroupsGetResponseADM] - /** * Gets the group with the given group IRI and returns the information as a [[GroupADM]]. * @@ -75,15 +65,6 @@ trait GroupsResponderADM { */ def groupGetADM(groupIri: IRI): Task[Option[GroupADM]] - /** - * Gets the group with the given group IRI and returns the information as a [[GroupGetResponseADM]]. - * - * @param groupIri the IRI of the group requested. - * @return information about the group as a [[GroupGetResponseADM]]. - */ - def groupGetRequestADM(groupIri: IRI): Task[GroupGetResponseADM] - final def groupGetRequest(iri: GroupIri): Task[GroupGetResponseADM] = groupGetRequestADM(iri.value) - /** * Gets the groups with the given IRIs and returns a set of [[GroupGetResponseADM]] objects. * @@ -110,13 +91,13 @@ trait GroupsResponderADM { * @param createRequest the create request information. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]] + * @return a [[GroupGetResponseADM]] */ def createGroupADM( createRequest: GroupCreatePayloadADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] + ): Task[GroupGetResponseADM] /** * Change group's basic information. @@ -125,14 +106,14 @@ trait GroupsResponderADM { * @param changeGroupRequest the change request. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]]. + * @return a [[GroupGetResponseADM]]. */ def changeGroupBasicInformationRequestADM( groupIri: IRI, changeGroupRequest: GroupUpdatePayloadADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] + ): Task[GroupGetResponseADM] /** * Change group's basic information. @@ -141,14 +122,14 @@ trait GroupsResponderADM { * @param changeGroupRequest the change request. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]]. + * @return a [[GroupGetResponseADM]]. */ def changeGroupStatusRequestADM( groupIri: IRI, changeGroupRequest: ChangeGroupApiRequestADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] + ): Task[GroupGetResponseADM] } final case class GroupsResponderADMLive( @@ -171,10 +152,8 @@ final case class GroupsResponderADMLive( */ def handle(msg: ResponderRequest): Task[Any] = msg match { case _: GroupsGetADM => groupsGetADM - case _: GroupsGetRequestADM => groupsGetRequestADM case r: GroupGetADM => groupGetADM(r.groupIri) case r: MultipleGroupsGetRequestADM => multipleGroupsGetRequestADM(r.groupIris) - case r: GroupGetRequestADM => groupGetRequestADM(r.groupIri) case r: GroupMembersGetRequestADM => groupMembersGetRequestADM(r.groupIri, r.requestingUser) case r: GroupCreateRequestADM => createGroupADM(r.createRequest, r.requestingUser, r.apiRequestID) case r: GroupChangeRequestADM => @@ -235,13 +214,6 @@ final case class GroupsResponderADMLive( private def findProjectById(id: ProjectIdentifierADM) = messageRelay.ask[Option[ProjectADM]](ProjectGetADM(id)) - /** - * Gets all the groups and returns them as a [[GroupsGetResponseADM]]. - * - * @return all the groups as a [[GroupsGetResponseADM]]. - */ - override def groupsGetRequestADM: Task[GroupsGetResponseADM] = groupsGetADM.map(GroupsGetResponseADM) - /** * Gets the group with the given group IRI and returns the information as a [[GroupADM]]. * @@ -256,17 +228,6 @@ final case class GroupsResponderADMLive( } yield maybeGroup } - /** - * Gets the group with the given group IRI and returns the information as a [[GroupGetResponseADM]]. - * - * @param groupIri the IRI of the group requested. - * @return information about the group as a [[GroupGetResponseADM]]. - */ - override def groupGetRequestADM(groupIri: IRI): Task[GroupGetResponseADM] = - groupGetADM(groupIri) - .flatMap(ZIO.fromOption(_)) - .mapBoth(_ => NotFoundException(s"Group <$groupIri> not found."), GroupGetResponseADM) - /** * Gets the groups with the given IRIs and returns a set of [[GroupGetResponseADM]] objects. * @@ -274,7 +235,11 @@ final case class GroupsResponderADMLive( * @return information about the group as a set of [[GroupGetResponseADM]] objects. */ override def multipleGroupsGetRequestADM(groupIris: Set[IRI]): Task[Set[GroupGetResponseADM]] = - ZioHelper.sequence(groupIris.map(groupGetRequestADM)) + ZioHelper.sequence(groupIris.map { iri => + groupGetADM(iri) + .flatMap(ZIO.fromOption(_)) + .mapBoth(_ => NotFoundException(s"Group <$iri> not found."), GroupGetResponseADM) + }) /** * Gets the members with the given group IRI and returns the information as a sequence of [[User]]. @@ -342,17 +307,17 @@ final case class GroupsResponderADMLive( * @param createRequest the create request information. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]] + * @return a [[GroupGetResponseADM]] */ override def createGroupADM( createRequest: GroupCreatePayloadADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] = { + ): Task[GroupGetResponseADM] = { def createGroupTask( createRequest: GroupCreatePayloadADM, requestingUser: User - ): Task[GroupOperationResponseADM] = + ): Task[GroupGetResponseADM] = for { /* check if the requesting user is allowed to create group */ _ <- ZIO @@ -408,7 +373,7 @@ final case class GroupsResponderADMLive( .flatMap(ZIO.fromOption(_)) .orElseFail(UpdateNotPerformedException(s"Group was not created. Please report this as a possible bug.")) - } yield GroupOperationResponseADM(createdGroup) + } yield GroupGetResponseADM(createdGroup) val task = createGroupTask(createRequest, requestingUser) IriLocker.runWithIriLock(apiRequestID, GROUPS_GLOBAL_LOCK_IRI, task) @@ -421,14 +386,14 @@ final case class GroupsResponderADMLive( * @param changeGroupRequest the change request. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]]. + * @return a [[GroupGetResponseADM]]. */ override def changeGroupBasicInformationRequestADM( groupIri: IRI, changeGroupRequest: GroupUpdatePayloadADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] = { + ): Task[GroupGetResponseADM] = { /** * The actual change group task run with an IRI lock. @@ -437,7 +402,7 @@ final case class GroupsResponderADMLive( groupIri: IRI, changeGroupRequest: GroupUpdatePayloadADM, requestingUser: User - ): Task[GroupOperationResponseADM] = + ): Task[GroupGetResponseADM] = for { // check if necessary information is present _ <- ZIO @@ -479,14 +444,14 @@ final case class GroupsResponderADMLive( * @param changeGroupRequest the change request. * @param requestingUser the user making the request. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]]. + * @return a [[GroupGetResponseADM]]. */ override def changeGroupStatusRequestADM( groupIri: IRI, changeGroupRequest: ChangeGroupApiRequestADM, requestingUser: User, apiRequestID: UUID - ): Task[GroupOperationResponseADM] = { + ): Task[GroupGetResponseADM] = { /** * The actual change group task run with an IRI lock. @@ -495,7 +460,7 @@ final case class GroupsResponderADMLive( groupIri: IRI, changeGroupRequest: ChangeGroupApiRequestADM, requestingUser: User - ): Task[GroupOperationResponseADM] = + ): Task[GroupGetResponseADM] = for { // check if necessary information is present @@ -543,7 +508,7 @@ final case class GroupsResponderADMLive( * * @param groupIri the IRI of the group we are updating. * @param groupUpdatePayload the payload holding the information which we want to update. - * @return a [[GroupOperationResponseADM]] + * @return a [[GroupGetResponseADM]] */ private def updateGroupADM(groupIri: IRI, groupUpdatePayload: GroupUpdatePayloadADM) = for { @@ -595,7 +560,7 @@ final case class GroupsResponderADMLive( groupGetADM(groupIri) .flatMap(ZIO.fromOption(_)) .orElseFail(UpdateNotPerformedException("Group was not updated. Please report this as a possible bug.")) - } yield GroupOperationResponseADM(updatedGroup) + } yield GroupGetResponseADM(updatedGroup) //////////////////// // Helper Methods // @@ -617,16 +582,16 @@ final case class GroupsResponderADMLive( * * @param changedGroup the group with the new status. * @param apiRequestID the unique request ID. - * @return a [[GroupOperationResponseADM]] + * @return a [[GroupGetResponseADM]] */ private def removeGroupMembersIfNecessary( changedGroup: GroupADM, apiRequestID: UUID - ): Task[GroupOperationResponseADM] = + ): Task[GroupGetResponseADM] = if (changedGroup.status) { // group active. no need to remove members. logger.debug("removeGroupMembersIfNecessary - group active. no need to remove members.") - ZIO.succeed(GroupOperationResponseADM(changedGroup)) + ZIO.succeed(GroupGetResponseADM(changedGroup)) } else { // group deactivated. need to remove members. logger.debug("removeGroupMembersIfNecessary - group deactivated. need to remove members.") @@ -652,7 +617,7 @@ final case class GroupsResponderADMLive( _ <- ZioHelper.sequence(seqOfFutures) - } yield GroupOperationResponseADM(group = changedGroup) + } yield GroupGetResponseADM(group = changedGroup) } } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/RouteUtilADM.scala b/webapi/src/main/scala/org/knora/webapi/routing/RouteUtilADM.scala index ab0632f3db..0761bab518 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/RouteUtilADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/RouteUtilADM.scala @@ -75,7 +75,6 @@ object RouteUtilADM { case GroupGetResponseADM(group) => GroupGetResponseADM(groupAsExternalRepresentation(group)) case GroupMembersGetResponseADM(members) => GroupMembersGetResponseADM(members.map(userAsExternalRepresentation)) - case GroupOperationResponseADM(group) => GroupOperationResponseADM(groupAsExternalRepresentation(group)) case UsersGetResponseADM(users) => UsersGetResponseADM(users.map(userAsExternalRepresentation)) case UserResponseADM(user) => UserResponseADM(userAsExternalRepresentation(user)) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpoints.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpoints.scala index fde7bb1347..a45eb74d35 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpoints.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpoints.scala @@ -25,7 +25,7 @@ final case class GroupsEndpoints(baseEndpoints: BaseEndpoints) { .out(sprayJsonBody[GroupsGetResponseADM]) .description("Returns all groups.") - val getGroup = baseEndpoints.publicEndpoint.get + val getGroupByIri = baseEndpoints.publicEndpoint.get .in(base / groupIri) .out(sprayJsonBody[GroupGetResponseADM]) .description("Returns a single group identified by IRI.") @@ -37,7 +37,7 @@ final case class GroupsEndpoints(baseEndpoints: BaseEndpoints) { private val securedEndpoins = Seq(getGroupMembers).map(_.endpoint) - val endpoints: Seq[AnyEndpoint] = (Seq(getGroups, getGroup) ++ securedEndpoins) + val endpoints: Seq[AnyEndpoint] = (Seq(getGroups, getGroupByIri) ++ securedEndpoins) .map(_.tag("Admin Groups")) } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpointsHandler.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpointsHandler.scala index add6bb0cdc..79e916c5a9 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpointsHandler.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/GroupsEndpointsHandler.scala @@ -24,10 +24,10 @@ case class GroupsEndpointsHandler( (_: Unit) => restService.getGroups ) - private val getGroupHandler = + private val getGroupByIriHandler = PublicEndpointHandler( - endpoints.getGroup, - (iri: GroupIri) => restService.getGroup(iri) + endpoints.getGroupByIri, + (iri: GroupIri) => restService.getGroupByIri(iri) ) private val getGroupMembersHandler = @@ -38,7 +38,7 @@ case class GroupsEndpointsHandler( private val securedHandlers = List(getGroupMembersHandler).map(mapper.mapSecuredEndpointHandler(_)) - val allHandlers = List(getGroupsHandler, getGroupHandler).map(mapper.mapPublicEndpointHandler(_)) + val allHandlers = List(getGroupsHandler, getGroupByIriHandler).map(mapper.mapPublicEndpointHandler(_)) ++ securedHandlers } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala index 838b9c8631..4fbf532098 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala @@ -8,6 +8,7 @@ package org.knora.webapi.slice.admin.api.service import zio.* import zio.macros.accessible +import dsp.errors.NotFoundException import org.knora.webapi.messages.admin.responder.groupsmessages.* import org.knora.webapi.messages.admin.responder.usersmessages.GroupMembersGetResponseADM import org.knora.webapi.responders.admin.GroupsResponderADM @@ -18,7 +19,7 @@ import org.knora.webapi.slice.common.api.KnoraResponseRenderer @accessible trait GroupsRestService { def getGroups: Task[GroupsGetResponseADM] - def getGroup(iri: GroupIri): Task[GroupGetResponseADM] + def getGroupByIri(iri: GroupIri): Task[GroupGetResponseADM] def getGroupMembers(iri: GroupIri, user: User): Task[GroupMembersGetResponseADM] } @@ -27,13 +28,16 @@ final case class GroupsRestServiceLive( format: KnoraResponseRenderer ) extends GroupsRestService { override def getGroups: Task[GroupsGetResponseADM] = for { - internal <- responder.groupsGetRequestADM + internal <- responder.groupsGetADM.map(GroupsGetResponseADM) external <- format.toExternal(internal) } yield external - override def getGroup(iri: GroupIri): Task[GroupGetResponseADM] = + override def getGroupByIri(iri: GroupIri): Task[GroupGetResponseADM] = for { - internal <- responder.groupGetRequest(iri) + internal <- responder + .groupGetADM(iri.value) + .someOrFail(NotFoundException(s"Group <${iri.value}> not found.")) + .map(GroupGetResponseADM.apply) external <- format.toExternal(internal) } yield external