Skip to content

Commit

Permalink
fix: The GroupIri should allow "knora-admin:" prefixed iris and expan…
Browse files Browse the repository at this point in the history
…d it
  • Loading branch information
seakayone committed Jul 1, 2024
1 parent 923a7b0 commit d3b77e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit d3b77e8

Please sign in to comment.