Skip to content

Commit

Permalink
refactor: Migrate repositories to use AbstractEntityRepo with builtIn…
Browse files Browse the repository at this point in the history
… entities and remove constants (#3163)
  • Loading branch information
seakayone authored Apr 5, 2024
1 parent f25cfa9 commit 1dd0314
Show file tree
Hide file tree
Showing 64 changed files with 1,162 additions and 1,224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {

groupInfo.name should be("NewGroup")
groupInfo.descriptions should be(Seq(StringLiteralV2.from("NewGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.project should be(Some(SharedTestDataADM.imagesProjectExternal))
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)

Expand Down Expand Up @@ -235,7 +235,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.project should be(Some(SharedTestDataADM.imagesProjectExternal))
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)

Expand Down Expand Up @@ -263,7 +263,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.project should be(Some(SharedTestDataADM.imagesProjectExternal))
groupInfo.status should be(false)
groupInfo.selfjoin should be(false)

Expand Down Expand Up @@ -309,7 +309,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.project should be(Some(SharedTestDataADM.imagesProjectExternal))
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import org.knora.webapi.E2ESpec
import org.knora.webapi.e2e.ClientTestDataCollector
import org.knora.webapi.e2e.TestDataFileContent
import org.knora.webapi.e2e.TestDataFilePath
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.store.triplestoremessages.TriplestoreJsonProtocol
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.slice.admin.domain.service.KnoraGroupRepo
import org.knora.webapi.util.AkkaHttpUtils

/**
Expand All @@ -42,8 +41,7 @@ class PermissionsADME2ESpec extends E2ESpec with TriplestoreJsonProtocol {
"return a group's administrative permission" in {
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 groupIri = URLEncoder.encode(KnoraGroupRepo.builtIn.ProjectMember.id.value, "utf-8")
val request = Get(baseApiUrl + s"/admin/permissions/ap/$projectIri/$groupIri") ~> addCredentials(
BasicHttpCredentials(SharedTestDataADM.rootUser.email, SharedTestDataADM.testPass),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import java.util.UUID
import dsp.errors.BadRequestException
import dsp.errors.ForbiddenException
import org.knora.webapi.CoreSpec
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.responders.admin.PermissionsResponderADM
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.domain.model.Permission
import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo
import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA

/**
Expand All @@ -46,7 +46,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[BadRequestException](
AdministrativePermissionForProjectGroupGetADM(
projectIri = projectIri,
groupIri = OntologyConstants.KnoraAdmin.ProjectMember,
groupIri = KnoraGroupRepo.builtIn.ProjectMember.id.value,
requestingUser = SharedTestDataADM.imagesUser01,
),
)
Expand All @@ -57,7 +57,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[ForbiddenException](
AdministrativePermissionForProjectGroupGetADM(
projectIri = SharedTestDataADM.imagesProjectIri,
groupIri = OntologyConstants.KnoraAdmin.ProjectMember,
groupIri = KnoraGroupRepo.builtIn.ProjectMember.id.value,
requestingUser = SharedTestDataADM.imagesUser02,
),
)
Expand All @@ -71,7 +71,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createAdministrativePermission(
CreateAdministrativePermissionAPIRequestADM(
forProject = "invalid-project-IRI",
forGroup = OntologyConstants.KnoraAdmin.ProjectMember,
forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value,
hasPermissions = Set(PermissionADM.from(Permission.Administrative.ProjectAdminAll)),
),
SharedTestDataADM.imagesUser01,
Expand Down Expand Up @@ -102,7 +102,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
CreateAdministrativePermissionAPIRequestADM(
id = Some(permissionIri),
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = OntologyConstants.KnoraAdmin.ProjectMember,
forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value,
hasPermissions = Set(PermissionADM.from(Permission.Administrative.ProjectAdminAll)),
),
SharedTestDataADM.imagesUser01,
Expand All @@ -124,7 +124,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createAdministrativePermission(
CreateAdministrativePermissionAPIRequestADM(
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = OntologyConstants.KnoraAdmin.ProjectMember,
forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value,
hasPermissions = hasPermissions,
),
SharedTestDataADM.imagesUser01,
Expand All @@ -142,7 +142,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createAdministrativePermission(
CreateAdministrativePermissionAPIRequestADM(
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = OntologyConstants.KnoraAdmin.ProjectMember,
forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value,
hasPermissions = Set.empty[PermissionADM],
),
SharedTestDataADM.imagesUser01,
Expand All @@ -156,7 +156,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createAdministrativePermission(
CreateAdministrativePermissionAPIRequestADM(
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = OntologyConstants.KnoraAdmin.ProjectMember,
forGroup = KnoraGroupRepo.builtIn.ProjectMember.id.value,
hasPermissions = Set(PermissionADM.from(Permission.Administrative.ProjectAdminAll)),
),
SharedTestDataADM.imagesReviewerUser,
Expand Down Expand Up @@ -201,7 +201,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[BadRequestException](
DefaultObjectAccessPermissionGetRequestADM(
projectIri = projectIri,
groupIri = Some(OntologyConstants.KnoraAdmin.ProjectMember),
groupIri = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
requestingUser = SharedTestDataADM.imagesUser01,
),
)
Expand Down Expand Up @@ -236,7 +236,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[BadRequestException](
DefaultObjectAccessPermissionGetRequestADM(
projectIri = SharedTestDataADM.imagesProjectIri,
groupIri = Some(OntologyConstants.KnoraAdmin.ProjectMember),
groupIri = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
resourceClassIri = Some(SharedOntologyTestDataADM.IMAGES_BILD_RESOURCE_CLASS),
requestingUser = SharedTestDataADM.imagesUser01,
),
Expand All @@ -248,7 +248,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[BadRequestException](
DefaultObjectAccessPermissionGetRequestADM(
projectIri = SharedTestDataADM.imagesProjectIri,
groupIri = Some(OntologyConstants.KnoraAdmin.ProjectMember),
groupIri = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
propertyIri = Some(SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY_LocalHost),
requestingUser = SharedTestDataADM.imagesUser01,
),
Expand All @@ -272,7 +272,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val caught = intercept[ForbiddenException](
DefaultObjectAccessPermissionGetRequestADM(
projectIri = SharedTestDataADM.imagesProjectIri,
groupIri = Some(OntologyConstants.KnoraAdmin.ProjectMember),
groupIri = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
requestingUser = SharedTestDataADM.imagesUser02,
),
)
Expand Down Expand Up @@ -419,9 +419,10 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createDefaultObjectAccessPermission(
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = forProject,
forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.imagesUser01,
),
Expand All @@ -436,8 +437,9 @@ class PermissionsMessagesADMSpec extends CoreSpec {
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = Some(groupIri),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.imagesUser01,
),
Expand All @@ -452,9 +454,10 @@ class PermissionsMessagesADMSpec extends CoreSpec {
CreateDefaultObjectAccessPermissionAPIRequestADM(
id = Some(permissionIri),
forProject = SharedTestDataADM.imagesProjectIri,
forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.imagesUser01,
),
Expand All @@ -480,7 +483,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val hasPermissions = Set(
PermissionADM(
name = "invalid",
additionalInformation = Some(OntologyConstants.KnoraAdmin.Creator),
additionalInformation = Some(KnoraGroupRepo.builtIn.Creator.id.value),
permissionCode = Some(8),
),
)
Expand All @@ -498,7 +501,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val hasPermissions = Set(
PermissionADM(
name = Permission.ObjectAccess.ChangeRights.token,
additionalInformation = Some(OntologyConstants.KnoraAdmin.Creator),
additionalInformation = Some(KnoraGroupRepo.builtIn.Creator.id.value),
permissionCode = Some(invalidCode),
),
)
Expand All @@ -516,7 +519,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val hasPermissions = Set(
PermissionADM(
name = Permission.ObjectAccess.ChangeRights.token,
additionalInformation = Some(OntologyConstants.KnoraAdmin.Creator),
additionalInformation = Some(KnoraGroupRepo.builtIn.Creator.id.value),
permissionCode = Some(Permission.ObjectAccess.View.code),
),
)
Expand All @@ -534,7 +537,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val hasPermissions = Set(
PermissionADM(
name = "",
additionalInformation = Some(OntologyConstants.KnoraAdmin.Creator),
additionalInformation = Some(KnoraGroupRepo.builtIn.Creator.id.value),
permissionCode = None,
),
)
Expand Down Expand Up @@ -587,10 +590,11 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createDefaultObjectAccessPermission(
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = anythingProjectIri,
forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember),
forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
forResourceClass = Some(ANYTHING_THING_RESOURCE_CLASS_LocalHost),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.rootUser,
),
Expand All @@ -603,10 +607,11 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createDefaultObjectAccessPermission(
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = anythingProjectIri,
forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember),
forGroup = Some(KnoraGroupRepo.builtIn.ProjectMember.id.value),
forProperty = Some(ANYTHING_HasDate_PROPERTY_LocalHost),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.rootUser,
),
Expand All @@ -620,8 +625,9 @@ class PermissionsMessagesADMSpec extends CoreSpec {
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = anythingProjectIri,
forProperty = Some(SharedTestDataADM.customValueIRI),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.rootUser,
),
Expand All @@ -635,8 +641,9 @@ class PermissionsMessagesADMSpec extends CoreSpec {
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = anythingProjectIri,
forResourceClass = Some(ANYTHING_THING_RESOURCE_CLASS_LocalHost),
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.rootUser,
),
Expand All @@ -652,8 +659,9 @@ class PermissionsMessagesADMSpec extends CoreSpec {
PermissionsRestService.createDefaultObjectAccessPermission(
CreateDefaultObjectAccessPermissionAPIRequestADM(
forProject = anythingProjectIri,
hasPermissions =
Set(PermissionADM.from(Permission.ObjectAccess.ChangeRights, OntologyConstants.KnoraAdmin.ProjectMember)),
hasPermissions = Set(
PermissionADM.from(Permission.ObjectAccess.ChangeRights, KnoraGroupRepo.builtIn.ProjectMember.id.value),
),
),
SharedTestDataADM.rootUser,
),
Expand Down
Loading

0 comments on commit 1dd0314

Please sign in to comment.