Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract away the fetching of ACLs from the AclCheck trait #4810

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
)
Comment on lines +61 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer

}

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