Skip to content

Commit

Permalink
Abstract away the fetching of ACLs from the AclCheck trait (#4810)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Mar 28, 2024
1 parent 7b14da6 commit 644cd9c
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.routes
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.{Directive1, Route}
import cats.effect.IO
import cats.effect.unsafe.implicits._
import cats.implicits._
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder
Expand All @@ -12,8 +11,8 @@ import ch.epfl.bluebrain.nexus.delta.routes.OrganizationsRoutes.OrganizationInpu
import ch.epfl.bluebrain.nexus.delta.sdk.OrganizationResource
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.circe.CirceUnmarshalling
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaDirectives._
import ch.epfl.bluebrain.nexus.delta.sdk.directives.AuthDirectives
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaDirectives._
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
Expand Down Expand Up @@ -59,17 +58,15 @@ final class OrganizationsRoutes(
import baseUri.prefixSegment

private def orgsSearchParams(implicit caller: Caller): Directive1[OrganizationSearchParams] =
onSuccess(aclCheck.fetchAll.unsafeToFuture()).flatMap { allAcls =>
(searchParams & parameter("label".?)).tmap { case (deprecated, rev, createdBy, updatedBy, label) =>
OrganizationSearchParams(
deprecated,
rev,
createdBy,
updatedBy,
label,
org => aclCheck.authorizeFor(org.label, orgs.read, allAcls)
)
}
(searchParams & parameter("label".?)).tmap { case (deprecated, rev, createdBy, updatedBy, label) =>
OrganizationSearchParams(
deprecated,
rev,
createdBy,
updatedBy,
label,
org => aclCheck.authorizeFor(org.label, orgs.read)
)
}

private def emitMetadata(value: IO[OrganizationResource]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ final class ProjectsRoutes(
implicit val paginationConfig: PaginationConfig = config.pagination

private def projectsSearchParams(implicit caller: Caller): Directive1[ProjectSearchParams] = {
onSuccess(aclCheck.fetchAll.unsafeToFuture()).flatMap { allAcls =>
(searchParams & parameter("label".?)).tmap { case (deprecated, rev, createdBy, updatedBy, label) =>
ProjectSearchParams(
None,
deprecated,
rev,
createdBy,
updatedBy,
label,
proj => aclCheck.authorizeFor(proj.ref, ReadProjects, allAcls)
)
}
(searchParams & parameter("label".?)).tmap { case (deprecated, rev, createdBy, updatedBy, label) =>
ProjectSearchParams(
None,
deprecated,
rev,
createdBy,
updatedBy,
label,
proj => aclCheck.authorizeFor(proj.ref, ReadProjects)
)
}
}

Expand Down
Loading

0 comments on commit 644cd9c

Please sign in to comment.