From 5ef5ab63d1ee5095b72631428fcf5842a03fb129 Mon Sep 17 00:00:00 2001 From: Florian M Date: Wed, 9 Nov 2022 16:01:16 +0100 Subject: [PATCH] Allow viewing vx workflows via link if organization matches --- CHANGELOG.unreleased.md | 1 + app/controllers/VoxelyticsController.scala | 14 ++++++++++---- app/models/voxelytics/VoxelyticsDAO.scala | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 798d5c4bc69..7e03242f809 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -24,6 +24,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - Jobs can no longer be started on datastores without workers. [#6595](https://github.com/scalableminds/webknossos/pull/6595) - When downloading volume annotations with volume data skipped, the nml volume tag is now included anyway (but has no location attribute in this case). [#6566](https://github.com/scalableminds/webknossos/pull/6566) - Re-phrased some backend (error) messages to improve clarity and provide helping hints. [#6616](https://github.com/scalableminds/webknossos/pull/6616) +- Voxelytics workflows can now be viewed by anyone with the link who is in the right organization. [#6622](https://github.com/scalableminds/webknossos/pull/6622) ### Fixed - Fixed importing a dataset from disk. [#6615](https://github.com/scalableminds/webknossos/pull/6615) diff --git a/app/controllers/VoxelyticsController.scala b/app/controllers/VoxelyticsController.scala index a15e5a1b106..d42c2c0a5a1 100644 --- a/app/controllers/VoxelyticsController.scala +++ b/app/controllers/VoxelyticsController.scala @@ -61,7 +61,7 @@ class VoxelyticsController @Inject()( for { _ <- bool2Fox(wkConf.Features.voxelyticsEnabled) ?~> "voxelytics.disabled" // Auth is implemented in `voxelyticsDAO.findRuns` - runs <- voxelyticsDAO.findRuns(request.identity, None, workflowHash, conf.staleTimeout) + runs <- voxelyticsDAO.findRuns(request.identity, None, workflowHash, conf.staleTimeout, allowUnlisted = false) result <- if (runs.nonEmpty) { listWorkflowsWithRuns(request, runs) } else { @@ -113,9 +113,15 @@ class VoxelyticsController @Inject()( // If all runs are fetched, a combined version of the workflow report // will be returned that contains the information of the most recent task runs runs <- runIdValidatedOpt - .map(runIdValidated => - voxelyticsDAO.findRuns(request.identity, Some(List(runIdValidated)), Some(workflowHash), conf.staleTimeout)) - .getOrElse(voxelyticsDAO.findRuns(request.identity, None, Some(workflowHash), conf.staleTimeout)) + .map( + runIdValidated => + voxelyticsDAO.findRuns(request.identity, + Some(List(runIdValidated)), + Some(workflowHash), + conf.staleTimeout, + allowUnlisted = true)) + .getOrElse( + voxelyticsDAO.findRuns(request.identity, None, Some(workflowHash), conf.staleTimeout, allowUnlisted = true)) _ <- bool2Fox(runs.nonEmpty) ?~> "voxelytics.runNotFound" ~> NOT_FOUND sortedRuns = runs.sortBy(_.beginTime).reverse // All workflows have at least one run, because they are created at the same time diff --git a/app/models/voxelytics/VoxelyticsDAO.scala b/app/models/voxelytics/VoxelyticsDAO.scala index ea2b9089496..588261c087c 100644 --- a/app/models/voxelytics/VoxelyticsDAO.scala +++ b/app/models/voxelytics/VoxelyticsDAO.scala @@ -195,9 +195,11 @@ class VoxelyticsDAO @Inject()(sqlClient: SQLClient)(implicit ec: ExecutionContex def findRuns(currentUser: User, runIds: Option[List[ObjectId]], workflowHash: Option[String], - staleTimeout: Duration): Fox[List[RunEntry]] = { + staleTimeout: Duration, + allowUnlisted: Boolean): Fox[List[RunEntry]] = { val organizationId = currentUser._organization - val readAccessQ = if (currentUser.isAdmin) { "" } else { s" AND (r._user = ${escapeLiteral(currentUser._id.id)})" } + val readAccessQ = + if (currentUser.isAdmin || allowUnlisted) "" else { s" AND (r._user = ${escapeLiteral(currentUser._id.id)})" } val runIdsQ = runIds.map(runIds => s" AND r._id IN ${writeEscapedTuple(runIds.map(_.id))}").getOrElse("") val workflowHashQ = workflowHash.map(workflowHash => s" AND r.workflow_hash = ${escapeLiteral(workflowHash)}").getOrElse("")