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 (#3301)
  • Loading branch information
seakayone authored Jul 1, 2024
1 parent 9aad48e commit 9a91759
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

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

0 comments on commit 9a91759

Please sign in to comment.