diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2SpecFullData.scala b/integration/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2SpecFullData.scala index 38c338219f..43b03dba47 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2SpecFullData.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2SpecFullData.scala @@ -11,8 +11,6 @@ import dsp.valueobjects.UuidUtil import org.knora.webapi.InternalSchema import org.knora.webapi.messages.IriConversions._ import org.knora.webapi.messages.StringFormatter -import org.knora.webapi.messages.util.PermissionUtilADM.ChangeRightsPermission -import org.knora.webapi.messages.util.PermissionUtilADM.ViewPermission import org.knora.webapi.messages.v2.responder.resourcemessages.ReadResourceV2 import org.knora.webapi.messages.v2.responder.resourcemessages.ReadResourcesSequenceV2 import org.knora.webapi.messages.v2.responder.standoffmessages.StandoffDataTypeClasses @@ -20,6 +18,7 @@ import org.knora.webapi.messages.v2.responder.standoffmessages.StandoffTagIriAtt import org.knora.webapi.messages.v2.responder.standoffmessages.StandoffTagV2 import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.sharedtestdata.SharedTestDataADM +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormatter) { @@ -33,7 +32,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2019-11-29T10:00:00.673298Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0001/anything#hasInteger".toSmartIri -> Vector( ReadOtherValueV2( @@ -48,7 +47,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("F2xCr0S2QfWRQxJDWY9L0g"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ReadOtherValueV2( @@ -63,7 +62,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("yVTqO37cRkCSvXbFc3vTyw"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -87,7 +86,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2019-11-29T10:00:00.673298Z"), - userPermission = ViewPermission, + userPermission = ObjectAccessPermission.View, values = Map(), projectADM = SharedTestDataADM.anythingProject, lastModificationDate = None, @@ -108,7 +107,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2020-04-07T09:12:56.710717Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0001/anything#hasOtherThingValue".toSmartIri -> Vector( ReadLinkValueV2( @@ -127,7 +126,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2020-04-07T09:12:56.710717Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map(), projectADM = SharedTestDataADM.anythingProject, lastModificationDate = None, @@ -142,7 +141,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("UgSp5mXTTSKdI02ZU1KIAA"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -159,7 +158,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("U1PwfNaVRQebbOSFWNdMqQ"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -183,7 +182,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2020-04-07T09:12:56.710717Z"), - userPermission = ViewPermission, + userPermission = ObjectAccessPermission.View, values = Map( "http://www.knora.org/ontology/0001/anything#hasInteger".toSmartIri -> Vector( ReadOtherValueV2( @@ -198,7 +197,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("U1PwfNaVRQebbOSFWNdMqQ"), - userPermission = ViewPermission, + userPermission = ObjectAccessPermission.View, deletionInfo = None, ), ), @@ -222,7 +221,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0001/anything#hasText".toSmartIri -> Vector( ReadTextValueV2( @@ -276,7 +275,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("1"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ReadTextValueV2( @@ -330,7 +329,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, valueHasUUID = UuidUtil.decode("2"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -351,7 +350,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map(), projectADM = SharedTestDataADM.anythingProject, lastModificationDate = None, @@ -366,7 +365,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://www.knora.org/ontology/knora-admin#SystemUser", previousValueIri = None, valueHasUUID = UuidUtil.decode("0"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -391,7 +390,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#page".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:23Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#partOfValue".toSmartIri -> Vector( ReadLinkValueV2( @@ -411,7 +410,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:23Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#title".toSmartIri -> Vector( ReadTextValueV2( @@ -429,7 +428,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("d9a522845006"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -448,7 +447,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("bbd4d6a9-8b73-4670-b0cd-e851cd0a7c5d"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -466,7 +465,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("fae17f4f6106"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -484,7 +483,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#page".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#partOfValue".toSmartIri -> Vector( ReadLinkValueV2( @@ -504,7 +503,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#title".toSmartIri -> Vector( ReadTextValueV2( @@ -522,7 +521,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("c3295339"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -541,7 +540,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("25c5e9fd-2cb2-4350-88bb-882be3373745"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -559,7 +558,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("53feeaf80a"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -584,7 +583,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#title".toSmartIri -> Vector( ReadTextValueV2( @@ -602,7 +601,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("c3295339"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -624,7 +623,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#page".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:10Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#partOfValue".toSmartIri -> Vector( ReadLinkValueV2( @@ -644,7 +643,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("25c5e9fd-2cb2-4350-88bb-882be3373745"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -662,7 +661,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("53feeaf80a"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -681,7 +680,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("25c5e9fd-2cb2-4350-88bb-882be3373745"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -699,7 +698,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:23Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#title".toSmartIri -> Vector( ReadTextValueV2( @@ -717,7 +716,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("d9a522845006"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -739,7 +738,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#page".toSmartIri, creationDate = Instant.parse("2016-03-02T15:05:23Z"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, values = Map( "http://www.knora.org/ontology/0803/incunabula#partOfValue".toSmartIri -> Vector( ReadLinkValueV2( @@ -759,7 +758,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("bbd4d6a9-8b73-4670-b0cd-e851cd0a7c5d"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -777,7 +776,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("fae17f4f6106"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), @@ -796,7 +795,7 @@ class ConstructResponseUtilV2SpecFullData(implicit stringFormatter: StringFormat attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, valueHasUUID = UuidUtil.decode("bbd4d6a9-8b73-4670-b0cd-e851cd0a7c5d"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, deletionInfo = None, ), ), diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/PermissionUtilADMSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/util/PermissionUtilADMSpec.scala index c6f2de9b2f..03e3482866 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/PermissionUtilADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/PermissionUtilADMSpec.scala @@ -14,9 +14,9 @@ import org.knora.webapi.messages.OntologyConstants import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionADM import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionType import org.knora.webapi.messages.util.PermissionUtilADM -import org.knora.webapi.messages.util.PermissionUtilADM._ import org.knora.webapi.sharedtestdata.SharedTestDataADM import org.knora.webapi.sharedtestdata.SharedTestDataADM2 +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import pekko.testkit.ImplicitSender @@ -25,11 +25,11 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { val permissionLiteral = "RV knora-admin:UnknownUser|V knora-admin:KnownUser|M knora-admin:ProjectMember|CR knora-admin:Creator" - val parsedPermissionLiteral: Map[EntityPermission, Set[IRI]] = Map( - RestrictedViewPermission -> Set(OntologyConstants.KnoraAdmin.UnknownUser), - ViewPermission -> Set(OntologyConstants.KnoraAdmin.KnownUser), - ModifyPermission -> Set(OntologyConstants.KnoraAdmin.ProjectMember), - ChangeRightsPermission -> Set(OntologyConstants.KnoraAdmin.Creator), + val parsedPermissionLiteral: Map[ObjectAccessPermission, Set[IRI]] = Map( + ObjectAccessPermission.RestrictedView -> Set(OntologyConstants.KnoraAdmin.UnknownUser), + ObjectAccessPermission.View -> Set(OntologyConstants.KnoraAdmin.KnownUser), + ObjectAccessPermission.Modify -> Set(OntologyConstants.KnoraAdmin.ProjectMember), + ObjectAccessPermission.ChangeRights -> Set(OntologyConstants.KnoraAdmin.Creator), ) "PermissionUtil" should { @@ -40,7 +40,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.incunabulaMemberUser, - ) should equal(Some(ModifyPermission)) // modify permission + ) should equal(Some(ObjectAccessPermission.Modify)) // modify permission } "return user's max permission for a specific resource (incunabula project admin user)" in { @@ -49,7 +49,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.incunabulaProjectAdminUser, - ) should equal(Some(ChangeRightsPermission)) // change rights permission + ) should equal(Some(ObjectAccessPermission.ChangeRights)) // change rights permission } "return user's max permission for a specific resource (incunabula creator user)" in { @@ -58,7 +58,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.incunabulaCreatorUser, - ) should equal(Some(ChangeRightsPermission)) // change rights permission + ) should equal(Some(ObjectAccessPermission.ChangeRights)) // change rights permission } "return user's max permission for a specific resource (root user)" in { @@ -67,7 +67,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.rootUser, - ) should equal(Some(ChangeRightsPermission)) // change rights permission + ) should equal(Some(ObjectAccessPermission.ChangeRights)) // change rights permission } "return user's max permission for a specific resource (normal user)" in { @@ -76,7 +76,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.normalUser, - ) should equal(Some(ViewPermission)) // view permission + ) should equal(Some(ObjectAccessPermission.View)) // view permission } "return user's max permission for a specific resource (anonymous user)" in { @@ -85,7 +85,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityProject = SharedTestDataADM2.incunabulaProjectIri, entityPermissionLiteral = permissionLiteral, requestingUser = SharedTestDataADM.anonymousUser, - ) should equal(Some(RestrictedViewPermission)) // restricted view permission + ) should equal(Some(ObjectAccessPermission.RestrictedView)) // restricted view permission } "return user's max permission from assertions for a specific resource" in { @@ -99,7 +99,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { entityIri = "http://rdfh.ch/00014b43f902", assertions = assertions, requestingUser = SharedTestDataADM.incunabulaMemberUser, - ) should equal(Some(ModifyPermission)) // modify permissions + ) should equal(Some(ObjectAccessPermission.Modify)) // modify permissions } "return user's max permission on link value" ignore { @@ -119,7 +119,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.ProjectMember), PermissionADM.viewPermission(OntologyConstants.KnoraAdmin.KnownUser), PermissionADM.viewPermission("http://rdfh.ch/groups/customgroup"), - PermissionADM.restrictedViewPermission(OntologyConstants.KnoraAdmin.UnknownUser), + ObjectAccessPermission.View.toPermissionADM(OntologyConstants.KnoraAdmin.UnknownUser), ) PermissionUtilADM.parsePermissionsWithType( @@ -161,17 +161,17 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { "remove duplicate permissions" in { val duplicatedPermissions = Seq( - PermissionADM.restrictedViewPermission("1"), - PermissionADM.restrictedViewPermission("1"), - PermissionADM.restrictedViewPermission("2"), + ObjectAccessPermission.View.toPermissionADM("1"), + ObjectAccessPermission.View.toPermissionADM("1"), + ObjectAccessPermission.View.toPermissionADM("2"), PermissionADM.changeRightsPermission("2"), PermissionADM.changeRightsPermission("3"), PermissionADM.changeRightsPermission("3"), ) val deduplicatedPermissions = Set( - PermissionADM.restrictedViewPermission("1"), - PermissionADM.restrictedViewPermission("2"), + ObjectAccessPermission.View.toPermissionADM("1"), + ObjectAccessPermission.View.toPermissionADM("2"), PermissionADM.changeRightsPermission("2"), PermissionADM.changeRightsPermission("3"), ) @@ -184,7 +184,7 @@ class PermissionUtilADMSpec extends CoreSpec with ImplicitSender { "remove lesser permissions" in { val withLesserPermissions = Set( - PermissionADM.restrictedViewPermission("1"), + ObjectAccessPermission.View.toPermissionADM("1"), PermissionADM.viewPermission("1"), PermissionADM.modifyPermission("2"), PermissionADM.changeRightsPermission("1"), diff --git a/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2SpecFullData.scala b/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2SpecFullData.scala index 1234422068..f4e9005f89 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2SpecFullData.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2SpecFullData.scala @@ -13,10 +13,10 @@ import org.knora.webapi.messages.IriConversions._ import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.util.CalendarNameJulian import org.knora.webapi.messages.util.DatePrecisionYear -import org.knora.webapi.messages.util.PermissionUtilADM._ import org.knora.webapi.messages.v2.responder.resourcemessages._ import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.sharedtestdata.SharedTestDataADM +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission // FIXME: Rename to something more generic and without spec in the name since it is not a spec and is used in more then one spec class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { @@ -26,7 +26,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter resourceIri = "http://rdfh.ch/0803/c5058f3a", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -46,7 +46,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("5524469101"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:UnknownUser,knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -66,7 +66,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("184e99ca01"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -84,7 +84,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("db77ec0302"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:UnknownUser,knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -102,7 +102,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("9ea13f3d02"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -122,7 +122,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("497df9ab"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -141,7 +141,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueIri = "http://rdfh.ch/0803/c5058f3a/values/8653a672", valueHasUUID = UuidUtil.decode("8653a672"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -162,7 +162,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("10e00c7acc2704"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -182,7 +182,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("92faf25701"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:UnknownUser,knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -202,7 +202,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("0ca74ce5"), permissions = "CR knora-admin:Creator|V knora-admin:UnknownUser,knora-admin:KnownUser,knora-admin:ProjectMember", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -224,7 +224,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("cfd09f1e01"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -244,7 +244,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("c3295339"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -261,7 +261,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter resourceIri = "http://rdfh.ch/0803/c5058f3a", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -277,7 +277,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter resourceIri = "http://rdfh.ch/0803/2a6221216701", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -297,7 +297,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("e94fa8a09205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -317,7 +317,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("7b4a9bf89305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -335,7 +335,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("3e74ee319405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -353,7 +353,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("019e416b9405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -371,7 +371,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("c4c794a49405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -389,7 +389,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("87f1e7dd9405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -407,7 +407,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("4a1b3b179505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -425,7 +425,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("0d458e509505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -443,7 +443,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("d06ee1899505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -461,7 +461,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("939834c39505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -481,7 +481,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("dda85bbb9105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -500,7 +500,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueIri = "http://rdfh.ch/0803/2a6221216701/values/1a7f08829105", valueHasUUID = UuidUtil.decode("1a7f08829105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -520,7 +520,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("56c287fc9505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -541,7 +541,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("f89173afca2704"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -561,7 +561,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("ac79fbd99205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -579,7 +579,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("6fa34e139305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -597,7 +597,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("32cda14c9305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -615,7 +615,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("f5f6f4859305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -635,7 +635,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("b82048bf9305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -655,7 +655,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("262655679205"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -675,7 +675,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("a0d2aef49105"), permissions = "CR knora-admin:Creator|V knora-admin:ProjectMember,knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -697,7 +697,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("63fc012e9205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -717,7 +717,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("d1010fd69005"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -735,7 +735,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("942b620f9105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -753,7 +753,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueHasUUID = UuidUtil.decode("5755b5489105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -772,7 +772,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter resourceIri = "http://rdfh.ch/0803/2a6221216701", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = "http://rdfh.ch/users/91e19f1e01", projectADM = SharedTestDataADM.incunabulaProject, values = Map(), @@ -800,7 +800,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter label = "A thing with version history", resourceIri = "http://rdfh.ch/0001/thing-with-history", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:UnknownUser", - userPermission = ModifyPermission, + userPermission = ObjectAccessPermission.Modify, attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2019-02-08T15:05:10Z"), @@ -817,7 +817,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueIri = "http://rdfh.ch/0001/thing-with-history/values/2b", valueHasUUID = UuidUtil.decode("W5fm67e0QDWxRZumcXcs6g"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2019-02-11T10:05:10Z"), attachedToUser = "http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ", previousValueIri = Some("http://rdfh.ch/0001/thing-with-history/values/2a"), @@ -836,7 +836,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueIri = "http://rdfh.ch/0001/thing-with-history/values/3a", valueHasUUID = UuidUtil.decode("IZGOjVqxTfSNO4ieKyp0SA"), permissions = "V knora-admin:UnknownUser|M knora-admin:ProjectMember", - userPermission = ModifyPermission, + userPermission = ObjectAccessPermission.Modify, valueCreationDate = Instant.parse("2019-02-10T10:30:10Z"), attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", previousValueIri = None, @@ -853,7 +853,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueIri = "http://rdfh.ch/0001/thing-with-history/values/1a", valueHasUUID = UuidUtil.decode("pLlW4ODASumZfZFbJdpw1g"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2019-02-11T09:05:10Z"), attachedToUser = "http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ", previousValueIri = None, @@ -966,7 +966,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2019-02-08T15:05:10Z"), - userPermission = ModifyPermission, + userPermission = ObjectAccessPermission.Modify, values = Map( "http://www.knora.org/ontology/0001/anything#hasInteger".toSmartIri -> Vector( ReadOtherValueV2( @@ -980,7 +980,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueCreationDate = Instant.parse("2019-02-13T09:05:10Z"), attachedToUser = "http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ", valueHasUUID = UuidUtil.decode("pLlW4ODASumZfZFbJdpw1g"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, previousValueIri = Some("http://rdfh.ch/0001/thing-with-history/values/1b"), deletionInfo = None, ), @@ -1004,7 +1004,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter attachedToUser = "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q", resourceClassIri = "http://www.knora.org/ontology/0001/anything#Thing".toSmartIri, creationDate = Instant.parse("2019-02-08T15:05:10Z"), - userPermission = ModifyPermission, + userPermission = ObjectAccessPermission.Modify, values = Map( "http://www.knora.org/ontology/0001/anything#hasInteger".toSmartIri -> Vector( ReadOtherValueV2( @@ -1018,7 +1018,7 @@ class ResourcesResponderV2SpecFullData(implicit stringFormatter: StringFormatter valueCreationDate = Instant.parse("2019-02-12T09:05:10Z"), attachedToUser = "http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ", valueHasUUID = UuidUtil.decode("pLlW4ODASumZfZFbJdpw1g"), - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, previousValueIri = Some("http://rdfh.ch/0001/thing-with-history/values/1a"), deletionInfo = None, ), diff --git a/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponseCheckerV2SpecFullData.scala b/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponseCheckerV2SpecFullData.scala index 7a1dd4c6c5..e0d08e4ba3 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponseCheckerV2SpecFullData.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponseCheckerV2SpecFullData.scala @@ -13,10 +13,10 @@ import org.knora.webapi.messages.IriConversions._ import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.util.CalendarNameJulian import org.knora.webapi.messages.util.DatePrecisionYear -import org.knora.webapi.messages.util.PermissionUtilADM._ import org.knora.webapi.messages.v2.responder.resourcemessages._ import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.sharedtestdata.SharedTestDataADM +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission // FIXME: Rename to something without spec in the name since it is not a spec class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFormatter) { @@ -27,7 +27,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor resourceIri = "http://rdfh.ch/2a6221216701", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -46,7 +46,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("e94fa8a09205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -66,7 +66,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("7b4a9bf89305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -84,7 +84,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("3e74ee319405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -102,7 +102,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("019e416b9405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -120,7 +120,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("c4c794a49405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -138,7 +138,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("87f1e7dd9405"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -156,7 +156,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("4a1b3b179505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -174,7 +174,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("0d458e509505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -192,7 +192,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("d06ee1899505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -210,7 +210,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("939834c39505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -230,7 +230,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("dda85bbb9105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -249,7 +249,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueIri = "http://rdfh.ch/2a6221216701/values/1a7f08829105", valueHasUUID = UuidUtil.decode("1a7f08829105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -269,7 +269,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("56c287fc9505"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:21Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -290,7 +290,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("f89173afca2704"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -310,7 +310,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("ac79fbd99205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -328,7 +328,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("6fa34e139305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -346,7 +346,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("32cda14c9305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -364,7 +364,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("f5f6f4859305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -384,7 +384,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("b82048bf9305"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -404,7 +404,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("262655679205"), permissions = "CR knora-admin:Creator|D knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -424,7 +424,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("a0d2aef49105"), permissions = "CR knora-admin:Creator|V knora-admin:ProjectMember,knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -446,7 +446,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("63fc012e9205"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -466,7 +466,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("d1010fd69005"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, @@ -484,7 +484,7 @@ class ResourcesResponseCheckerV2SpecFullData(implicit stringFormatter: StringFor valueHasUUID = UuidUtil.decode("942b620f9105"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, valueCreationDate = Instant.parse("2016-03-02T15:05:20Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", previousValueIri = None, diff --git a/integration/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala b/integration/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala index 156361f54e..38d885b7d3 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala @@ -13,11 +13,11 @@ import dsp.valueobjects.UuidUtil import org.knora.webapi._ import org.knora.webapi.messages.IriConversions._ import org.knora.webapi.messages.StringFormatter -import org.knora.webapi.messages.util.PermissionUtilADM._ import org.knora.webapi.messages.util.search._ import org.knora.webapi.messages.v2.responder.resourcemessages._ import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.sharedtestdata.SharedTestDataADM +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import pekko.actor.ActorSystem @@ -34,7 +34,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { resourceIri = "", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ChangeRightsPermission, + userPermission = ObjectAccessPermission.ChangeRights, attachedToUser = testUser1, resourceClassIri = booksBookIri.toSmartIri, projectADM = SharedTestDataADM.anythingProject, @@ -53,7 +53,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { valueHasUUID = UuidUtil.decode("d34d34d3-4d34-d34d-3496-2b2dfef6a5b9"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = ModifyPermission, + userPermission = ObjectAccessPermission.Modify, previousValueIri = None, valueCreationDate = Instant.parse("2018-05-29T16:42:04.381Z"), attachedToUser = testUser2, @@ -137,7 +137,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { resourceIri = "http://rdfh.ch/0803/c5058f3a", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = RestrictedViewPermission, + userPermission = ObjectAccessPermission.RestrictedView, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -156,7 +156,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { valueHasUUID = UuidUtil.decode("c3295339"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ViewPermission, + userPermission = ObjectAccessPermission.View, previousValueIri = None, valueCreationDate = Instant.parse("2016-03-02T15:05:10Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", @@ -173,7 +173,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { resourceIri = "http://rdfh.ch/0803/ff17e5ef9601", permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser", - userPermission = RestrictedViewPermission, + userPermission = ObjectAccessPermission.RestrictedView, attachedToUser = "http://rdfh.ch/users/91e19f1e01", resourceClassIri = "http://www.knora.org/ontology/0803/incunabula#book".toSmartIri, projectADM = SharedTestDataADM.incunabulaProject, @@ -192,7 +192,7 @@ class SearchResponderV2SpecFullData(implicit stringFormatter: StringFormatter) { valueHasUUID = UuidUtil.decode("d9a522845006"), permissions = "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", - userPermission = ViewPermission, + userPermission = ObjectAccessPermission.View, previousValueIri = None, valueCreationDate = Instant.parse("2016-03-02T15:05:23Z"), attachedToUser = "http://rdfh.ch/users/91e19f1e01", diff --git a/integration/src/test/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala b/integration/src/test/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala index 4ca04a641a..32b43f0ad8 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala @@ -2607,7 +2607,7 @@ class ValuesResponderV2Spec extends CoreSpec with ImplicitSender { } } - "not update a value with custom permissions if the requesting user does not have ChangeRightsPermission on the value" in { + "not update a value with custom permissions if the requesting user does not have ObjectAccessPermission.ChangeRights on the value" in { val resourceIri: IRI = aThingIri val propertyIri: SmartIri = "http://0.0.0.0:3333/ontology/0001/anything/v2#hasInteger".toSmartIri val permissions = "CR knora-admin:Creator" @@ -2733,7 +2733,7 @@ class ValuesResponderV2Spec extends CoreSpec with ImplicitSender { updatedValueFromTriplestore.permissions should ===(permissions) } - "not update a value, changing only its permissions, if the requesting user does not have ChangeRightsPermission on the value" in { + "not update a value, changing only its permissions, if the requesting user does not have ObjectAccessPermission.ChangeRights on the value" in { val resourceIri: IRI = aThingIri val propertyIri: SmartIri = "http://0.0.0.0:3333/ontology/0001/anything/v2#hasInteger".toSmartIri val permissions = "CR knora-admin:Creator" diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala index fa7e17eb5e..1de84f7dcd 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala @@ -38,7 +38,6 @@ import org.knora.webapi.messages.util.ConstructResponseUtilV2.ValueRdfData import org.knora.webapi.messages.util.ConstructResponseUtilV2.emptyFlatStatements import org.knora.webapi.messages.util.ConstructResponseUtilV2.emptyRdfPropertyValues import org.knora.webapi.messages.util.ConstructResponseUtilV2.emptyRdfResources -import org.knora.webapi.messages.util.PermissionUtilADM.EntityPermission import org.knora.webapi.messages.util.standoff.StandoffTagUtilV2 import org.knora.webapi.messages.v2.responder.listsmessages.NodeGetRequestV2 import org.knora.webapi.messages.v2.responder.listsmessages.NodeGetResponseV2 @@ -52,6 +51,7 @@ import org.knora.webapi.messages.v2.responder.standoffmessages.GetXSLTransformat import org.knora.webapi.messages.v2.responder.standoffmessages.MappingXMLtoStandoff import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.ProjectService import org.knora.webapi.slice.resources.IiifImageRequestUrl @@ -360,7 +360,7 @@ object ConstructResponseUtilV2 { valueObjectClass: SmartIri, nestedResource: Option[ResourceWithValueRdfData] = None, isIncomingLink: Boolean = false, - userPermission: EntityPermission, + userPermission: ObjectAccessPermission, assertions: FlatPredicateObjects, standoff: FlatStatements, ) extends RdfData @@ -378,7 +378,7 @@ object ConstructResponseUtilV2 { subjectIri: IRI, assertions: FlatPredicateObjects, isMainResource: Boolean, - userPermission: Option[EntityPermission], + userPermission: Option[ObjectAccessPermission], valuePropertyAssertions: RdfPropertyValues, ) extends RdfData @@ -412,7 +412,10 @@ object ConstructResponseUtilV2 { * @param assertions RDF assertions about the entity. * @param maybeUserPermission the user's permission on the entity, if any. */ - case class RdfWithUserPermission(assertions: ConstructPredicateObjects, maybeUserPermission: Option[EntityPermission]) + case class RdfWithUserPermission( + assertions: ConstructPredicateObjects, + maybeUserPermission: Option[ObjectAccessPermission], + ) } @@ -517,7 +520,7 @@ final case class ConstructResponseUtilV2Live( case (pred: SmartIri, objs: Seq[LiteralV2]) => pred -> objs.head } - val userPermission: Option[EntityPermission] = + val userPermission: Option[ObjectAccessPermission] = PermissionUtilADM.getUserPermissionFromConstructAssertionsADM(resourceIri, assertions, requestingUser) // Make a ResourceWithValueRdfData for each resource IRI. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/PermissionUtilADM.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/PermissionUtilADM.scala index 8ca69abf27..c0f7f4875b 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/PermissionUtilADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/PermissionUtilADM.scala @@ -36,77 +36,7 @@ import org.knora.webapi.slice.admin.domain.model.User */ object PermissionUtilADM extends LazyLogging { - // TODO: unify EntityPermission with PermissionADM. - - /** - * Represents a permission granted to a group on an entity. The `toString` method of an `EntityPermission` - * returns one of the codes in [[OntologyConstants.KnoraBase.EntityPermissionAbbreviations]]. - */ - sealed trait EntityPermission extends Ordered[EntityPermission] { - - def permission: ObjectAccessPermission - - /** - * Represents this [[EntityPermission]] as an integer, as required by Knora API v1. - */ - final def toInt: Int = permission.code - - override def compare(that: EntityPermission): Int = this.permission.code - that.permission.code - - final override def toString: String = permission.token - final def getName: String = permission.token - final def toPermissionADM(groupIri: IRI): PermissionADM = PermissionADM.from(permission, groupIri) - } - - /** - * Represents restricted view permission on an entity. - */ - case object RestrictedViewPermission extends EntityPermission { - override def permission: ObjectAccessPermission = ObjectAccessPermission.RestrictedView - } - - /** - * Represents unrestricted view permission on an entity. - */ - case object ViewPermission extends EntityPermission { - override def permission: ObjectAccessPermission = ObjectAccessPermission.View - } - - /** - * Represents modify permission on an entity. - */ - case object ModifyPermission extends EntityPermission { - override def permission: ObjectAccessPermission = ObjectAccessPermission.Modify - } - - /** - * Represents delete permission on an entity. - */ - case object DeletePermission extends EntityPermission { - override def permission: ObjectAccessPermission = ObjectAccessPermission.Delete - } - - /** - * Represents permission to change the permissions on an entity. - */ - case object ChangeRightsPermission extends EntityPermission { - override def permission: ObjectAccessPermission = ObjectAccessPermission.ChangeRights - } - - /** - * The highest permission, i.e. the one that is least restrictive. - */ - private val MaxPermissionLevel: EntityPermission = ChangeRightsPermission - - private val permissionStringsToPermissionLevels: Map[String, EntityPermission] = Set( - RestrictedViewPermission, - ViewPermission, - ModifyPermission, - DeletePermission, - ChangeRightsPermission, - ).map { level => - level.toString -> level - }.toMap + private val levelsByToken = ObjectAccessPermissions.all.map(level => level.token -> level).toMap /** * A set of assertions that are relevant for calculating permissions. @@ -137,11 +67,11 @@ object PermissionUtilADM extends LazyLogging { * on the entity. */ private def calculateHighestGrantedPermissionLevel( - entityPermissions: Map[EntityPermission, Set[IRI]], + entityPermissions: Map[ObjectAccessPermission, Set[IRI]], userGroups: Set[IRI], - ): Option[EntityPermission] = { + ): Option[ObjectAccessPermission] = { // Make a set of all the permissions the user can obtain for this entity. - val permissionLevels: Set[EntityPermission] = entityPermissions.foldLeft(Set.empty[EntityPermission]) { + val permissionLevels: Set[ObjectAccessPermission] = entityPermissions.foldLeft(Set.empty[ObjectAccessPermission]) { case (acc, (permissionLevel, grantedToGroups)) => if (grantedToGroups.intersect(userGroups).nonEmpty) { acc + permissionLevel @@ -160,13 +90,13 @@ object PermissionUtilADM extends LazyLogging { } /** - * Determines the permissions that a user has on a entity, and returns an [[EntityPermission]]. + * Determines the permissions that a user has on a entity, and returns an [[ObjectAccessPermission]]. * * @param entityCreator the IRI of the user that created the entity. * @param entityProject the IRI of the entity's project. * @param entityPermissionLiteral the literal that is the object of the entity's `knora-base:hasPermissions` predicate. * @param requestingUser the user making the request. - * @return an [[EntityPermission]] representing the user's permission level for the entity, or `None` if the user + * @return an [[ObjectAccessPermission]] representing the user's permission level for the entity, or `None` if the user * has no permissions on the entity. */ def getUserPermissionADM( @@ -174,16 +104,16 @@ object PermissionUtilADM extends LazyLogging { entityProject: IRI, entityPermissionLiteral: String, requestingUser: User, - ): Option[EntityPermission] = { + ): Option[ObjectAccessPermission] = { val maybePermissionLevel = if ( requestingUser.isSystemUser || requestingUser.isSystemAdmin || requestingUser.permissions .hasProjectAdminAllPermissionFor(entityProject) ) { // If the user is the system user, is in the SystemAdmin group, or has ProjectAdminAllPermission, just give them the maximum permission. - Some(MaxPermissionLevel) + Some(ObjectAccessPermission.maxPermission) } else { - val entityPermissions: Map[EntityPermission, Set[IRI]] = parsePermissions(entityPermissionLiteral) + val entityPermissions: Map[ObjectAccessPermission, Set[IRI]] = parsePermissions(entityPermissionLiteral) // Make a list of all the groups (both built-in and custom) that the user belongs to in relation // to the entity. @@ -264,14 +194,14 @@ object PermissionUtilADM extends LazyLogging { permissionLiteralB: String, requestingUser: User, ): PermissionComparisonResult = { - val maybePermissionA: Option[EntityPermission] = getUserPermissionADM( + val maybePermissionA: Option[ObjectAccessPermission] = getUserPermissionADM( entityCreator = requestingUser.id, entityProject = entityProject, entityPermissionLiteral = permissionLiteralA, requestingUser = requestingUser, ) - val maybePermissionB: Option[EntityPermission] = getUserPermissionADM( + val maybePermissionB: Option[ObjectAccessPermission] = getUserPermissionADM( entityCreator = requestingUser.id, entityProject = entityProject, entityPermissionLiteral = permissionLiteralB, @@ -283,7 +213,7 @@ object PermissionUtilADM extends LazyLogging { case (None, Some(_)) => ALessThanB case (Some(_), None) => AGreaterThanB - case (Some(permissionA: EntityPermission), Some(permissionB: EntityPermission)) => + case (Some(permissionA: ObjectAccessPermission), Some(permissionB: ObjectAccessPermission)) => if (permissionA == permissionB) { AEqualToB } else if (permissionA < permissionB) { @@ -296,7 +226,7 @@ object PermissionUtilADM extends LazyLogging { /** * Given data from a [[org.knora.webapi.messages.store.triplestoremessages.SparqlExtendedConstructResponse]], determines the permissions that a user has on a entity, - * and returns an [[EntityPermission]]. + * and returns an [[ObjectAccessPermission]]. * * @param entityIri the IRI of the entity. * @param assertions a [[Seq]] containing all the permission-relevant predicates and objects @@ -313,7 +243,7 @@ object PermissionUtilADM extends LazyLogging { entityIri: IRI, assertions: ConstructPredicateObjects, requestingUser: User, - ): Option[EntityPermission] = { + ): Option[ObjectAccessPermission] = { val assertionsAsStrings: Seq[(IRI, String)] = assertions.toSeq.flatMap { case (pred: SmartIri, objs: Seq[LiteralV2]) => objs.map { obj => @@ -329,7 +259,7 @@ object PermissionUtilADM extends LazyLogging { } /** - * Determines the permissions that a user has on a entity, and returns an [[EntityPermission]]. + * Determines the permissions that a user has on a entity, and returns an [[ObjectAccessPermission]]. * * @param entityIri the IRI of the entity. * @param assertions a [[Seq]] containing all the permission-relevant predicates and objects @@ -346,7 +276,7 @@ object PermissionUtilADM extends LazyLogging { entityIri: IRI, assertions: Seq[(IRI, String)], requestingUser: User, - ): Option[EntityPermission] = { + ): Option[ObjectAccessPermission] = { // Get the entity's creator, project, and permissions. val assertionMap: Map[IRI, String] = assertions.toMap @@ -376,16 +306,14 @@ object PermissionUtilADM extends LazyLogging { * Parses the literal object of the predicate `knora-base:hasPermissions`. * * @param permissionLiteral the literal to parse. - * @return a [[Map]] in which the keys are permission abbreviations in - * [[OntologyConstants.KnoraBase.EntityPermissionAbbreviations]], and the values are sets of - * user group IRIs. + * @return a [[Map]] in which the keys are permission tokens, and the values are sets of user group IRIs. */ def parsePermissions( permissionLiteral: String, errorFun: String => Nothing = { (permissionLiteral: String) => throw InconsistentRepositoryDataException(s"invalid permission literal: $permissionLiteral") }, - ): Map[EntityPermission, Set[IRI]] = { + ): Map[ObjectAccessPermission, Set[IRI]] = { val permissions: Seq[String] = permissionLiteral.split(OntologyConstants.KnoraBase.PermissionListDelimiter).toIndexedSeq @@ -397,16 +325,15 @@ object PermissionUtilADM extends LazyLogging { } val abbreviation: String = splitPermission(0) - - if (!ObjectAccessPermissions.allTokens.contains(abbreviation)) { - errorFun(permissionLiteral) - } + val perm = ObjectAccessPermission + .fromToken(abbreviation) + .getOrElse(errorFun(permissionLiteral)) val shortGroups: Set[String] = splitPermission(1).split(OntologyConstants.KnoraBase.GroupListDelimiter).toSet val groups = shortGroups.map( _.replace(OntologyConstants.KnoraAdmin.KnoraAdminPrefix, OntologyConstants.KnoraAdmin.KnoraAdminPrefixExpansion), ) - (permissionStringsToPermissionLevels(abbreviation), groups) + (perm, groups) }.toMap } @@ -414,8 +341,7 @@ object PermissionUtilADM extends LazyLogging { * Parses the literal object of the predicate `knora-base:hasPermissions`. * * @param maybePermissionListStr the literal to parse. - * @return a [[Map]] in which the keys are permission abbreviations in - * [[OntologyConstants.KnoraBase.EntityPermissionAbbreviations]], and the values are sets of + * @return a [[Map]] in which the keys are permission tokens, and the values are sets of * user group IRIs. */ def parsePermissionsWithType( @@ -602,7 +528,7 @@ object PermissionUtilADM extends LazyLogging { case PermissionType.OAP => if (permissions.nonEmpty) { - /* a map with permission names, shortened groups, and full group names. */ + /* a levelsByToken with permission names, shortened groups, and full group names. */ val groupedPermissions: Map[String, String] = permissions.groupBy(_.name).map { case (name: String, perms: Set[PermissionADM]) => val shortGroupsString = perms.toVector.sortBy(_.additionalInformation.get).foldLeft("") { @@ -624,7 +550,7 @@ object PermissionUtilADM extends LazyLogging { /* Sort permissions in descending order */ val sortedPermissions: Array[(String, String)] = groupedPermissions.toArray.sortWith { (left, right) => - permissionStringsToPermissionLevels(left._1) > permissionStringsToPermissionLevels(right._1) + levelsByToken(left._1) > levelsByToken(right._1) } /* create the permissions string */ @@ -672,7 +598,7 @@ object PermissionUtilADM extends LazyLogging { def impliesPermissionCodeV1(userHasPermissionCode: Option[Int], userNeedsPermission: String): Boolean = userHasPermissionCode match { case Some(permissionCode) => - permissionCode >= permissionStringsToPermissionLevels(userNeedsPermission).permission.code + permissionCode >= levelsByToken(userNeedsPermission).code case None => false } } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2.scala index c8b841ec88..9dc191e567 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2.scala @@ -24,7 +24,6 @@ import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.ValuesValidator.xsdDateTimeStampToInstant import org.knora.webapi.messages.admin.responder.projectsmessages.Project -import org.knora.webapi.messages.util.PermissionUtilADM.EntityPermission import org.knora.webapi.messages.util._ import org.knora.webapi.messages.util.rdf._ import org.knora.webapi.messages.util.standoff.StandoffTagUtilV2 @@ -35,6 +34,7 @@ import org.knora.webapi.messages.v2.responder.resourcemessages.CreateResourceReq import org.knora.webapi.messages.v2.responder.standoffmessages.MappingXMLtoStandoff import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.ProjectService import org.knora.webapi.slice.admin.domain.service.UserService @@ -383,7 +383,7 @@ case class ReadResourceV2( attachedToUser: IRI, projectADM: Project, permissions: String, - userPermission: EntityPermission, + userPermission: ObjectAccessPermission, values: Map[SmartIri, Seq[ReadValueV2]], creationDate: Instant, lastModificationDate: Option[Instant], diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala index e144a3a181..2fc4a0e4a2 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala @@ -31,7 +31,6 @@ import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.ValuesValidator import org.knora.webapi.messages.admin.responder.projectsmessages.Project -import org.knora.webapi.messages.util.PermissionUtilADM.EntityPermission import org.knora.webapi.messages.util._ import org.knora.webapi.messages.util.rdf._ import org.knora.webapi.messages.util.standoff.StandoffStringUtil @@ -46,6 +45,7 @@ import org.knora.webapi.routing.RouteUtilV2 import org.knora.webapi.routing.RouteUtilZ import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.resourceinfo.domain.IriConverter import org.knora.webapi.slice.resources.IiifImageRequestUrl @@ -342,7 +342,7 @@ sealed trait ReadValueV2 extends IOValueV2 { /** * The permission that the requesting user has on the value. */ - def userPermission: EntityPermission + def userPermission: ObjectAccessPermission /** * The date when the value was created. @@ -493,7 +493,7 @@ case class ReadTextValueV2( valueIri: IRI, attachedToUser: IRI, permissions: String, - userPermission: EntityPermission, + userPermission: ObjectAccessPermission, valueCreationDate: Instant, valueHasUUID: UUID, valueContent: TextValueContentV2, @@ -532,7 +532,7 @@ case class ReadLinkValueV2( valueIri: IRI, attachedToUser: IRI, permissions: String, - userPermission: EntityPermission, + userPermission: ObjectAccessPermission, valueCreationDate: Instant, valueHasUUID: UUID, valueContent: LinkValueContentV2, @@ -569,7 +569,7 @@ case class ReadOtherValueV2( valueIri: IRI, attachedToUser: IRI, permissions: String, - userPermission: EntityPermission, + userPermission: ObjectAccessPermission, valueCreationDate: Instant, valueHasUUID: UUID, valueContent: ValueContentV2, diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala index 08be54af4d..bc03b7b1b1 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala @@ -73,7 +73,7 @@ final case class AssetPermissionsResponder( PermissionUtilADM .getUserPermissionFromAssertionsADM(fileValueIriSubject.toString, assertions, requestingUser) - .map(_.permission.code) + .map(_.code) .getOrElse(0) } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala index da2614cb57..f519fccbc3 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala @@ -1674,7 +1674,7 @@ final case class PermissionsResponderADMLive( } if (permission.permissionCode.nonEmpty && permission.name.nonEmpty) { val code = permission.permissionCode.get - if (!ObjectAccessPermission.from(permission.name).map(_.code).contains(code)) { + if (!ObjectAccessPermission.fromToken(permission.name).map(_.code).contains(code)) { throw BadRequestException( s"Given permission code $code and permission name ${permission.name} are not consistent.", ) diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourceUtilV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourceUtilV2.scala index f3a51fe164..c7d25fe4f0 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourceUtilV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourceUtilV2.scala @@ -22,13 +22,13 @@ import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanent import org.knora.webapi.messages.twirl.queries.sparql import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.messages.util.PermissionUtilADM -import org.knora.webapi.messages.util.PermissionUtilADM.EntityPermission import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.messages.v2.responder.UpdateResultInProject import org.knora.webapi.messages.v2.responder.resourcemessages.ReadResourceV2 import org.knora.webapi.messages.v2.responder.valuemessages.FileValueContentV2 import org.knora.webapi.messages.v2.responder.valuemessages.ReadValueV2 import org.knora.webapi.messages.v2.responder.valuemessages.StillImageExternalFileValueContentV2 +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.store.triplestore.api.TriplestoreService import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Construct @@ -42,13 +42,13 @@ trait ResourceUtilV2 { * Checks that a user has the specified permission on a resource. * * @param resourceInfo the resource to be updated. - * @param permissionNeeded the necessary EntityPermission, + * @param permissionNeeded the necessary ObjectAccessPermission, * @param requestingUser the requesting user. * @return [[ForbiddenException]] if user does not have permission needed on the resource. */ def checkResourcePermission( resourceInfo: ReadResourceV2, - permissionNeeded: EntityPermission, + permissionNeeded: ObjectAccessPermission, requestingUser: User, ): IO[ForbiddenException, Unit] @@ -57,14 +57,14 @@ trait ResourceUtilV2 { * * @param resourceInfo the resource containing the value. * @param valueInfo the value to be updated. - * @param permissionNeeded the necessary EntityPermission, + * @param permissionNeeded the necessary ObjectAccessPermission, * @param requestingUser the requesting user. * @return [[ForbiddenException]] if user does not have permissions on the value. */ def checkValuePermission( resourceInfo: ReadResourceV2, valueInfo: ReadValueV2, - permissionNeeded: EntityPermission, + permissionNeeded: ObjectAccessPermission, requestingUser: User, ): IO[ForbiddenException, Unit] @@ -124,15 +124,15 @@ final case class ResourceUtilV2Live(triplestore: TriplestoreService, messageRela * Checks that a user has the specified permission on a resource. * * @param resourceInfo the resource to be updated. - * @param permissionNeeded the necessary EntityPermission, + * @param permissionNeeded the necessary ObjectAccessPermission, * @param requestingUser the requesting user. */ override def checkResourcePermission( resourceInfo: ReadResourceV2, - permissionNeeded: EntityPermission, + permissionNeeded: ObjectAccessPermission, requestingUser: User, ): IO[ForbiddenException, Unit] = { - val maybeUserPermission: Option[EntityPermission] = PermissionUtilADM.getUserPermissionADM( + val maybeUserPermission: Option[ObjectAccessPermission] = PermissionUtilADM.getUserPermissionADM( entityCreator = resourceInfo.attachedToUser, entityProject = resourceInfo.projectADM.id, entityPermissionLiteral = resourceInfo.permissions, @@ -140,14 +140,14 @@ final case class ResourceUtilV2Live(triplestore: TriplestoreService, messageRela ) val hasRequiredPermission: Boolean = maybeUserPermission match { - case Some(userPermission: EntityPermission) => userPermission >= permissionNeeded - case None => false + case Some(userPermission: ObjectAccessPermission) => userPermission >= permissionNeeded + case None => false } ZIO .fail( ForbiddenException( - s"User ${requestingUser.email} does not have ${permissionNeeded.getName} on resource <${resourceInfo.resourceIri}>", + s"User ${requestingUser.email} does not have ${permissionNeeded.token} on resource <${resourceInfo.resourceIri}>", ), ) .when(!hasRequiredPermission) @@ -159,16 +159,16 @@ final case class ResourceUtilV2Live(triplestore: TriplestoreService, messageRela * * @param resourceInfo the resource containing the value. * @param valueInfo the value to be updated. - * @param permissionNeeded the necessary EntityPermission, + * @param permissionNeeded the necessary ObjectAccessPermission, * @param requestingUser the requesting user. */ override def checkValuePermission( resourceInfo: ReadResourceV2, valueInfo: ReadValueV2, - permissionNeeded: EntityPermission, + permissionNeeded: ObjectAccessPermission, requestingUser: User, ): IO[ForbiddenException, Unit] = { - val maybeUserPermission: Option[EntityPermission] = PermissionUtilADM.getUserPermissionADM( + val maybeUserPermission: Option[ObjectAccessPermission] = PermissionUtilADM.getUserPermissionADM( entityCreator = valueInfo.attachedToUser, entityProject = resourceInfo.projectADM.id, entityPermissionLiteral = valueInfo.permissions, @@ -176,14 +176,14 @@ final case class ResourceUtilV2Live(triplestore: TriplestoreService, messageRela ) val hasRequiredPermission: Boolean = maybeUserPermission match { - case Some(userPermission: EntityPermission) => userPermission >= permissionNeeded - case None => false + case Some(userPermission: ObjectAccessPermission) => userPermission >= permissionNeeded + case None => false } ZIO .fail( ForbiddenException( - s"User ${requestingUser.email} does not have ${permissionNeeded.getName} on value <${valueInfo.valueIri}>", + s"User ${requestingUser.email} does not have ${permissionNeeded.token} on value <${valueInfo.valueIri}>", ), ) .when(!hasRequiredPermission) diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala index 5b59bbe739..81aaa40236 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala @@ -27,8 +27,6 @@ import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse import org.knora.webapi.messages.twirl.queries.sparql import org.knora.webapi.messages.util.ConstructResponseUtilV2.MappingAndXSLTransformation -import org.knora.webapi.messages.util.PermissionUtilADM.DeletePermission -import org.knora.webapi.messages.util.PermissionUtilADM.ModifyPermission import org.knora.webapi.messages.util._ import org.knora.webapi.messages.util.rdf._ import org.knora.webapi.messages.util.search.gravsearch.GravsearchParser @@ -45,6 +43,7 @@ import org.knora.webapi.responders.IriService import org.knora.webapi.responders.Responder import org.knora.webapi.responders.v2.resources.CreateResourceV2Handler import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.KnoraProjectService import org.knora.webapi.slice.admin.domain.service.ProjectService @@ -238,7 +237,7 @@ final case class ResourcesResponderV2( // Check that the user has permission to modify the resource. _ <- resourceUtilV2.checkResourcePermission( resource, - ModifyPermission, + ObjectAccessPermission.Modify, updateResourceMetadataRequestV2.requestingUser, ) @@ -383,7 +382,11 @@ final case class ResourcesResponderV2( } // Check that the user has permission to mark the resource as deleted. - _ <- resourceUtilV2.checkResourcePermission(resource, DeletePermission, deleteResourceV2.requestingUser) + _ <- resourceUtilV2.checkResourcePermission( + resource, + ObjectAccessPermission.Delete, + deleteResourceV2.requestingUser, + ) // Get the IRI of the named graph in which the resource is stored. dataNamedGraph = ProjectService.projectDataNamedGraphV2(resource.projectADM).value diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala index aa660efed1..15089c6e1d 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala @@ -38,6 +38,7 @@ import org.knora.webapi.messages.v2.responder.valuemessages._ import org.knora.webapi.responders.IriLocker import org.knora.webapi.responders.IriService import org.knora.webapi.responders.Responder +import org.knora.webapi.slice.admin.domain.model.ObjectAccessPermission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.ProjectService import org.knora.webapi.slice.ontology.domain.model.Cardinality.AtLeastOne @@ -177,7 +178,7 @@ final case class ValuesResponderV2Live( // Check that the user has permission to modify the resource. _ <- resourceUtilV2.checkResourcePermission( resourceInfo = resourceInfo, - permissionNeeded = ModifyPermission, + permissionNeeded = ObjectAccessPermission.Modify, requestingUser = requestingUser, ) @@ -1014,7 +1015,7 @@ final case class ValuesResponderV2Live( // Validate and reformat the submitted permissions. newValuePermissionLiteral <- permissionUtilADM.validatePermissions(updateValuePermissionsV2.permissions) - // Check that the user has ChangeRightsPermission on the value, and that the new permissions are + // Check that the user has ObjectAccessPermission.ChangeRights on the value, and that the new permissions are // different from the current ones. currentPermissionsParsed <- ZIO.attempt(PermissionUtilADM.parsePermissions(currentValue.permissions)) newPermissionsParsed <- @@ -1032,7 +1033,7 @@ final case class ValuesResponderV2Live( _ <- resourceUtilV2.checkValuePermission( resourceInfo = resourceInfo, valueInfo = currentValue, - permissionNeeded = ChangeRightsPermission, + permissionNeeded = ObjectAccessPermission.ChangeRights, requestingUser = requestingUser, ) @@ -1102,7 +1103,7 @@ final case class ValuesResponderV2Live( } // Check that the user has permission to do the update. If they want to change the permissions - // on the value, they need ChangeRightsPermission, otherwise they need ModifyPermission. + // on the value, they need ObjectAccessPermission.ChangeRights, otherwise they need ObjectAccessPermission.Modify. currentPermissionsParsed <- ZIO.attempt(PermissionUtilADM.parsePermissions(currentValue.permissions)) newPermissionsParsed <- ZIO.attempt( @@ -1113,8 +1114,8 @@ final case class ValuesResponderV2Live( ) permissionNeeded = - if (newPermissionsParsed != currentPermissionsParsed) { ChangeRightsPermission } - else { ModifyPermission } + if (newPermissionsParsed != currentPermissionsParsed) { ObjectAccessPermission.ChangeRights } + else { ObjectAccessPermission.Modify } _ <- resourceUtilV2.checkValuePermission( resourceInfo = resourceInfo, @@ -1172,7 +1173,7 @@ final case class ValuesResponderV2Live( // check that the user has permission to modify the resource. resourceUtilV2.checkResourcePermission( resourceInfo = resourceInfo, - permissionNeeded = ModifyPermission, + permissionNeeded = ObjectAccessPermission.Modify, requestingUser = requestingUser, ) @@ -1596,7 +1597,7 @@ final case class ValuesResponderV2Live( _ <- resourceUtilV2.checkValuePermission( resourceInfo = resourceInfo, valueInfo = currentValue, - permissionNeeded = DeletePermission, + permissionNeeded = ObjectAccessPermission.Delete, requestingUser, ) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/ObjectAccessPermissions.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/ObjectAccessPermissions.scala index 6c21444f56..9bdc36c7a3 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/ObjectAccessPermissions.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/ObjectAccessPermissions.scala @@ -46,8 +46,8 @@ object ObjectAccessPermission { val maxPermission: ObjectAccessPermission = ChangeRights def from(code: Int): Option[ObjectAccessPermission] = ObjectAccessPermissions.all.find(_.code == code) - def from(shortString: String): Option[ObjectAccessPermission] = - ObjectAccessPermissions.all.find(_.token == shortString) + def fromToken(token: String): Option[ObjectAccessPermission] = + ObjectAccessPermissions.all.find(_.token == token) } object ObjectAccessPermissions {