From 9a917592c7e1655d8cca642e1df26e5bc14c0fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 1 Jul 2024 16:33:12 +0200 Subject: [PATCH] fix: The GroupIri should allow "knora-admin:" prefixed iris and expand it (#3301) --- .../webapi/slice/admin/domain/model/KnoraGroup.scala | 7 ++++--- .../webapi/slice/admin/domain/model/GroupIriSpec.scala | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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..d74e085c78 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 @@ -103,9 +103,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..b8100713c8 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,17 +5,27 @@ package org.knora.webapi.slice.admin.domain.model +import zio.Chunk import zio.test.Gen import zio.test.Spec import zio.test.ZIOSpecDefault import zio.test.assertTrue import zio.test.check +import org.knora.webapi.messages.OntologyConstants.KnoraAdmin.KnoraAdminPrefixExpansion + object GroupIriSpec extends ZIOSpecDefault { override val spec: Spec[Any, Nothing] = suite("GroupIri should")( 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(