Skip to content

Commit

Permalink
Fix Dataset Configurations (#4845)
Browse files Browse the repository at this point in the history
* change getting of dataset configurations

* [WIP] backend split layer and dataset config handling

* clean up frontend

* add evolutions

* fix frontend linting

* fix frontend tests

* fix frontend tests 2

* pretty frontend

* update changelog and migrations guide

* Apply suggestions from code review

Co-authored-by: Florian M <[email protected]>

* remove unnecessary invalidation of user

* apply pr feedback

* check for volume ids when no config is found

* rename default view config to unify wk and datastore implementation

* rename backend types to match each other

* add frontend part to validate DatasetConfiguration

* fix evolution after renaming

* move type and schema definitions

* fix e2e tests

* move datasource types

* update snapshots

* run eliminate errors always because it checks for errors

* enforce validated configuration in api instead of model_initialization

* use new validation for dataset import as well

* fix frontend tests

* add table for layer view configurations

* fix for null values

* fix frontend test

* add additional frontend tests

* fix pretty

* reversion of evolution

* rework update layers

* fix naming in reversion of evolution

* update documentation

* fix documentation

* rename methods to new naming schema

* pr feedback

* bump schema version

* fix version number in evolution

Co-authored-by: Gritta Weisheit <[email protected]>
Co-authored-by: Florian M <[email protected]>
Co-authored-by: Philipp Otto <[email protected]>
  • Loading branch information
4 people authored Oct 29, 2020
1 parent bc6b71d commit ff0457c
Show file tree
Hide file tree
Showing 158 changed files with 1,081 additions and 631 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- In the tree tab, all groups but the root group are now collapsed instead of expanded when opening a tracing. [#4897](https://github.com/scalableminds/webknossos/pull/4897)

### Fixed
-
- Fixed the disappearing of dataset settings after switching between view mode and annotation mode. [#4845](https://github.com/scalableminds/webknossos/pull/4845)

### Removed
-
2 changes: 1 addition & 1 deletion MIGRATIONS.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ User-facing changes are documented in the [changelog](CHANGELOG.released.md).
-

### Postgres Evolutions:
-
- [056-add-layer-specific-view-configs.sql](conf/evolutions/056-add-layer-specific-view-configs.sql)
91 changes: 42 additions & 49 deletions app/controllers/ConfigurationController.scala
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package controllers

import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContext}
import com.mohiva.play.silhouette.api.Silhouette
import com.scalableminds.util.accesscontext.GlobalAccessContext
import com.scalableminds.util.tools.Fox
import javax.inject.Inject
import models.binary.{DataSet, DataSetDAO, DataSetService}
import models.configuration.{DataSetConfiguration, DataSetConfigurationDefaults, UserConfiguration}
import models.user.{UserDataSetConfigurationDAO, UserService}
import models.configuration.{DataSetConfigurationService, UserConfiguration}
import models.user.{UserDataSetConfigurationDAO, UserDataSetLayerConfigurationDAO, UserService}
import oxalis.security.WkEnv
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.actions.{SecuredRequest, UserAwareRequest}
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.{JsObject, JsValue}
import play.api.i18n.Messages
import play.api.libs.json.{JsObject}
import play.api.libs.json.Json._
import play.api.mvc.PlayBodyParsers

import scala.concurrent.ExecutionContext

class ConfigurationController @Inject()(userService: UserService,
dataSetService: DataSetService,
dataSetDAO: DataSetDAO,
userDataSetConfigurationDAO: UserDataSetConfigurationDAO,
dataSetConfigurationDefaults: DataSetConfigurationDefaults,
sil: Silhouette[WkEnv])(implicit ec: ExecutionContext)
class ConfigurationController @Inject()(
userService: UserService,
dataSetService: DataSetService,
dataSetDAO: DataSetDAO,
dataSetConfigurationService: DataSetConfigurationService,
sil: Silhouette[WkEnv])(implicit ec: ExecutionContext, bodyParsers: PlayBodyParsers)
extends Controller {

def read = sil.UserAwareAction.async { implicit request =>
Expand All @@ -41,57 +41,50 @@ class ConfigurationController @Inject()(userService: UserService,
}
}

def readDataSet(organizationName: String, dataSetName: String) = sil.UserAwareAction.async { implicit request =>
request.identity.toFox.flatMap { user =>
for {
configurationJson: JsValue <- userDataSetConfigurationDAO.findOneForUserAndDataset(user._id, dataSetName)
} yield DataSetConfiguration(configurationJson.validate[Map[String, JsValue]].getOrElse(Map.empty))
}.orElse(
for {
dataSet <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName)(GlobalAccessContext)
config <- dataSetConfigurationDefaults.constructInitialDefault(dataSet)
} yield config
)
.getOrElse(dataSetConfigurationDefaults.constructInitialDefault(List()))
.map(configuration => Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(configuration))))
}
def readDataSetViewConfiguration(organizationName: String, dataSetName: String) =
sil.UserAwareAction.async(validateJson[List[String]]) { implicit request =>
request.identity.toFox
.flatMap(user =>
dataSetConfigurationService
.getDataSetViewConfigurationForUserAndDataset(request.body, user, dataSetName, organizationName))
.orElse(
dataSetConfigurationService.getDataSetViewConfigurationForDataset(request.body, dataSetName, organizationName)
)
.getOrElse(Map.empty)
.map(configuration => Ok(toJson(configuration)))
}

def updateDataSet(organizationName: String, dataSetName: String) =
def updateDataSetViewConfiguration(organizationName: String, dataSetName: String) =
sil.SecuredAction.async(parse.json(maxLength = 20480)) { implicit request =>
for {
jsConfiguration <- request.body.asOpt[JsObject] ?~> "user.configuration.dataset.invalid"
conf = jsConfiguration.fields.toMap
_ <- userService.updateDataSetConfiguration(request.identity,
dataSetName,
organizationName,
DataSetConfiguration(conf))
dataSetConf = conf - "layers"
layerConf = conf.get("layers")
_ <- userService.updateDataSetViewConfiguration(request.identity,
dataSetName,
organizationName,
dataSetConf,
layerConf)
} yield {
JsonOk(Messages("user.configuration.dataset.updated"))
}
}

def readDataSetDefault(organizationName: String, dataSetName: String) = sil.SecuredAction.async { implicit request =>
dataSetDAO.findOneByNameAndOrganization(dataSetName, request.identity._organization).flatMap { dataSet: DataSet =>
dataSet.defaultConfiguration match {
case Some(c) =>
Fox.successful(
Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(c, dataSet.sourceDefaultConfiguration))))
case _ =>
dataSetConfigurationDefaults
.constructInitialDefault(dataSet)
.map(c => Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(c))))
}
}
def readDataSetAdminViewConfiguration(organizationName: String, dataSetName: String) = sil.SecuredAction.async {
implicit request =>
dataSetConfigurationService
.getCompleteAdminViewConfiguration(dataSetName, organizationName)
.map(configuration => Ok(toJson(configuration)))
}

def updateDataSetDefault(organizationName: String, dataSetName: String) =
def updateDataSetAdminViewConfiguration(organizationName: String, dataSetName: String) =
sil.SecuredAction.async(parse.json(maxLength = 20480)) { implicit request =>
for {
dataset <- dataSetDAO.findOneByNameAndOrganization(dataSetName, request.identity._organization) ?~> "dataset.notFound" ~> NOT_FOUND
dataset <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName) ?~> "dataset.notFound" ~> NOT_FOUND
_ <- dataSetService.isEditableBy(dataset, Some(request.identity)) ?~> "notAllowed" ~> FORBIDDEN
jsConfiguration <- request.body.asOpt[JsObject] ?~> "user.configuration.dataset.invalid"
conf = jsConfiguration.fields.toMap
_ <- dataSetDAO.updateDefaultConfigurationByName(dataSetName, DataSetConfiguration(conf))
jsObject <- request.body.asOpt[JsObject].toFox ?~> "user.configuration.dataset.invalid"
_ <- dataSetConfigurationService.updateAdminViewConfigurationFor(dataset, jsObject.fields.toMap)
} yield {
JsonOk(Messages("user.configuration.dataset.updated"))
}
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/DataSetController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class DataSetController @Inject()(userService: UserService,
case Some(a) =>
Fox.successful(a)
case _ => {
val defaultCenterOpt = dataSet.defaultConfiguration.flatMap(c =>
c.configuration.get("position").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Point3D])))
val defaultZoomOpt = dataSet.defaultConfiguration.flatMap(c =>
c.configuration.get("zoom").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Double])))
val defaultCenterOpt = dataSet.adminViewConfiguration.flatMap(c =>
c.get("position").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Point3D])))
val defaultZoomOpt = dataSet.adminViewConfiguration.flatMap(c =>
c.get("zoom").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Double])))
dataSetService
.clientFor(dataSet)
.flatMap(
Expand Down
Loading

0 comments on commit ff0457c

Please sign in to comment.