Skip to content
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

Unify permission system for setting allowed teams during upload #7518

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed a bug where meshes (or chunks of them) were always colored white, if they were loaded while the corresponding segmentation layer was disabled. [#7507](https://github.com/scalableminds/webknossos/pull/7507)
- Fixed a race condition when opening a short link, that would sometimes lead to an error toast. [#7507](https://github.com/scalableminds/webknossos/pull/7507)
- Fixed that the Segment Statistics feature was not available in the context menu of segment groups and in the context menu of the data viewports. [#7510](https://github.com/scalableminds/webknossos/pull/7510)
- Fixed a bug where dataset managers were not allowed to assign teams to new datasets that they are only member of. This already worked while editing the dataset later, but not during upload. [#7518](https://github.com/scalableminds/webknossos/pull/7518)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/WKRemoteDataStoreController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class WKRemoteDataStoreController @Inject()(
_ <- Fox.serialCombined(uploadInfo.layersToLink.getOrElse(List.empty))(l => validateLayerToLink(l, user)) ?~> "dataset.upload.invalidLinkedLayers"
dataSet <- datasetService.createPreliminaryDataset(uploadInfo.name, uploadInfo.organization, dataStore) ?~> "dataset.name.alreadyTaken"
_ <- datasetDAO.updateFolder(dataSet._id, folderId)(GlobalAccessContext)
_ <- datasetService.addInitialTeams(dataSet, uploadInfo.initialTeams)(AuthorizedAccessContext(user))
_ <- datasetService.addInitialTeams(dataSet, uploadInfo.initialTeams, user)(AuthorizedAccessContext(user))
_ <- datasetService.addUploader(dataSet, user._id)(AuthorizedAccessContext(user))
} yield Ok
}
Expand Down
8 changes: 4 additions & 4 deletions app/models/dataset/DatasetService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ class DatasetService @Inject()(organizationDAO: OrganizationDAO,

def isUnreported(dataset: Dataset): Boolean = dataset.status == unreportedStatus

def addInitialTeams(dataset: Dataset, teams: List[String])(implicit ctx: DBAccessContext): Fox[Unit] =
def addInitialTeams(dataset: Dataset, teams: List[String], user: User)(implicit ctx: DBAccessContext): Fox[Unit] =
for {
previousDatasetTeams <- teamService.allowedTeamIdsForDataset(dataset, cumulative = false) ?~> "allowedTeams.notFound"
_ <- bool2Fox(previousDatasetTeams.isEmpty) ?~> "dataset.initialTeams.teamsNotEmpty"
userTeams <- teamDAO.findAllEditable
userTeamIds = userTeams.map(_._id)
includeMemberOnlyTeams = user.isDatasetManager
userTeams <- if (includeMemberOnlyTeams) teamDAO.findAll else teamDAO.findAllEditable
teamIdsValidated <- Fox.serialCombined(teams)(ObjectId.fromString(_))
_ <- bool2Fox(teamIdsValidated.forall(team => userTeamIds.contains(team))) ?~> "dataset.initialTeams.invalidTeams"
_ <- bool2Fox(teamIdsValidated.forall(team => userTeams.map(_._id).contains(team))) ?~> "dataset.initialTeams.invalidTeams"
_ <- datasetDAO.assertUpdateAccess(dataset._id) ?~> "dataset.initialTeams.forbidden"
_ <- teamDAO.updateAllowedTeamsForDataset(dataset._id, teamIdsValidated)
} yield ()
Expand Down