Skip to content

Commit 6c6ec24

Browse files
fm3normanrzMichaelBuessemeyer
authored
Make organization name its id, drop the mongo id (#7386)
* WIP: make organization name its id, drop the mongo id * more usages * Update LokiClient.scala * fix compiler errors after merge * prune scala usages of organizationName * fix migration guide * prune frontend usages of organizationName * prune frontend usages of organization.name * fix data type of orga references * sql check, fix delete organization * WIP: Add migration and revision * format backend * enable backend to parse old analytics schema for ingest events * format backend * update schema version * finish first version of migration and revision * fix schema & migration - give explicit name to constraints to make the name more consistent and less implicit * add migration for analyticsEvents' eventProperties * add organizationName to LinkedLayerIdentifier to make it backwards compatible * add legacy route to list datasets supporting the old get param organizationName when filtering for specific datasets & bump api version * dont use direct get on box and throw jserror when no orgaid or organame is defined in analytics event * format backend * remove comments from evolution files & fix schema version * fix migration, remove old now duplicate unique index * readd unique contraint in reversion * in reversion: migrate local join orga, open dataset & uplaod dataset back * in reversion: fix fk constraints and views * in reversion: fix user infos view * migrate new code pulled in by merge to use orgaId and not name * format backend * update schema version & include warning in reversion * rename organizationDisplayName to organizationName * add changelog entry * add migration entry * remove auto generated message files for data and tracingstore * update e2e db fixtures / initial db data * rename left over orgDisplayName variable to orgName * update snapshots to use new e2e your name last names * fix typo and format code * more relaxed analytics json reads * drop default for id column * add missing redirect to versioned.routes * rename migration, undo changing worker job args --------- Co-authored-by: Norman Rzepka <code@normanrz.com> Co-authored-by: Michael Büßemeyer <michael.buessemeyer@student.hpi.de> Co-authored-by: Michael Büßemeyer <MichaelBuessemeyer@users.noreply.github.com>
1 parent 54db378 commit 6c6ec24

File tree

146 files changed

+1643
-1341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1643
-1341
lines changed

CHANGELOG.unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
4242
- The warning about a mismatch between the scale of a pre-computed mesh and the dataset scale's factor now also considers all supported mags of the active segmentation layer. This reduces the false posive rate regarding this warning. [#7921](https://github.com/scalableminds/webknossos/pull/7921/)
4343
- It is no longer allowed to edit annotations of other organizations, even if they are set to public and to others-may-edit. [#7923](https://github.com/scalableminds/webknossos/pull/7923)
4444
- When proofreading segmentations, the user can now interact with super-voxels directly in the data viewports. Additionally, proofreading is significantly faster because the segmentation data doesn't have to be re-downloaded after each merge/split operation. [#7654](https://github.com/scalableminds/webknossos/pull/7654)
45+
- Changed internal data model changing an organization's name to id and its displayName to name. The previously existing id was removed. [#7386](https://github.com/scalableminds/webknossos/pull/7386)
4546
- Because of the way our models are trained, AI analysis and training is disabled for 2D and ND datasets, as well as for color layers with data type uInt24. [#7957](https://github.com/scalableminds/webknossos/pull/7957)
4647
- The overall performance was improved (especially for the segments tab). [#7958](https://github.com/scalableminds/webknossos/pull/7958)
4748
- The performance for the skeleton tab was improved. [#7989](https://github.com/scalableminds/webknossos/pull/7989)

MIGRATIONS.unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ User-facing changes are documented in the [changelog](CHANGELOG.released.md).
1212

1313
### Postgres Evolutions:
1414
- [119-add-metadata-to-folders-and-datasets.sql](conf/evolutions/119-add-metadata-to-folders-and-datasets.sql)
15+
- [120-remove-old-organization-id.sql](conf/evolutions/120-remove-old-organization-id.sql)

app/controllers/AiModelController.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class AiModelController @Inject()(
133133
jobCommand = JobCommand.train_model
134134
commandArgs = Json.obj(
135135
"training_annotations" -> Json.toJson(trainingAnnotations),
136-
"organization_name" -> organization.name,
136+
"organization_name" -> organization._id,
137137
"model_id" -> modelId,
138138
"custom_workflow_provided_by_user" -> request.body.workflowYaml
139139
)
@@ -171,7 +171,7 @@ class AiModelController @Inject()(
171171
jobCommand = JobCommand.infer_with_model
172172
boundingBox <- BoundingBox.fromLiteral(request.body.boundingBox).toFox
173173
commandArgs = Json.obj(
174-
"organization_name" -> organization.name,
174+
"organization_name" -> organization._id,
175175
"dataset_name" -> dataset.name,
176176
"color_layer_name" -> request.body.colorLayerName,
177177
"bounding_box" -> boundingBox.toLiteral,

app/controllers/AnnotationController.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class AnnotationController @Inject()(
204204
newLayerName = request.body.name.getOrElse(AnnotationLayer.defaultNameForType(request.body.typ))
205205
_ <- bool2Fox(!annotation.annotationLayers.exists(_.name == newLayerName)) ?~> "annotation.addLayer.nameInUse"
206206
organization <- organizationDAO.findOne(request.identity._organization)
207-
_ <- annotationService.addAnnotationLayer(annotation, organization.name, request.body)
207+
_ <- annotationService.addAnnotationLayer(annotation, organization._id, request.body)
208208
updated <- provider.provideAnnotation(typ, id, request.identity)
209209
json <- annotationService.publicWrites(updated, Some(request.identity)) ?~> "annotation.write.failed"
210210
} yield JsonOk(json)
@@ -242,12 +242,12 @@ class AnnotationController @Inject()(
242242
} yield result
243243
}
244244

245-
def createExplorational(organizationName: String, datasetName: String): Action[List[AnnotationLayerParameters]] =
245+
def createExplorational(organizationId: String, datasetName: String): Action[List[AnnotationLayerParameters]] =
246246
sil.SecuredAction.async(validateJson[List[AnnotationLayerParameters]]) { implicit request =>
247247
for {
248-
organization <- organizationDAO.findOneByName(organizationName)(GlobalAccessContext) ?~> Messages(
248+
organization <- organizationDAO.findOne(organizationId)(GlobalAccessContext) ?~> Messages(
249249
"organization.notFound",
250-
organizationName) ~> NOT_FOUND
250+
organizationId) ~> NOT_FOUND
251251
dataset <- datasetDAO.findOneByNameAndOrganization(datasetName, organization._id) ?~> Messages(
252252
"dataset.notFound",
253253
datasetName) ~> NOT_FOUND
@@ -262,16 +262,16 @@ class AnnotationController @Inject()(
262262
} yield JsonOk(json)
263263
}
264264

265-
def getSandbox(organizationName: String,
265+
def getSandbox(organization: String,
266266
datasetName: String,
267267
typ: String,
268268
sharingToken: Option[String]): Action[AnyContent] =
269269
sil.UserAwareAction.async { implicit request =>
270270
val ctx = URLSharing.fallbackTokenAccessContext(sharingToken) // users with dataset sharing token may also get a sandbox annotation
271271
for {
272-
organization <- organizationDAO.findOneByName(organizationName)(GlobalAccessContext) ?~> Messages(
272+
organization <- organizationDAO.findOne(organization)(GlobalAccessContext) ?~> Messages(
273273
"organization.notFound",
274-
organizationName) ~> NOT_FOUND
274+
organization) ~> NOT_FOUND
275275
dataset <- datasetDAO.findOneByNameAndOrganization(datasetName, organization._id)(ctx) ?~> Messages(
276276
"dataset.notFound",
277277
datasetName) ~> NOT_FOUND
@@ -301,7 +301,7 @@ class AnnotationController @Inject()(
301301
_ <- restrictions.allowUpdate(request.identity) ?~> "notAllowed" ~> FORBIDDEN
302302
annotation <- provider.provideAnnotation(typ, id, request.identity)
303303
organization <- organizationDAO.findOne(request.identity._organization)
304-
_ <- annotationService.makeAnnotationHybrid(annotation, organization.name, fallbackLayerName) ?~> "annotation.makeHybrid.failed"
304+
_ <- annotationService.makeAnnotationHybrid(annotation, organization._id, fallbackLayerName) ?~> "annotation.makeHybrid.failed"
305305
updated <- provider.provideAnnotation(typ, id, request.identity)
306306
json <- annotationService.publicWrites(updated, Some(request.identity)) ?~> "annotation.write.failed"
307307
} yield JsonOk(json)

app/controllers/AnnotationIOController.scala

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ class AnnotationIOController @Inject()(
103103
request.body.dataParts("createGroupForEachFile").headOption.contains("true")
104104
val overwritingDatasetName: Option[String] =
105105
request.body.dataParts.get("datasetName").flatMap(_.headOption)
106-
val overwritingOrganizationName: Option[String] =
107-
request.body.dataParts.get("organizationName").flatMap(_.headOption)
106+
val overwritingOrganizationId: Option[String] =
107+
request.body.dataParts.get("organizationId").flatMap(_.headOption)
108108
val attachedFiles = request.body.files.map(f => (f.ref.path.toFile, f.filename))
109109
val parsedFiles =
110110
annotationUploadService.extractFromFiles(attachedFiles,
111111
useZipName = true,
112112
overwritingDatasetName,
113-
overwritingOrganizationName)
113+
overwritingOrganizationId)
114114
val parsedFilesWrapped =
115115
annotationUploadService.wrapOrPrefixGroups(parsedFiles.parseResults, shouldCreateGroupForEachFile)
116116
val parseResultsFiltered: List[NmlParseResult] = parsedFilesWrapped.filter(_.succeeded)
@@ -225,15 +225,15 @@ class AnnotationIOController @Inject()(
225225
wkUrl: String)(implicit mp: MessagesProvider, ctx: DBAccessContext): Fox[Dataset] =
226226
for {
227227
datasetName <- assertAllOnSameDataset(skeletonTracings, volumeTracings) ?~> "nml.file.differentDatasets"
228-
organizationNameOpt <- assertAllOnSameOrganization(skeletonTracings, volumeTracings) ?~> "nml.file.differentDatasets"
229-
organizationIdOpt <- Fox.runOptional(organizationNameOpt) {
230-
organizationDAO.findOneByName(_)(GlobalAccessContext).map(_._id)
228+
organizationIdOpt <- assertAllOnSameOrganization(skeletonTracings, volumeTracings) ?~> "nml.file.differentDatasets"
229+
organizationIdOpt <- Fox.runOptional(organizationIdOpt) {
230+
organizationDAO.findOne(_)(GlobalAccessContext).map(_._id)
231231
} ?~> (if (wkUrl.nonEmpty && conf.Http.uri != wkUrl) {
232-
Messages("organization.notFound.wrongHost", organizationNameOpt.getOrElse(""), wkUrl, conf.Http.uri)
233-
} else { Messages("organization.notFound", organizationNameOpt.getOrElse("")) }) ~>
232+
Messages("organization.notFound.wrongHost", organizationIdOpt.getOrElse(""), wkUrl, conf.Http.uri)
233+
} else { Messages("organization.notFound", organizationIdOpt.getOrElse("")) }) ~>
234234
NOT_FOUND
235235
organizationId <- Fox.fillOption(organizationIdOpt) {
236-
datasetDAO.getOrganizationForDataset(datasetName)(GlobalAccessContext)
236+
datasetDAO.getOrganizationIdForDataset(datasetName)(GlobalAccessContext)
237237
} ?~> Messages("dataset.noAccess", datasetName) ~> FORBIDDEN
238238
dataset <- datasetDAO.findOneByNameAndOrganization(datasetName, organizationId) ?~> (if (wkUrl.nonEmpty && conf.Http.uri != wkUrl) {
239239
Messages(
@@ -277,11 +277,11 @@ class AnnotationIOController @Inject()(
277277

278278
private def assertAllOnSameOrganization(skeletons: List[SkeletonTracing],
279279
volumes: List[VolumeTracing]): Fox[Option[String]] = {
280-
// Note that organizationNames are optional. Tracings with no organization attribute are ignored here
281-
val organizationNames = skeletons.flatMap(_.organizationName) ::: volumes.flatMap(_.organizationName)
280+
// Note that organizationIds are optional. Tracings with no organization attribute are ignored here
281+
val organizationIds = skeletons.flatMap(_.organizationId) ::: volumes.flatMap(_.organizationId)
282282
for {
283-
_ <- Fox.runOptional(organizationNames.headOption)(name => bool2Fox(organizationNames.forall(_ == name)))
284-
} yield organizationNames.headOption
283+
_ <- Fox.runOptional(organizationIds.headOption)(name => bool2Fox(organizationIds.forall(_ == name)))
284+
} yield organizationIds.headOption
285285
}
286286

287287
private def adaptVolumeTracingsToFallbackLayer(volumeLayersGrouped: List[List[UploadedVolumeLayer]],
@@ -297,7 +297,7 @@ class AnnotationIOController @Inject()(
297297
adaptedTracing <- adaptPropertiesToFallbackLayer(volumeLayer.tracing,
298298
dataSource,
299299
dataset,
300-
organization.name,
300+
organization._id,
301301
remoteDataStoreClient)
302302
adaptedAnnotationLayer = volumeLayer.copy(tracing = adaptedTracing)
303303
} yield adaptedAnnotationLayer
@@ -309,7 +309,7 @@ class AnnotationIOController @Inject()(
309309
volumeTracing: VolumeTracing,
310310
dataSource: GenericDataSource[T],
311311
dataset: Dataset,
312-
organizationName: String,
312+
organizationId: String,
313313
remoteDataStoreClient: WKRemoteDataStoreClient): Fox[VolumeTracing] = {
314314
val fallbackLayerOpt = dataSource.dataLayers.flatMap {
315315
case layer: SegmentationLayer if volumeTracing.fallbackLayer contains layer.name => Some(layer)
@@ -323,7 +323,7 @@ class AnnotationIOController @Inject()(
323323
.map(layer => elementClassToProto(layer.elementClass))
324324
.getOrElse(elementClassToProto(VolumeTracingDefaults.elementClass))
325325
for {
326-
tracingCanHaveSegmentIndex <- canHaveSegmentIndex(organizationName,
326+
tracingCanHaveSegmentIndex <- canHaveSegmentIndex(organizationId,
327327
dataset.name,
328328
fallbackLayerOpt.map(_.name),
329329
remoteDataStoreClient)
@@ -341,13 +341,13 @@ class AnnotationIOController @Inject()(
341341
}
342342

343343
private def canHaveSegmentIndex(
344-
organizationName: String,
344+
organizationId: String,
345345
datasetName: String,
346346
fallbackLayerName: Option[String],
347347
remoteDataStoreClient: WKRemoteDataStoreClient)(implicit ec: ExecutionContext): Fox[Boolean] =
348348
fallbackLayerName match {
349349
case Some(layerName) =>
350-
remoteDataStoreClient.hasSegmentIndexFile(organizationName, datasetName, layerName)
350+
remoteDataStoreClient.hasSegmentIndexFile(organizationId, datasetName, layerName)
351351
case None =>
352352
Fox.successful(true)
353353
}
@@ -411,9 +411,7 @@ class AnnotationIOController @Inject()(
411411

412412
// Note: volumeVersion cannot currently be supplied per layer, see https://github.com/scalableminds/webknossos/issues/5925
413413

414-
def skeletonToTemporaryFile(dataset: Dataset,
415-
annotation: Annotation,
416-
organizationName: String): Fox[TemporaryFile] =
414+
def skeletonToTemporaryFile(dataset: Dataset, annotation: Annotation, organizationId: String): Fox[TemporaryFile] =
417415
for {
418416
tracingStoreClient <- tracingStoreService.clientFor(dataset)
419417
fetchedAnnotationLayers <- Fox.serialCombined(annotation.skeletonAnnotationLayers)(
@@ -426,7 +424,7 @@ class AnnotationIOController @Inject()(
426424
Some(annotation),
427425
dataset.voxelSize,
428426
None,
429-
organizationName,
427+
organizationId,
430428
conf.Http.uri,
431429
dataset.name,
432430
Some(user),
@@ -443,7 +441,7 @@ class AnnotationIOController @Inject()(
443441
def volumeOrHybridToTemporaryFile(dataset: Dataset,
444442
annotation: Annotation,
445443
name: String,
446-
organizationName: String): Fox[TemporaryFile] =
444+
organizationId: String): Fox[TemporaryFile] =
447445
for {
448446
tracingStoreClient <- tracingStoreService.clientFor(dataset)
449447
fetchedVolumeLayers: List[FetchedAnnotationLayer] <- Fox.serialCombined(annotation.volumeAnnotationLayers) {
@@ -466,7 +464,7 @@ class AnnotationIOController @Inject()(
466464
Some(annotation),
467465
dataset.voxelSize,
468466
None,
469-
organizationName,
467+
organizationId,
470468
conf.Http.uri,
471469
dataset.name,
472470
Some(user),
@@ -491,11 +489,11 @@ class AnnotationIOController @Inject()(
491489
def annotationToTemporaryFile(dataset: Dataset,
492490
annotation: Annotation,
493491
name: String,
494-
organizationName: String): Fox[TemporaryFile] =
492+
organizationId: String): Fox[TemporaryFile] =
495493
if (annotation.tracingType == TracingType.skeleton)
496-
skeletonToTemporaryFile(dataset, annotation, organizationName) ?~> "annotation.download.skeletonToFile.failed"
494+
skeletonToTemporaryFile(dataset, annotation, organizationId) ?~> "annotation.download.skeletonToFile.failed"
497495
else
498-
volumeOrHybridToTemporaryFile(dataset, annotation, name, organizationName) ?~> "annotation.download.hybridToFile.failed"
496+
volumeOrHybridToTemporaryFile(dataset, annotation, name, organizationId) ?~> "annotation.download.hybridToFile.failed"
499497

500498
def exportExtensionForAnnotation(annotation: Annotation): String =
501499
if (annotation.tracingType == TracingType.skeleton)
@@ -519,7 +517,7 @@ class AnnotationIOController @Inject()(
519517
_ <- restrictions.allowDownload(issuingUser) ?~> "annotation.download.notAllowed" ~> FORBIDDEN
520518
dataset <- datasetDAO.findOne(annotation._dataset)(GlobalAccessContext) ?~> "dataset.notFoundForAnnotation" ~> NOT_FOUND
521519
organization <- organizationDAO.findOne(dataset._organization)(GlobalAccessContext) ?~> "organization.notFound" ~> NOT_FOUND
522-
temporaryFile <- annotationToTemporaryFile(dataset, annotation, name, organization.name) ?~> "annotation.writeTemporaryFile.failed"
520+
temporaryFile <- annotationToTemporaryFile(dataset, annotation, name, organization._id) ?~> "annotation.writeTemporaryFile.failed"
523521
} yield {
524522
Ok.sendFile(temporaryFile, inline = false)
525523
.as(mimeType)

app/controllers/Application.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class Application @Inject()(actorSystem: ActorSystem,
6464
for {
6565
organization <- organizationDAO.findOne(request.identity._organization)
6666
userEmail <- userService.emailFor(request.identity)
67-
_ = Mailer ! Send(
68-
defaultMails.helpMail(request.identity, userEmail, organization.displayName, message, currentUrl))
67+
_ = Mailer ! Send(defaultMails.helpMail(request.identity, userEmail, organization.name, message, currentUrl))
6968
} yield Ok
7069
}
7170

0 commit comments

Comments
 (0)