diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/KnoraGroup.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/KnoraGroup.scala index 0ecdc83cdd..ff3d74ebf4 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/KnoraGroup.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/KnoraGroup.scala @@ -11,7 +11,6 @@ import sttp.tapir.CodecFormat import zio.Chunk import zio.json.DeriveJsonCodec import zio.json.JsonCodec - import dsp.valueobjects.Iri import dsp.valueobjects.UuidUtil import org.knora.webapi.IRI @@ -103,9 +102,10 @@ object GroupIri extends StringValueCompanion[GroupIri] { private def isBuiltInGroupIri(iri: String): Boolean = BuiltInGroups.contains(iri) def from(value: String): Either[String, GroupIri] = value match { - case _ if value.isEmpty => Left("Group IRI cannot be empty.") - case _ if isGroupIriValid(value) => Right(GroupIri(value)) - case v => Left(s"Group IRI is invalid: $v") + case _ if value.isEmpty => Left("Group IRI cannot be empty.") + case _ if value.startsWith("knora-admin:") => from(value.replace("knora-admin:", KnoraAdminPrefixExpansion)) + case _ if isGroupIriValid(value) => Right(GroupIri(value)) + case v => Left(s"Group IRI is invalid: $v") } /** diff --git a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/GroupIriSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/GroupIriSpec.scala index 1e145981a3..940ee6121f 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/GroupIriSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/model/GroupIriSpec.scala @@ -5,6 +5,8 @@ package org.knora.webapi.slice.admin.domain.model +import org.knora.webapi.messages.OntologyConstants.KnoraAdmin.KnoraAdminPrefixExpansion +import zio.Chunk import zio.test.Gen import zio.test.Spec import zio.test.ZIOSpecDefault @@ -16,6 +18,13 @@ object GroupIriSpec extends ZIOSpecDefault { test("not be created from an empty value") { assertTrue(GroupIri.from("") == Left("Group IRI cannot be empty.")) }, + test("allow prefixed builtin GroupIris") { + val builtIn = Chunk("UnknownUser", "KnownUser", "Creator", "ProjectMember", "ProjectAdmin", "SystemAdmin") + .map("knora-admin:" + _) + check(Gen.fromIterable(builtIn)) { it => + assertTrue(GroupIri.from(it).map(_.value) == Right(it.replace("knora-admin:", KnoraAdminPrefixExpansion))) + } + }, test("be created from a valid value") { val validIris = Gen.fromIterable( Seq(