From 5815fab6501c5e77b39a75807cd8fb97e1dcad12 Mon Sep 17 00:00:00 2001 From: frcroth Date: Wed, 13 Nov 2024 11:47:07 +0100 Subject: [PATCH] Provide dataset org from frontend for run Inference job --- app/controllers/AiModelController.scala | 7 ++++++- conf/messages | 2 +- frontend/javascripts/admin/api/jobs.ts | 1 + .../oxalis/view/action-bar/starting_job_modals.tsx | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/AiModelController.scala b/app/controllers/AiModelController.scala index 4e8078aacd..c8c2e9f204 100644 --- a/app/controllers/AiModelController.scala +++ b/app/controllers/AiModelController.scala @@ -1,5 +1,6 @@ package controllers +import com.scalableminds.util.accesscontext.GlobalAccessContext import com.scalableminds.util.geometry.{BoundingBox, Vec3Int} import com.scalableminds.util.tools.{Fox, FoxImplicits} import models.aimodels.{AiInference, AiInferenceDAO, AiInferenceService, AiModel, AiModelDAO, AiModelService} @@ -42,6 +43,7 @@ object RunTrainingParameters { case class RunInferenceParameters(annotationId: Option[ObjectId], aiModelId: ObjectId, datasetName: String, + organizationId: String, colorLayerName: String, boundingBox: String, newDatasetName: String, @@ -174,7 +176,10 @@ class AiModelController @Inject()( sil.SecuredAction.async(validateJson[RunInferenceParameters]) { implicit request => for { _ <- userService.assertIsSuperUser(request.identity) - organization <- organizationDAO.findOne(request.identity._organization) + organization <- organizationDAO.findOne(request.body.organizationId)(GlobalAccessContext) ?~> Messages( + "organization.notFound", + request.body.organizationId) + _ <- bool2Fox(request.identity._organization == organization._id) ?~> "job.runInference.notAllowed.organization" ~> FORBIDDEN dataset <- datasetDAO.findOneByNameAndOrganization(request.body.datasetName, organization._id) ?~> Messages( "dataset.notFound", request.body.datasetName) diff --git a/conf/messages b/conf/messages index bd4288cde7..34aa12fa2a 100644 --- a/conf/messages +++ b/conf/messages @@ -332,9 +332,9 @@ job.noWorkerForDatastoreAndJob = No webknossos-worker supporting the requested j job.emailNotifactionsDisabled = Email notifications are not enabled for this job type. job.renderAnimation.notAllowed.organization = Rendering animations is only allowed for datasets of your own organization. job.alignSections.notAllowed.organization = Aligning sections is only allowed for datasets of your own organization. -job.alignSections.notAllowed.onlySuperUsers = For now, aligning sections is only allowed for super users. job.additionalCoordinates.invalid = The passed additional coordinates are invalid. job.trainModel.notAllowed.organization = Training AI models is only allowed for datasets of your own organization. +job.runInference.notAllowed.organization = Running inference is only allowed for datasets of your own organization. voxelytics.disabled = Voxelytics workflow reporting and logging are not enabled for this WEBKNOSSOS instance. voxelytics.runNotFound = Workflow runs not found diff --git a/frontend/javascripts/admin/api/jobs.ts b/frontend/javascripts/admin/api/jobs.ts index 99d1c6e1bf..796ee43352 100644 --- a/frontend/javascripts/admin/api/jobs.ts +++ b/frontend/javascripts/admin/api/jobs.ts @@ -348,6 +348,7 @@ type RunInferenceParameters = { annotationId?: string; aiModelId: string; datasetName: string; + organizationId: string; colorLayerName: string; boundingBox: Vector6; newDatasetName: string; diff --git a/frontend/javascripts/oxalis/view/action-bar/starting_job_modals.tsx b/frontend/javascripts/oxalis/view/action-bar/starting_job_modals.tsx index a7b75bad1f..a3f071a2fb 100644 --- a/frontend/javascripts/oxalis/view/action-bar/starting_job_modals.tsx +++ b/frontend/javascripts/oxalis/view/action-bar/starting_job_modals.tsx @@ -829,6 +829,7 @@ function CustomAiModelInferenceForm() { aiModelId: form.getFieldValue("aiModel"), workflowYaml: useCustomWorkflow ? form.getFieldValue("workflowYaml") : undefined, datasetName: dataset.name, + organizationId: dataset.owningOrganization, colorLayerName: colorLayer.name, boundingBox, newDatasetName: newDatasetName,