-
Notifications
You must be signed in to change notification settings - Fork 24
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
Improve error messages for starting jobs on other orgs datasets #8181
Changes from all commits
4f83da0
bae19f9
69d5b43
ff0d6d1
5815fab
841f8a7
4a36ac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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} | ||||||||||||||||
|
@@ -18,6 +19,7 @@ import scala.concurrent.ExecutionContext | |||||||||||||||
import com.scalableminds.util.time.Instant | ||||||||||||||||
import models.aimodels.AiModelCategory.AiModelCategory | ||||||||||||||||
import models.organization.OrganizationDAO | ||||||||||||||||
import play.api.i18n.Messages | ||||||||||||||||
|
||||||||||||||||
case class TrainingAnnotationSpecification(annotationId: ObjectId, | ||||||||||||||||
colorLayerName: String, | ||||||||||||||||
|
@@ -41,6 +43,7 @@ object RunTrainingParameters { | |||||||||||||||
case class RunInferenceParameters(annotationId: Option[ObjectId], | ||||||||||||||||
aiModelId: ObjectId, | ||||||||||||||||
datasetName: String, | ||||||||||||||||
organizationId: String, | ||||||||||||||||
colorLayerName: String, | ||||||||||||||||
boundingBox: String, | ||||||||||||||||
newDatasetName: String, | ||||||||||||||||
|
@@ -135,6 +138,7 @@ class AiModelController @Inject()( | |||||||||||||||
firstAnnotationId <- trainingAnnotations.headOption.map(_.annotationId).toFox | ||||||||||||||||
annotation <- annotationDAO.findOne(firstAnnotationId) | ||||||||||||||||
dataset <- datasetDAO.findOne(annotation._dataset) | ||||||||||||||||
_ <- bool2Fox(request.identity._organization == dataset._organization) ?~> "job.trainModel.notAllowed.organization" ~> FORBIDDEN | ||||||||||||||||
dataStore <- dataStoreDAO.findOneByName(dataset._dataStore) ?~> "dataStore.notFound" | ||||||||||||||||
_ <- Fox | ||||||||||||||||
.serialCombined(request.body.trainingAnnotations.map(_.annotationId))(annotationDAO.findOne) ?~> "annotation.notFound" | ||||||||||||||||
|
@@ -172,8 +176,13 @@ class AiModelController @Inject()( | |||||||||||||||
sil.SecuredAction.async(validateJson[RunInferenceParameters]) { implicit request => | ||||||||||||||||
for { | ||||||||||||||||
_ <- userService.assertIsSuperUser(request.identity) | ||||||||||||||||
organization <- organizationDAO.findOne(request.identity._organization) | ||||||||||||||||
dataset <- datasetDAO.findOneByNameAndOrganization(request.body.datasetName, organization._id) | ||||||||||||||||
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) | ||||||||||||||||
Comment on lines
+183
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit organization validation for inference jobs While the code validates the dataset belongs to the organization during lookup, it should have an explicit organization check similar to dataset <- datasetDAO.findOneByNameAndOrganization(request.body.datasetName, organization._id) ?~>
Messages("dataset.notFound", request.body.datasetName)
+ _ <- bool2Fox(request.identity._organization == dataset._organization) ?~> "job.inferWithModel.notAllowed.organization" ~> FORBIDDEN
dataStore <- dataStoreDAO.findOneByName(dataset._dataStore) ?~> "dataStore.notFound" 📝 Committable suggestion
Suggested change
|
||||||||||||||||
dataStore <- dataStoreDAO.findOneByName(dataset._dataStore) ?~> "dataStore.notFound" | ||||||||||||||||
_ <- aiModelDAO.findOne(request.body.aiModelId) ?~> "aiModel.notFound" | ||||||||||||||||
_ <- datasetService.assertValidDatasetName(request.body.newDatasetName) | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Issue:
organizationId
parameter not passed inrunInferenceJob
callsorganizationId
is not included in anyrunInferenceJob
function calls in the frontend code, potentially leading to missing organization validation.🔗 Analysis chain
LGTM: Added organizationId parameter for explicit organization validation
The addition of organizationId parameter enables proper organization validation before running inference jobs. This aligns with the PR objective of improving error handling for cross-organization access attempts.
Let's verify that the frontend is updated to pass this new parameter:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 246
Script:
Length of output: 58
Script:
Length of output: 336