From bb58d3416c8dc975414853cd9b49eed41b97ad83 Mon Sep 17 00:00:00 2001 From: Simon Dumas Date: Fri, 4 Aug 2023 14:39:07 +0200 Subject: [PATCH] Address feedback --- .../nexus/delta/routes/MultiFetchRoutes.scala | 15 --------------- .../delta/routes/MultiFetchRoutesSpec.scala | 2 +- .../delta/sdk/multifetch/MultiFetch.scala | 18 ++++++++---------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutes.scala b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutes.scala index 578d6b87b0..9af9590cb5 100644 --- a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutes.scala +++ b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutes.scala @@ -46,18 +46,3 @@ class MultiFetchRoutes( } } - -object MultiFetchRoutes { - - /** - * @return - * the [[Route]] for the multi-fetch operation - */ - def apply(identities: Identities, aclCheck: AclCheck, multiFetch: MultiFetch)(implicit - baseUri: BaseUri, - cr: RemoteContextResolution, - ordering: JsonKeyOrdering, - s: Scheduler - ): Route = new MultiFetchRoutes(identities, aclCheck, multiFetch).routes - -} diff --git a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutesSpec.scala b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutesSpec.scala index ff1b3e44c9..7e64b16f90 100644 --- a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutesSpec.scala +++ b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/MultiFetchRoutesSpec.scala @@ -55,7 +55,7 @@ class MultiFetchRoutesSpec extends BaseRouteSpec { ) private val routes = Route.seal( - MultiFetchRoutes(identities, aclCheck, multiFetch) + new MultiFetchRoutes(identities, aclCheck, multiFetch).routes ) "The Multi fetch route" should { diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/multifetch/MultiFetch.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/multifetch/MultiFetch.scala index 5fa97fb392..22bcbee928 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/multifetch/MultiFetch.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/multifetch/MultiFetch.scala @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.sdk.multifetch import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdContent -import ch.epfl.bluebrain.nexus.delta.sdk.multifetch.model.MultiFetchResponse.Result import ch.epfl.bluebrain.nexus.delta.sdk.multifetch.model.MultiFetchResponse.Result._ import ch.epfl.bluebrain.nexus.delta.sdk.multifetch.model.{MultiFetchRequest, MultiFetchResponse} import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources @@ -33,15 +32,14 @@ object MultiFetch { val fetchAllCached = aclCheck.fetchAll.memoizeOnSuccess request.resources .traverse { input => - for { - authorized <- aclCheck.authorizeFor(input.project, resources.read, fetchAllCached) - resource <- if (authorized) fetchResource(input) else UIO.none - } yield { - if (authorized) resource.fold[Result](NotFound(input.id, input.project)) { content => - Success(input.id, input.project, content) - } - else - AuthorizationFailed(input.id, input.project) + aclCheck.authorizeFor(input.project, resources.read, fetchAllCached).flatMap { + case true => + fetchResource(input).map { + _.map(Success(input.id, input.project, _)) + .getOrElse(NotFound(input.id, input.project)) + } + case false => + UIO.pure(AuthorizationFailed(input.id, input.project)) } } .map { resources =>