Skip to content

Commit

Permalink
refactor: Remove GroupsResponderADM (DEV-3292) (#3213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 authored Apr 25, 2024
1 parent 8e57ada commit 8d2b5ba
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ object LayersTest {
GravsearchTypeInspectionRunner &
GroupRestService &
GroupService &
GroupsResponderADM &
HttpServer &
IIIFRequestMessageHandler &
InferenceOptimizationService &
Expand Down Expand Up @@ -160,7 +159,6 @@ object LayersTest {
ConstructTransformer.layer,
DspIngestClientLive.layer,
GravsearchTypeInspectionRunner.layer,
GroupsResponderADM.layer,
HandlerMapper.layer,
HttpServer.layer,
IIIFRequestMessageHandlerLive.layer,
Expand Down
2 changes: 0 additions & 2 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ object LayersLive {
GravsearchTypeInspectionRunner &
GroupRestService &
GroupService &
GroupsResponderADM &
HttpServer &
IIIFRequestMessageHandler &
InferenceOptimizationService &
Expand Down Expand Up @@ -149,7 +148,6 @@ object LayersLive {
ConstructTransformer.layer,
DspIngestClientLive.layer,
GravsearchTypeInspectionRunner.layer,
GroupsResponderADM.layer,
HandlerMapper.layer,
HttpServer.layer,
IIIFRequestMessageHandlerLive.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,10 @@ import spray.json.DefaultJsonProtocol
import spray.json.JsonFormat
import spray.json.RootJsonFormat

import org.knora.webapi.IRI
import org.knora.webapi.core.RelayedMessage
import org.knora.webapi.messages.ResponderRequest.KnoraRequestADM
import org.knora.webapi.messages.admin.responder.AdminKnoraResponseADM
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectsADMJsonProtocol
import org.knora.webapi.slice.admin.domain.model.Group

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Messages

/**
* An abstract trait representing a request message that can be sent to 'GroupsResponderADM'.
*/
sealed trait GroupsResponderRequestADM extends KnoraRequestADM with RelayedMessage

/**
* Get everything about a multiple groups identified by their IRIs. The response will be a
* [[Set[GroupGetResponseADM] ]], or an error if one or more groups was not found.
*
* @param groupIris the IRIs of the groups being requested
*/
case class MultipleGroupsGetRequestADM(
groupIris: Set[IRI],
) extends GroupsResponderRequestADM

// Responses
/**
* Represents the Knora API v1 JSON response to a request for information about all groups.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ import zio.ZLayer

import dsp.errors.BadRequestException
import dsp.errors.InconsistentRepositoryDataException
import dsp.valueobjects.Iri
import dsp.errors.NotFoundException
import org.knora.webapi.IRI
import org.knora.webapi.core.MessageRelay
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.SmartIri
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.admin.responder.groupsmessages.GroupGetResponseADM
import org.knora.webapi.messages.admin.responder.groupsmessages.MultipleGroupsGetRequestADM
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionADM
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionType
import org.knora.webapi.messages.store.triplestoremessages.LiteralV2
import org.knora.webapi.messages.store.triplestoremessages.SparqlExtendedConstructResponse.ConstructPredicateObjects
import org.knora.webapi.messages.util.PermissionUtilADM.formatPermissionADMs
import org.knora.webapi.messages.util.PermissionUtilADM.parsePermissions
import org.knora.webapi.slice.admin.domain.model.GroupIri
import org.knora.webapi.slice.admin.domain.model.Permission
import org.knora.webapi.slice.admin.domain.model.User
import org.knora.webapi.slice.admin.domain.service.GroupService
import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo

/**
Expand Down Expand Up @@ -541,8 +539,7 @@ trait PermissionUtilADM {
def validatePermissions(permissionLiteral: String): Task[String]
}

final case class PermissionUtilADMLive(messageRelay: MessageRelay, stringFormatter: StringFormatter)
extends PermissionUtilADM {
final case class PermissionUtilADMLive(groupService: GroupService) extends PermissionUtilADM {

/**
* Given a permission literal, checks that it refers to valid permissions and groups.
Expand All @@ -564,18 +561,17 @@ final case class PermissionUtilADMLive(messageRelay: MessageRelay, stringFormatt
)

// Get the group IRIs that are mentioned, minus the built-in groups.
projectSpecificGroupIris: Set[IRI] =
projectSpecificGroupIris =
parsedPermissions.values.flatten.toSet -- KnoraGroupRepo.builtIn.all.map(_.id.value)

validatedProjectSpecificGroupIris <-
ZIO.attempt(
projectSpecificGroupIris.map(iri =>
Iri.validateAndEscapeIri(iri).getOrElse(throw BadRequestException(s"Invalid group IRI: $iri")),
),
)
irisToCheck = projectSpecificGroupIris.map(iri => GroupIri.unsafeFrom(iri)).toSeq

// Check that those groups exist.
_ <- messageRelay.ask[Set[GroupGetResponseADM]](MultipleGroupsGetRequestADM(validatedProjectSpecificGroupIris))
_ <- ZIO.foreach(irisToCheck)(iri =>
groupService
.findById(iri)
.someOrFail(NotFoundException(s"Group <$iri> not found.")),
)

// Reformat the permission literal.
permissionADMs: Set[PermissionADM] = parsedPermissions.flatMap { case (entityPermission, groupIris) =>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8d2b5ba

Please sign in to comment.