From 5a3374a87838849783d2db577c7dede16cf7f270 Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Thu, 11 Apr 2024 08:27:53 +0200 Subject: [PATCH] refactor: Align rest services naming & make layers more readable (#3179) --- .../org/knora/webapi/core/LayersTest.scala | 71 +++++++++++--- .../PermissionsMessagesADMSpec.scala | 34 +++---- .../admin/GroupsResponderADMSpec.scala | 4 +- .../admin/PermissionsResponderSpec.scala | 94 +++++++++---------- ...ceSpec.scala => UserRestServiceSpec.scala} | 92 +++++++++--------- .../org/knora/webapi/core/LayersLive.scala | 74 ++++++++++++--- .../slice/admin/api/AdminApiModule.scala | 14 +-- .../admin/api/GroupsEndpointsHandler.scala | 4 +- .../api/PermissionsEndpointsHandlers.scala | 4 +- .../admin/api/UsersEndpointsHandler.scala | 4 +- ...stService.scala => GroupRestService.scala} | 6 +- ...vice.scala => PermissionRestService.scala} | 10 +- ...estService.scala => UserRestService.scala} | 6 +- 13 files changed, 253 insertions(+), 164 deletions(-) rename integration/src/test/scala/org/knora/webapi/responders/admin/{UsersRestServiceSpec.scala => UserRestServiceSpec.scala} (85%) rename webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/{GroupsRestService.scala => GroupRestService.scala} (96%) rename webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/{PermissionsRestService.scala => PermissionRestService.scala} (96%) rename webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/{UsersRestService.scala => UserRestService.scala} (99%) diff --git a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala index e838ef346e..7445f6f91c 100644 --- a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala +++ b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala @@ -34,10 +34,10 @@ import org.knora.webapi.routing._ import org.knora.webapi.slice.admin.AdminModule import org.knora.webapi.slice.admin.api.AdminApiModule import org.knora.webapi.slice.admin.api._ -import org.knora.webapi.slice.admin.api.service.GroupsRestService -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.GroupRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.api.service.ProjectRestService -import org.knora.webapi.slice.admin.api.service.UsersRestService +import org.knora.webapi.slice.admin.api.service.UserRestService import org.knora.webapi.slice.admin.domain.service.ProjectExportStorageService import org.knora.webapi.slice.admin.domain.service._ import org.knora.webapi.slice.common.api._ @@ -86,16 +86,61 @@ object LayersTest { pekko.actor.ActorSystem & AppConfigurationsTest & JwtConfig & WhichSipiService type CommonR = - ApiRoutes & AdminApiEndpoints & ApiV2Endpoints & AppRouter & AssetPermissionsResponder & Authenticator & - AuthorizationRestService & CacheServiceRequestMessageHandler & CardinalityHandler & ConstructResponseUtilV2 & - DspIngestClient & GravsearchTypeInspectionRunner & GroupsResponderADM & GroupsRestService & GroupService & - HttpServer & IIIFRequestMessageHandler & InferenceOptimizationService & IriConverter & KnoraUserToUserConverter & ListsResponder & - ListsResponderV2 & MessageRelay & OntologyCache & OntologyHelpers & OntologyInferencer & OntologyRepo & - OntologyResponderV2 & PermissionUtilADM & PermissionsResponder & PermissionsRestService & ProjectExportService & - ProjectExportStorageService & ProjectImportService & ProjectService & ProjectRestService & QueryTraverser & - RepositoryUpdater & ResourceUtilV2 & ResourcesResponderV2 & RestCardinalityService & SearchApiRoutes & - SearchResponderV2 & StandoffResponderV2 & StandoffTagUtilV2 & State & TestClientService & TriplestoreService & - UserService & UsersResponder & UsersRestService & ValuesResponderV2 & JwtService & SipiService & StringFormatter + AdminApiEndpoints & + ApiRoutes & + ApiV2Endpoints & + AppRouter & + AssetPermissionsResponder & + Authenticator & + AuthorizationRestService & + CacheServiceRequestMessageHandler & + CardinalityHandler & + ConstructResponseUtilV2 & + DspIngestClient & + GravsearchTypeInspectionRunner & + GroupRestService & + GroupService & + GroupsResponderADM & + HttpServer & + IIIFRequestMessageHandler & + InferenceOptimizationService & + IriConverter & + JwtService & + KnoraUserToUserConverter & + ListsResponder & + ListsResponderV2 & + MessageRelay & + OntologyCache & + OntologyHelpers & + OntologyInferencer & + OntologyRepo & + OntologyResponderV2 & + PermissionRestService & + PermissionUtilADM & + PermissionsResponder & + ProjectExportService & + ProjectExportStorageService & + ProjectImportService & + ProjectRestService & + ProjectService & + QueryTraverser & + RepositoryUpdater & + ResourceUtilV2 & + ResourcesResponderV2 & + RestCardinalityService & + SearchApiRoutes & + SearchResponderV2 & + SipiService & + StandoffResponderV2 & + StandoffTagUtilV2 & + State & + StringFormatter & + TestClientService & + TriplestoreService & + UserRestService & + UserService & + UsersResponder & + ValuesResponderV2 private val commonLayersForAllIntegrationTests = ZLayer.makeSome[CommonR0, CommonR]( diff --git a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala index 838f82766c..00018f9fbd 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala @@ -17,7 +17,7 @@ import org.knora.webapi.routing.UnsafeZioRun import org.knora.webapi.sharedtestdata.SharedOntologyTestDataADM._ import org.knora.webapi.sharedtestdata.SharedTestDataADM2._ import org.knora.webapi.sharedtestdata._ -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.domain.model.Permission import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA @@ -45,7 +45,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "Administrative Permission Create Requests" should { "return 'BadRequest' if the supplied project IRI for AdministrativePermissionCreateRequestADM is not valid" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = "invalid-project-IRI", forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value, @@ -60,7 +60,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the supplied group IRI for AdministrativePermissionCreateRequestADM is not valid" in { val groupIri = "invalid-group-iri" val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = groupIri, @@ -75,7 +75,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the supplied permission IRI for AdministrativePermissionCreateRequestADM is not valid" in { val permissionIri = "invalid-permission-IRI" val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( id = Some(permissionIri), forProject = SharedTestDataADM.imagesProjectIri, @@ -98,7 +98,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { ), ) val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value, @@ -116,7 +116,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the a permissions supplied for AdministrativePermissionCreateRequestADM had invalid name" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value, @@ -130,7 +130,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'ForbiddenException' if the user requesting AdministrativePermissionCreateRequestADM is not system or project admin" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createAdministrativePermission( + PermissionRestService.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value, @@ -393,7 +393,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the supplied project IRI for DefaultObjectAccessPermissionCreateRequestADM is not valid" in { val forProject = "invalid-project-IRI" val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = forProject, forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value), @@ -410,7 +410,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the supplied group IRI for DefaultObjectAccessPermissionCreateRequestADM is not valid" in { val groupIri = "invalid-group-iri" val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = Some(groupIri), @@ -427,7 +427,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the supplied custom permission IRI for DefaultObjectAccessPermissionCreateRequestADM is not valid" in { val permissionIri = "invalid-permission-IRI" val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( id = Some(permissionIri), forProject = SharedTestDataADM.imagesProjectIri, @@ -444,7 +444,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the no permissions supplied for DefaultObjectAccessPermissionCreateRequestADM" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM.imagesProjectIri, forGroup = Some(SharedTestDataADM.thingSearcherGroup.id), @@ -546,7 +546,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'ForbiddenException' if the user requesting DefaultObjectAccessPermissionCreateRequestADM is not system or project Admin" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM.anythingProjectIri, forGroup = Some(SharedTestDataADM.thingSearcherGroup.id), @@ -564,7 +564,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the both group and resource class are supplied for DefaultObjectAccessPermissionCreateRequestADM" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = anythingProjectIri, forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value), @@ -581,7 +581,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if the both group and property are supplied for DefaultObjectAccessPermissionCreateRequestADM" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = anythingProjectIri, forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value), @@ -598,7 +598,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if propertyIri supplied for DefaultObjectAccessPermissionCreateRequestADM is not valid" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = anythingProjectIri, forProperty = Some(SharedTestDataADM.customValueIRI), @@ -614,7 +614,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if resourceClassIri supplied for DefaultObjectAccessPermissionCreateRequestADM is not valid" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = anythingProjectIri, forResourceClass = Some(ANYTHING_THING_RESOURCE_CLASS_LocalHost), @@ -633,7 +633,7 @@ class PermissionsMessagesADMSpec extends CoreSpec { "return 'BadRequest' if neither a group, nor a resource class, nor a property is supplied for DefaultObjectAccessPermissionCreateRequestADM" in { val exit = UnsafeZioRun.run( - PermissionsRestService.createDefaultObjectAccessPermission( + PermissionRestService.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = anythingProjectIri, hasPermissions = Set( 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 1310d41f6b..8a05715cd6 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 @@ -18,7 +18,7 @@ import org.knora.webapi.sharedtestdata.SharedTestDataADM._ import org.knora.webapi.slice.admin.api.GroupsRequests.GroupCreateRequest import org.knora.webapi.slice.admin.api.GroupsRequests.GroupStatusUpdateRequest import org.knora.webapi.slice.admin.api.GroupsRequests.GroupUpdateRequest -import org.knora.webapi.slice.admin.api.service.GroupsRestService +import org.knora.webapi.slice.admin.api.service.GroupRestService import org.knora.webapi.slice.admin.domain.model.GroupDescriptions import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.admin.domain.model.GroupName @@ -33,7 +33,7 @@ import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA * This spec is used to test the messages received by the [[GroupsResponderADMSpec]] actor. */ class GroupsResponderADMSpec extends CoreSpec { - private val groupRestService = ZIO.serviceWithZIO[GroupsRestService] + private val groupRestService = ZIO.serviceWithZIO[GroupRestService] private val groupService = ZIO.serviceWithZIO[GroupService] "The GroupsResponder " when { diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderSpec.scala index e0972249fd..ce3b693127 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderSpec.scala @@ -31,7 +31,7 @@ import org.knora.webapi.sharedtestdata.SharedTestDataADM.imagesUser02 import org.knora.webapi.sharedtestdata.SharedTestDataADM.incunabulaMemberUser import org.knora.webapi.sharedtestdata.SharedTestDataADM.normalUser import org.knora.webapi.sharedtestdata.SharedTestDataADM2 -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri import org.knora.webapi.slice.admin.domain.model.Permission @@ -58,8 +58,8 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { RdfDataObject(path = "test_data/project_data/anything-data.ttl", name = "http://www.knora.org/data/0001/anything"), ) - private val PermissionsRestService = ZIO.serviceWithZIO[PermissionsRestService] - private val PermissionsResponder = ZIO.serviceWithZIO[PermissionsResponder] + private val permissionRestService = ZIO.serviceWithZIO[PermissionRestService] + private val permissionsResponder = ZIO.serviceWithZIO[PermissionsResponder] "The PermissionsResponderADM" when { @@ -67,7 +67,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "return all Permission.Administrative for project" in { val result = UnsafeZioRun.runOrThrow( - PermissionsResponder(_.getPermissionsApByProjectIri(imagesProjectIri)), + permissionsResponder(_.getPermissionsApByProjectIri(imagesProjectIri)), ) result shouldEqual AdministrativePermissionsForProjectGetResponseADM( Seq(perm002_a1.p, perm002_a3.p, perm002_a2.p), @@ -76,7 +76,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "return Permission.Administrative for project and group" in { val result = UnsafeZioRun.runOrThrow( - PermissionsRestService( + permissionRestService( _.getPermissionsApByProjectAndGroupIri( ProjectIri.unsafeFrom(imagesProjectIri), KnoraGroupRepo.builtIn.ProjectMember.id, @@ -115,7 +115,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "asked to create an administrative permission" should { "fail and return a 'DuplicateValueException' when permission for project and group combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( forProject = imagesProjectIri, @@ -139,7 +139,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "create and return an administrative permission with a custom IRI" in { val customIri = "http://rdfh.ch/permissions/0001/24RD7QcoTKqEJKrDBE885Q" val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( id = Some(customIri), @@ -168,7 +168,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val expectedHasPermissions = Set(PermissionADM.from(Permission.Administrative.ProjectResourceCreateAll)) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createAdministrativePermission( CreateAdministrativePermissionAPIRequestADM( id = Some(customIri), @@ -232,7 +232,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "return all DefaultObjectAccessPermissions for project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.getPermissionsDaopByProjectIri( ProjectIri.unsafeFrom(imagesProjectIri), ), @@ -323,7 +323,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and group" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM.anythingProjectIri, @@ -350,7 +350,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and group with custom IRI" in { val customIri = "http://rdfh.ch/permissions/0001/4PnSvolsTEa86KJ2EG76SQ" val received = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( createRequest = CreateDefaultObjectAccessPermissionAPIRequestADM( id = Some(customIri), @@ -379,7 +379,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and resource class" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = imagesProjectIri, @@ -405,7 +405,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and property" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = imagesProjectIri, @@ -431,7 +431,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and group combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM2.incunabulaProjectIri, @@ -458,7 +458,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and resourceClass combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM2.incunabulaProjectIri, @@ -485,7 +485,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and property combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM2.incunabulaProjectIri, @@ -511,7 +511,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project, resource class, and property combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = SharedTestDataADM2.incunabulaProjectIri, @@ -547,7 +547,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = imagesProjectIri, @@ -584,7 +584,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.createDefaultObjectAccessPermission( CreateDefaultObjectAccessPermissionAPIRequestADM( forProject = imagesProjectIri, @@ -606,7 +606,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "return all permissions for 'image' project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.getPermissionsByProjectIri(ProjectIri.unsafeFrom(imagesProjectIri)), ), ) @@ -615,7 +615,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "return all permissions for 'incunabula' project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.getPermissionsByProjectIri( ProjectIri.unsafeFrom(SharedTestDataADM.incunabulaProjectIri), ), @@ -825,7 +825,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), ), ) @@ -838,7 +838,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionsGroup(permissionIri, newGroupIri, imagesUser02, UUID.randomUUID()), ), ) @@ -852,7 +852,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), ), ) @@ -865,7 +865,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/sdHG20U6RoiwSu8MeAT1vA") val newGroupIri = GroupIri.unsafeFrom(KnoraGroupRepo.builtIn.ProjectMember.id.value) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), ), ) @@ -879,7 +879,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/0000/KMjKHCNQQmC4uHPQwlEexw") val newGroupIri = GroupIri.unsafeFrom(KnoraGroupRepo.builtIn.ProjectMember.id.value) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), ), ) @@ -896,7 +896,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val hasPermissions = NonEmptyChunk(PermissionADM.from(Permission.Administrative.ProjectResourceCreateAll)) val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -916,7 +916,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ" val hasPermissions = NonEmptyChunk(PermissionADM.from(Permission.Administrative.ProjectResourceCreateAll)) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -942,7 +942,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -966,7 +966,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1001,7 +1001,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1033,7 +1033,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1059,7 +1059,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ), ) val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1086,7 +1086,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1114,7 +1114,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1141,7 +1141,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, @@ -1162,7 +1162,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), @@ -1182,7 +1182,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), @@ -1200,7 +1200,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/Q3OMWyFqStGYK8EXmC7KhQ" val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), @@ -1219,7 +1219,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/OySsjGn8QSqIpXUiSYnSSQ" val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), @@ -1241,7 +1241,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val propertyIri = SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), @@ -1261,7 +1261,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val propertyIri = OntologyConstants.KnoraBase.TextFileValue val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), @@ -1280,7 +1280,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val propertyIri = OntologyConstants.KnoraBase.TextFileValue val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), @@ -1299,7 +1299,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { val propertyIri = SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder( + permissionsResponder( _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), @@ -1319,7 +1319,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "throw BadRequestException if given IRI is not a permission IRI" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/RkVssk8XRVO9hZ3VR5IpLA") val exit = UnsafeZioRun.run( - PermissionsResponder(_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), + permissionsResponder(_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), ) assertFailsWithA[NotFoundException]( exit, @@ -1330,7 +1330,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "throw ForbiddenException if user requesting PermissionDeleteResponseADM is not a system or project admin" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val exit = UnsafeZioRun.run( - PermissionsResponder( + permissionsResponder( _.deletePermission(permissionIri, SharedTestDataADM.imagesUser02, UUID.randomUUID()), ), ) @@ -1343,7 +1343,7 @@ class PermissionsResponderSpec extends CoreSpec with ImplicitSender { "erase a permission with given IRI" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponder(_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), + permissionsResponder(_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), ) assert(actual.deleted) } diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/UserRestServiceSpec.scala similarity index 85% rename from integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala rename to integration/src/test/scala/org/knora/webapi/responders/admin/UserRestServiceSpec.scala index eb0f1148b6..aca6d2c595 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/UserRestServiceSpec.scala @@ -29,7 +29,7 @@ import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.StatusChangeRequ import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.SystemAdminChangeRequest import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.UserCreateRequest import org.knora.webapi.slice.admin.api.service.ProjectRestService -import org.knora.webapi.slice.admin.api.service.UsersRestService +import org.knora.webapi.slice.admin.api.service.UserRestService import org.knora.webapi.slice.admin.domain.model.Group import org.knora.webapi.slice.admin.domain.model.Username import org.knora.webapi.slice.admin.domain.model._ @@ -37,7 +37,7 @@ import org.knora.webapi.slice.admin.domain.service.KnoraUserRepo import org.knora.webapi.slice.admin.domain.service.UserService import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA -class UsersRestServiceSpec extends CoreSpec with ImplicitSender { +class UserRestServiceSpec extends CoreSpec with ImplicitSender { private val rootUser = SharedTestDataADM.rootUser private val normalUser = SharedTestDataADM.normalUser @@ -47,12 +47,12 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { private val imagesReviewerGroup = SharedTestDataADM.imagesReviewerGroup private val ProjectRestService = ZIO.serviceWithZIO[ProjectRestService] - private val UsersRestService = ZIO.serviceWithZIO[UsersRestService] + private val userRestService = ZIO.serviceWithZIO[UserRestService] - "The UsersRestService" when { + "The UserRestService" when { "calling getAllUsers" should { "with a SystemAdmin should return all real users" in { - val response = UnsafeZioRun.runOrThrow(UsersRestService(_.getAllUsers(rootUser))) + val response = UnsafeZioRun.runOrThrow(userRestService(_.getAllUsers(rootUser))) response.users.nonEmpty should be(true) response.users.size should be(18) response.users.count(_.id == KnoraUserRepo.builtIn.AnonymousUser.id.value) should be(0) @@ -60,7 +60,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { } "fail with unauthorized when asked by an anonymous user" in { - val exit = UnsafeZioRun.run(UsersRestService(_.getAllUsers(SharedTestDataADM.anonymousUser))) + val exit = UnsafeZioRun.run(userRestService(_.getAllUsers(SharedTestDataADM.anonymousUser))) assertFailsWithA[ForbiddenException](exit) } } @@ -69,14 +69,14 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "return a profile if the user (root user) is known" in { val actual = UnsafeZioRun.runOrThrow( - UsersRestService(_.getUserByEmail(KnoraSystemInstances.Users.SystemUser, Email.unsafeFrom(rootUser.email))), + userRestService(_.getUserByEmail(KnoraSystemInstances.Users.SystemUser, Email.unsafeFrom(rootUser.email))), ) actual.user shouldBe rootUser.ofType(UserInformationType.Restricted) } "return 'None' when the user is unknown" in { val exit = UnsafeZioRun.run( - UsersRestService( + userRestService( _.getUserByEmail(KnoraSystemInstances.Users.SystemUser, Email.unsafeFrom("userwrong@example.com")), ), ) @@ -87,7 +87,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "calling getUserByUsername" should { def getUserByUsername(requestingUser: User, username: Username) = - UsersRestService(_.getUserByUsername(requestingUser, username)) + userRestService(_.getUserByUsername(requestingUser, username)) "return a profile if the user (root user) is known" in { val actual = UnsafeZioRun.runOrThrow( @@ -126,7 +126,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "asked to create a new user" should { "CREATE the user and return it's profile if the supplied email is unique " in { val response = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.createUser( rootUser, UserCreateRequest( @@ -153,7 +153,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "return a 'DuplicateValueException' if the supplied 'username' is not unique" in { val exit = UnsafeZioRun.run( - UsersRestService( + userRestService( _.createUser( rootUser, UserCreateRequest( @@ -174,7 +174,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "return a 'DuplicateValueException' if the supplied 'email' is not unique" in { val exit = UnsafeZioRun.run( - UsersRestService( + userRestService( _.createUser( rootUser, UserCreateRequest( @@ -198,7 +198,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "UPDATE the user's basic information" in { /* User information is updated by the user */ val response1 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.updateUser( rootUser, SharedTestDataADM.normalUser.userIri, @@ -211,7 +211,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { /* User information is updated by a system admin */ val response2 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.updateUser( rootUser, SharedTestDataADM.normalUser.userIri, @@ -224,7 +224,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { /* User information is updated by a system admin */ val response3 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.updateUser( rootUser, SharedTestDataADM.normalUser.userIri, @@ -244,7 +244,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { val duplicateUsername = Some(Username.unsafeFrom(SharedTestDataADM.anythingUser1.username)) val exit = UnsafeZioRun.run( - UsersRestService( + userRestService( _.updateUser( rootUser, SharedTestDataADM.normalUser.userIri, @@ -261,7 +261,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "return a 'DuplicateValueException' if the supplied 'email' is not unique" in { val duplicateEmail = Some(Email.unsafeFrom(SharedTestDataADM.anythingUser1.email)) val exit = UnsafeZioRun.run( - UsersRestService( + userRestService( _.updateUser( rootUser, SharedTestDataADM.normalUser.userIri, @@ -279,7 +279,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { val requesterPassword = Password.unsafeFrom("test") val newPassword = Password.unsafeFrom("test123456") UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changePassword(normalUser, normalUser.userIri, PasswordChangeRequest(requesterPassword, newPassword)), ), ) @@ -297,7 +297,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { val newPassword = Password.unsafeFrom("test654321") UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changePassword( SharedTestDataADM.rootUser, SharedTestDataADM.normalUser.userIri, @@ -316,14 +316,14 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "UPDATE the user's status, making them inactive " in { val response1 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changeStatus(rootUser, SharedTestDataADM.normalUser.userIri, StatusChangeRequest(UserStatus.Inactive)), ), ) response1.user.status should equal(false) val response2 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changeStatus(rootUser, SharedTestDataADM.normalUser.userIri, StatusChangeRequest(UserStatus.Active)), ), ) @@ -332,7 +332,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "UPDATE the user's system admin membership" in { val response1 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changeSystemAdmin( rootUser, SharedTestDataADM.normalUser.userIri, @@ -343,7 +343,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { response1.user.isSystemAdmin should equal(true) val response2 = UnsafeZioRun.runOrThrow( - UsersRestService( + userRestService( _.changeSystemAdmin( rootUser, SharedTestDataADM.normalUser.userIri, @@ -361,16 +361,16 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { // get current project memberships val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects should equal(Chunk.empty) // add user to images project (00FF) UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToProject(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.addUserToProject(rootUser, normalUser.userIri, imagesProject.projectIri)), ) val membershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsAfterUpdate.projects.map(_.id) should equal(Chunk(imagesProject.id)) val received = UnsafeZioRun.runOrThrow( @@ -387,16 +387,16 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "ADD user to project as project admin" in { // get current project memberships val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects.map(_.id).sorted should equal(Seq(imagesProject.id).sorted) // add user to images project (00FF) UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToProject(rootUser, normalUser.userIri, incunabulaProject.projectIri)), + userRestService(_.addUserToProject(rootUser, normalUser.userIri, incunabulaProject.projectIri)), ) val membershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsAfterUpdate.projects.map(_.id).sorted should equal( Seq(imagesProject.id, incunabulaProject.id).sorted, ) @@ -415,34 +415,34 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "DELETE user from project and also as project admin" in { // check project memberships (user should be member of images and incunabula projects) val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects.map(_.id).sorted should equal( Seq(imagesProject.id, incunabulaProject.id).sorted, ) // add user as project admin to images project UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), ) // verify that the user has been added as project admin to the images project val projectAdminMembershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) projectAdminMembershipsBeforeUpdate.projects.map(_.id).sorted should equal(Seq(imagesProject.id).sorted) // remove the user as member of the images project UnsafeZioRun.runOrThrow( - UsersRestService(_.removeUserFromProject(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.removeUserFromProject(rootUser, normalUser.userIri, imagesProject.projectIri)), ) // verify that the user has been removed as project member of the images project val membershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectMemberShipsByUserIri(normalUser.userIri))) membershipsAfterUpdate.projects.map(_.id) should equal(Chunk(incunabulaProject.id)) // this should also have removed him as project admin from images project val projectAdminMembershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) projectAdminMembershipsAfterUpdate.projects should equal(Seq()) // also check that the user has been removed from the project's list of users @@ -462,12 +462,12 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "Not ADD user to project admin group if he is not a member of that project" in { // get the current project admin memberships (should be empty) val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects should equal(Seq()) // try to add user as project admin to images project (expected to fail because he is not a member of the project) val exit = UnsafeZioRun.run( - UsersRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), ) assertFailsWithA[BadRequestException]( exit, @@ -478,22 +478,22 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "ADD user to project admin group" in { // get the current project admin memberships (should be empty) val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects should equal(Seq()) // add user as project member to images project UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToProject(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.addUserToProject(rootUser, normalUser.userIri, imagesProject.projectIri)), ) // add user as project admin to images project UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.addUserToProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), ) // get the updated project admin memberships (should contain images project) val membershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) membershipsAfterUpdate.projects.map(_.id) should equal(Seq(imagesProject.id)) // get project admins for images project (should contain normal user) @@ -510,15 +510,15 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { "DELETE user from project admin group" in { val membershipsBeforeUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) membershipsBeforeUpdate.projects.map(_.id) should equal(Seq(imagesProject.id)) UnsafeZioRun.runOrThrow( - UsersRestService(_.removeUserFromProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), + userRestService(_.removeUserFromProjectAsAdmin(rootUser, normalUser.userIri, imagesProject.projectIri)), ) val membershipsAfterUpdate = - UnsafeZioRun.runOrThrow(UsersRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) + UnsafeZioRun.runOrThrow(userRestService(_.getProjectAdminMemberShipsByUserIri(normalUser.userIri))) membershipsAfterUpdate.projects should equal(Seq()) val received = UnsafeZioRun.runOrThrow( @@ -544,7 +544,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsBeforeUpdate should equal(Seq()) UnsafeZioRun.runOrThrow( - UsersRestService(_.addUserToGroup(rootUser, normalUser.userIri, imagesReviewerGroup.groupIri)), + userRestService(_.addUserToGroup(rootUser, normalUser.userIri, imagesReviewerGroup.groupIri)), ) val membershipsAfterUpdate = findGroupMembershipsByIri(normalUser.userIri) @@ -566,7 +566,7 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsBeforeUpdate.map(_.id) should equal(Seq(imagesReviewerGroup.id)) UnsafeZioRun.runOrThrow( - UsersRestService(_.removeUserFromGroup(rootUser, normalUser.userIri, imagesReviewerGroup.groupIri)), + userRestService(_.removeUserFromGroup(rootUser, normalUser.userIri, imagesReviewerGroup.groupIri)), ) val membershipsAfterUpdate = findGroupMembershipsByIri(normalUser.userIri) diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index 6283c1624a..115fe244bc 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -33,10 +33,10 @@ import org.knora.webapi.routing._ import org.knora.webapi.slice.admin.AdminModule import org.knora.webapi.slice.admin.api.AdminApiModule import org.knora.webapi.slice.admin.api._ -import org.knora.webapi.slice.admin.api.service.GroupsRestService -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.GroupRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.api.service.ProjectRestService -import org.knora.webapi.slice.admin.api.service.UsersRestService +import org.knora.webapi.slice.admin.api.service.UserRestService import org.knora.webapi.slice.admin.domain.service._ import org.knora.webapi.slice.common.api._ import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper @@ -70,18 +70,62 @@ object LayersLive { * The `Environment` that we require to exist at startup. */ type DspEnvironmentLive = - ActorSystem & AdminApiEndpoints & ApiRoutes & ApiV2Endpoints & AppConfigurations & AppRouter & - AssetPermissionsResponder & Authenticator & AuthorizationRestService & - CacheServiceRequestMessageHandler & CardinalityHandler & ConstructResponseUtilV2 & - GravsearchTypeInspectionRunner & GroupsResponderADM & GroupsRestService & GroupService & HttpServer & - IIIFRequestMessageHandler & InferenceOptimizationService & InstrumentationServerConfig & IriConverter & - JwtService & KnoraUserToUserConverter & ListsResponder & ListsResponderV2 & MessageRelay & OntologyCache & OntologyHelpers & - OntologyInferencer & OntologyResponderV2 & PermissionsResponder & PermissionsRestService & - PermissionUtilADM & ProjectService & ProjectExportService & ProjectExportStorageService & - ProjectImportService & ProjectRestService & QueryTraverser & RepositoryUpdater & ResourcesResponderV2 & - ResourceUtilV2 & ResourceUtilV2 & RestCardinalityService & SearchApiRoutes & - SearchResponderV2 & SipiService & StandoffResponderV2 & StandoffTagUtilV2 & State & StringFormatter & - TriplestoreService & UserService & UsersResponder & UsersRestService & ValuesResponderV2 + ActorSystem & + AdminApiEndpoints & + ApiRoutes & + ApiV2Endpoints & + AppConfigurations & + AppRouter & + AssetPermissionsResponder & + Authenticator & + AuthorizationRestService & + CacheServiceRequestMessageHandler & + CardinalityHandler & + ConstructResponseUtilV2 & + GravsearchTypeInspectionRunner & + GroupRestService & + GroupService & + GroupsResponderADM & + HttpServer & + IIIFRequestMessageHandler & + InferenceOptimizationService & + InstrumentationServerConfig & + IriConverter & + JwtService & + KnoraUserToUserConverter & + ListsResponder & + ListsResponderV2 & + MessageRelay & + OntologyCache & + OntologyHelpers & + OntologyInferencer & + OntologyResponderV2 & + PermissionRestService & + PermissionUtilADM & + PermissionsResponder & + ProjectExportService & + ProjectExportStorageService & + ProjectImportService & + ProjectRestService & + ProjectService & + QueryTraverser & + RepositoryUpdater & + ResourceUtilV2 & + ResourceUtilV2 & + ResourcesResponderV2 & + RestCardinalityService & + SearchApiRoutes & + SearchResponderV2 & + SipiService & + StandoffResponderV2 & + StandoffTagUtilV2 & + State & + StringFormatter & + TriplestoreService & + UserRestService & + UserService & + UsersResponder & + ValuesResponderV2 /** * All effect layers needed to provide the `Environment` diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala index 131e6ec434..4d7278d05e 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala @@ -13,12 +13,12 @@ import org.knora.webapi.responders.admin.GroupsResponderADM import org.knora.webapi.responders.admin.ListsResponder import org.knora.webapi.responders.admin.PermissionsResponder import org.knora.webapi.responders.admin.UsersResponder -import org.knora.webapi.slice.admin.api.service.GroupsRestService +import org.knora.webapi.slice.admin.api.service.GroupRestService import org.knora.webapi.slice.admin.api.service.MaintenanceRestService -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.api.service.ProjectRestService import org.knora.webapi.slice.admin.api.service.StoreRestService -import org.knora.webapi.slice.admin.api.service.UsersRestService +import org.knora.webapi.slice.admin.api.service.UserRestService import org.knora.webapi.slice.admin.domain.service.AdministrativePermissionService import org.knora.webapi.slice.admin.domain.service.GroupService import org.knora.webapi.slice.admin.domain.service.KnoraProjectService @@ -47,7 +47,7 @@ object AdminApiModule { type Provided = AdminApiEndpoints & AdminApiRoutes & // the `*RestService`s are only exposed for the integration tests - GroupsRestService & UsersRestService & ProjectRestService & PermissionsRestService + GroupRestService & UserRestService & ProjectRestService & PermissionRestService val layer: ZLayer[Dependencies, Nothing, Provided] = ZLayer.makeSome[Dependencies, Provided]( @@ -57,7 +57,7 @@ object AdminApiModule { FilesEndpointsHandler.layer, GroupsEndpoints.layer, GroupsEndpointsHandler.layer, - GroupsRestService.layer, + GroupRestService.layer, ListRestService.layer, ListsEndpoints.layer, ListsEndpointsHandlers.layer, @@ -66,14 +66,14 @@ object AdminApiModule { MaintenanceEndpointsHandlers.layer, PermissionsEndpoints.layer, PermissionsEndpointsHandlers.layer, - PermissionsRestService.layer, + PermissionRestService.layer, ProjectRestService.layer, ProjectsEndpoints.layer, ProjectsEndpointsHandler.layer, StoreRestService.layer, StoreEndpoints.layer, StoreEndpointsHandler.layer, - UsersRestService.layer, + UserRestService.layer, UsersEndpoints.layer, UsersEndpointsHandler.layer, ) 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 b4e3db9db9..261403ea76 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 @@ -10,7 +10,7 @@ import zio.ZLayer import org.knora.webapi.messages.admin.responder.groupsmessages.GroupGetResponseADM import org.knora.webapi.slice.admin.api.GroupsRequests.GroupStatusUpdateRequest import org.knora.webapi.slice.admin.api.GroupsRequests.GroupUpdateRequest -import org.knora.webapi.slice.admin.api.service.GroupsRestService +import org.knora.webapi.slice.admin.api.service.GroupRestService import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.common.api.HandlerMapper import org.knora.webapi.slice.common.api.PublicEndpointHandler @@ -18,7 +18,7 @@ import org.knora.webapi.slice.common.api.SecuredEndpointHandler case class GroupsEndpointsHandler( endpoints: GroupsEndpoints, - restService: GroupsRestService, + restService: GroupRestService, mapper: HandlerMapper, ) { private val getGroupsHandler = diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/PermissionsEndpointsHandlers.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/PermissionsEndpointsHandlers.scala index a80cf0c6ae..da478ae251 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/PermissionsEndpointsHandlers.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/PermissionsEndpointsHandlers.scala @@ -22,7 +22,7 @@ import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionD import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionGetResponseADM import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionsForProjectGetResponseADM import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM.IriIdentifier -import org.knora.webapi.slice.admin.api.service.PermissionsRestService +import org.knora.webapi.slice.admin.api.service.PermissionRestService import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.admin.domain.model.PermissionIri import org.knora.webapi.slice.common.api.HandlerMapper @@ -30,7 +30,7 @@ import org.knora.webapi.slice.common.api.SecuredEndpointHandler final case class PermissionsEndpointsHandlers( permissionsEndpoints: PermissionsEndpoints, - restService: PermissionsRestService, + restService: PermissionRestService, mapper: HandlerMapper, ) { diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/UsersEndpointsHandler.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/UsersEndpointsHandler.scala index c268dd994d..68fab9d164 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/UsersEndpointsHandler.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/UsersEndpointsHandler.scala @@ -15,7 +15,7 @@ import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.PasswordChangeRe import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.StatusChangeRequest import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.SystemAdminChangeRequest import org.knora.webapi.slice.admin.api.UsersEndpoints.Requests.UserCreateRequest -import org.knora.webapi.slice.admin.api.service.UsersRestService +import org.knora.webapi.slice.admin.api.service.UserRestService import org.knora.webapi.slice.admin.domain.model.Email import org.knora.webapi.slice.admin.domain.model.GroupIri import org.knora.webapi.slice.admin.domain.model.UserIri @@ -26,7 +26,7 @@ import org.knora.webapi.slice.common.api.SecuredEndpointHandler case class UsersEndpointsHandler( usersEndpoints: UsersEndpoints, - restService: UsersRestService, + restService: UserRestService, mapper: HandlerMapper, ) { 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/GroupRestService.scala similarity index 96% rename from webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala rename to webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupRestService.scala index 16d14af109..97f398f5e6 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/GroupRestService.scala @@ -20,7 +20,7 @@ import org.knora.webapi.slice.admin.domain.service.GroupService import org.knora.webapi.slice.common.api.AuthorizationRestService import org.knora.webapi.slice.common.api.KnoraResponseRenderer -final case class GroupsRestService( +final case class GroupRestService( auth: AuthorizationRestService, groupService: GroupService, responder: GroupsResponderADM, @@ -80,6 +80,6 @@ final case class GroupsRestService( } yield external } -object GroupsRestService { - val layer = ZLayer.derive[GroupsRestService] +object GroupRestService { + val layer = ZLayer.derive[GroupRestService] } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionsRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionRestService.scala similarity index 96% rename from webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionsRestService.scala rename to webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionRestService.scala index 0d9cec88a5..a0ad0ec0c2 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionsRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/PermissionRestService.scala @@ -39,7 +39,7 @@ import org.knora.webapi.slice.admin.domain.service.KnoraProjectService import org.knora.webapi.slice.common.api.AuthorizationRestService import org.knora.webapi.slice.common.api.KnoraResponseRenderer -final case class PermissionsRestService( +final case class PermissionRestService( responder: PermissionsResponder, knoraProjectService: KnoraProjectService, auth: AuthorizationRestService, @@ -188,18 +188,18 @@ final case class PermissionsRestService( } yield ext } -object PermissionsRestService { +object PermissionRestService { def createAdministrativePermission( request: CreateAdministrativePermissionAPIRequestADM, user: User, - ): ZIO[PermissionsRestService, Throwable, AdministrativePermissionCreateResponseADM] = + ): ZIO[PermissionRestService, Throwable, AdministrativePermissionCreateResponseADM] = ZIO.serviceWithZIO(_.createAdministrativePermission(request, user)) def createDefaultObjectAccessPermission( request: CreateDefaultObjectAccessPermissionAPIRequestADM, user: User, - ): ZIO[PermissionsRestService, Throwable, DefaultObjectAccessPermissionCreateResponseADM] = + ): ZIO[PermissionRestService, Throwable, DefaultObjectAccessPermissionCreateResponseADM] = ZIO.serviceWithZIO(_.createDefaultObjectAccessPermission(request, user)) - val layer = ZLayer.derive[PermissionsRestService] + val layer = ZLayer.derive[PermissionRestService] } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UsersRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UserRestService.scala similarity index 99% rename from webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UsersRestService.scala rename to webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UserRestService.scala index c988421445..31e26c4c97 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UsersRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/UserRestService.scala @@ -39,7 +39,7 @@ import org.knora.webapi.slice.admin.domain.service.UserService import org.knora.webapi.slice.common.api.AuthorizationRestService import org.knora.webapi.slice.common.api.KnoraResponseRenderer -final case class UsersRestService( +final case class UserRestService( auth: AuthorizationRestService, groupService: GroupService, userService: UserService, @@ -295,6 +295,6 @@ final case class UsersRestService( } yield response } -object UsersRestService { - val layer = ZLayer.derive[UsersRestService] +object UserRestService { + val layer = ZLayer.derive[UserRestService] }