Skip to content

Commit

Permalink
refactor: Migrate admin/permissions endpoints to tapir (DEV-1590) (#…
Browse files Browse the repository at this point in the history
…2975)

Co-authored-by: Balduin Landolt <[email protected]>
  • Loading branch information
seakayone and BalduinLandolt authored Jan 9, 2024
1 parent 6ee0111 commit cf2c6fb
Show file tree
Hide file tree
Showing 41 changed files with 1,881 additions and 2,335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.knora.webapi.responders.v2.ontology.OntologyHelpersLive
import org.knora.webapi.routing._
import org.knora.webapi.slice.admin.api._
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.ProjectADMRestService
import org.knora.webapi.slice.admin.api.service.ProjectsADMRestServiceLive
import org.knora.webapi.slice.admin.api.service.UsersADMRestServiceLive
Expand Down Expand Up @@ -77,11 +78,12 @@ object LayersTest {
with DspIngestTestContainer
with SharedVolumes.Images

type CommonR0 = ActorSystem with AppConfigurations with SipiService with JwtService with StringFormatter
type CommonR0 = ActorSystem with AppConfigurations with JwtService with SipiService with StringFormatter
type CommonR =
ApiRoutes
with AppRouter
with Authenticator
with AuthorizationRestService
with CacheService
with CacheServiceRequestMessageHandler
with CardinalityHandler
Expand All @@ -102,10 +104,12 @@ object LayersTest {
with MessageRelay
with OntologyCache
with OntologyHelpers
with OntologyInferencer
with OntologyRepo
with OntologyResponderV2
with PermissionUtilADM
with PermissionsResponderADM
with PermissionsRestService
with PredicateObjectMapper
with ProjectADMRestService
with ProjectADMService
Expand All @@ -118,12 +122,10 @@ object LayersTest {
with ResourceUtilV2
with ResourcesResponderV2
with RestCardinalityService
with RestPermissionService
with RestResourceInfoService
with SearchApiRoutes
with SearchResponderV2
with SipiResponderADM
with OntologyInferencer
with StandoffResponderV2
with StandoffTagUtilV2
with State
Expand All @@ -139,6 +141,7 @@ object LayersTest {
ApiRoutes.layer,
AppRouter.layer,
AuthenticatorLive.layer,
AuthorizationRestServiceLive.layer,
BaseEndpoints.layer,
CacheServiceInMemImpl.layer,
CacheServiceRequestMessageHandlerLive.layer,
Expand Down Expand Up @@ -170,7 +173,10 @@ object LayersTest {
OntologyRepoLive.layer,
OntologyResponderV2Live.layer,
PermissionUtilADMLive.layer,
PermissionsEndpoints.layer,
PermissionsEndpointsHandlers.layer,
PermissionsResponderADMLive.layer,
PermissionsRestService.layer,
PredicateObjectMapper.layer,
PredicateRepositoryLive.layer,
ProjectADMServiceLive.layer,
Expand All @@ -187,7 +193,6 @@ object LayersTest {
ResourceUtilV2Live.layer,
ResourcesResponderV2Live.layer,
RestCardinalityServiceLive.layer,
RestPermissionServiceLive.layer,
SearchApiRoutes.layer,
SearchResponderV2Live.layer,
SipiResponderADMLive.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

package org.knora.webapi.e2e.admin

import org.apache.pekko
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials
import spray.json._
import zio.durationInt

import java.net.URLEncoder

import org.knora.webapi.E2ESpec
import org.knora.webapi.e2e.ClientTestDataCollector
import org.knora.webapi.e2e.TestDataFileContent
Expand All @@ -18,11 +21,10 @@ import org.knora.webapi.messages.store.triplestoremessages.TriplestoreJsonProtoc
import org.knora.webapi.sharedtestdata.SharedOntologyTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM2
import org.knora.webapi.slice.admin.domain.model.GroupIri
import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.util.AkkaHttpUtils

import pekko.http.scaladsl.model._
import pekko.http.scaladsl.model.headers.BasicHttpCredentials

/**
* End-to-End (E2E) test specification for testing the 'v1/permissions' route.
*
Expand All @@ -38,9 +40,10 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
"The Permissions Route ('admin/permissions')" when {
"getting permissions" should {
"return a group's administrative permission" in {

val projectIri = java.net.URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")
val groupIri = java.net.URLEncoder.encode(OntologyConstants.KnoraAdmin.ProjectMember, "utf-8")
val projectIri =
URLEncoder.encode(ProjectIri.unsafeFrom(SharedTestDataADM2.imagesProjectInfo.id).value, "utf-8")
val groupIri =
URLEncoder.encode(GroupIri.unsafeFrom(OntologyConstants.KnoraAdmin.ProjectMember).value, "utf-8")
val request = Get(baseApiUrl + s"/admin/permissions/ap/$projectIri/$groupIri") ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
)
Expand Down Expand Up @@ -68,7 +71,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
}

"return a project's administrative permissions" in {
val projectIri = java.net.URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")
val projectIri = URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")

val request = Get(baseApiUrl + s"/admin/permissions/ap/$projectIri") ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
Expand All @@ -93,7 +96,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
}

"return a project's default object access permissions" in {
val projectIri = java.net.URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")
val projectIri = URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")

val request = Get(baseApiUrl + s"/admin/permissions/doap/$projectIri") ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
Expand All @@ -118,7 +121,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
}

"return a project's all permissions" in {
val projectIri = java.net.URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")
val projectIri = URLEncoder.encode(SharedTestDataADM2.imagesProjectInfo.id, "utf-8")

val request = Get(baseApiUrl + s"/admin/permissions/$projectIri") ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
Expand Down Expand Up @@ -419,7 +422,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
"updating permissions" should {
"change the group of an administrative permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val newGroupIri = "http://rdfh.ch/groups/00FF/images-reviewer"
val updatePermissionGroup =
s"""{
Expand Down Expand Up @@ -461,7 +464,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {

"change the group of a default object access permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/sdHG20U6RoiwSu8MeAT1vA"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val newGroupIri = "http://rdfh.ch/groups/00FF/images-reviewer"
val updatePermissionGroup =
s"""{
Expand Down Expand Up @@ -504,7 +507,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {

"change the set of hasPermissions of an administrative permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val updateHasPermissions =
s"""{
| "hasPermissions":[{"additionalInformation":null,"name":"ProjectAdminGroupAllPermission","permissionCode":null}]
Expand Down Expand Up @@ -549,7 +552,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {

"change the set of hasPermissions of a default object access permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/Q3OMWyFqStGYK8EXmC7KhQ"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val updateHasPermissions =
s"""{
| "hasPermissions":[{"additionalInformation":"http://www.knora.org/ontology/knora-admin#ProjectMember","name":"D","permissionCode":7}]
Expand Down Expand Up @@ -600,7 +603,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {

"change the resource class of a default object access permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/Q3OMWyFqStGYK8EXmC7KhQ"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS
val updateResourceClass =
s"""{
Expand Down Expand Up @@ -646,7 +649,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {

"change the property of a default object access permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val propertyClassIri = SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY
val updateResourceClass =
s"""{
Expand Down Expand Up @@ -691,7 +694,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
"delete request" should {
"erase a defaultObjectAccess permission" in {
val permissionIri = customDOAPIri
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val request = Delete(baseApiUrl + s"/admin/permissions/" + encodedPermissionIri) ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
)
Expand All @@ -712,7 +715,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
}
"erase an administrative permission" in {
val permissionIri = "http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ"
val encodedPermissionIri = java.net.URLEncoder.encode(permissionIri, "utf-8")
val encodedPermissionIri = URLEncoder.encode(permissionIri, "utf-8")
val request = Delete(baseApiUrl + s"/admin/permissions/" + encodedPermissionIri) ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass)
)
Expand Down
Loading

0 comments on commit cf2c6fb

Please sign in to comment.