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

add admins and dataset managers to dataset access list #4862

Merged
merged 4 commits into from
Oct 12, 2020
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 @@ -13,6 +13,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
### Added
- Hybrid tracings can now be imported directly in the tracing view via drag'n'drop. [#4837](https://github.com/scalableminds/webknossos/pull/4837)
- The find data function now works for volume tracings, too. [#4847](https://github.com/scalableminds/webknossos/pull/4847)
- Added admins and dataset managers to dataset access list, as they can access all datasets of the organization. [#4862](https://github.com/scalableminds/webknossos/pull/4862)

### Changed
- Brush circles are now connected with rectangles to provide a continuous stroke even if the brush is moved quickly. [#4785](https://github.com/scalableminds/webknossos/pull/4822)
Expand Down
14 changes: 9 additions & 5 deletions app/controllers/DataSetController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.scalableminds.util.tools.DefaultConverters._
import com.scalableminds.util.tools.{Fox, JsonHelper, Math}
import models.binary._
import models.team.{OrganizationDAO, TeamDAO}
import models.user.{User, UserService}
import models.user.{User, UserDAO, UserService}
import oxalis.security.{URLSharing, WkEnv}
import play.api.cache.SyncCacheApi
import play.api.i18n.{Messages, MessagesApi, MessagesProvider}
Expand All @@ -21,6 +21,7 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._

class DataSetController @Inject()(userService: UserService,
userDAO: UserDAO,
dataSetService: DataSetService,
dataSetAllowedTeamsDAO: DataSetAllowedTeamsDAO,
dataSetDataLayerDAO: DataSetDataLayerDAO,
Expand Down Expand Up @@ -176,11 +177,14 @@ class DataSetController @Inject()(userService: UserService,

def accessList(organizationName: String, dataSetName: String) = sil.SecuredAction.async { implicit request =>
for {
dataSet <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName) ?~> notFoundMessage(
dataSetName) ~> NOT_FOUND
organization <- organizationDAO.findOneByName(organizationName)
dataSet <- dataSetDAO
.findOneByNameAndOrganization(dataSetName, organization._id) ?~> notFoundMessage(dataSetName) ~> NOT_FOUND
allowedTeams <- dataSetService.allowedTeamIdsFor(dataSet._id)
users <- userService.findByTeams(allowedTeams)
usersJs <- Fox.serialCombined(users.distinct)(u => userService.compactWrites(u))
usersByTeams <- userDAO.findAllByTeams(allowedTeams)
adminsAndDatasetManagers <- userDAO.findAdminsAndDatasetManagersByOrg(organization._id)
usersJs <- Fox.serialCombined((usersByTeams ++ adminsAndDatasetManagers).distinct)(u =>
userService.compactWrites(u))
} yield {
Ok(Json.toJson(usersJs))
}
Expand Down
19 changes: 17 additions & 2 deletions app/models/user/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,34 @@ class UserDAO @Inject()(sqlClient: SQLClient)(implicit ec: ExecutionContext)
parsed
}

def findAllByTeams(teams: List[ObjectId], includeDeactivated: Boolean = true)(implicit ctx: DBAccessContext) =
def findAllByTeams(teams: List[ObjectId], includeDeactivated: Boolean = true)(
implicit ctx: DBAccessContext): Fox[List[User]] =
if (teams.isEmpty) Fox.successful(List())
else
for {
accessQuery <- readAccessQuery
r <- run(sql"""select u.*
r <- run(sql"""select #${columnsWithPrefix("u.")}
from (select #${columns} from #${existingCollectionName} where #${accessQuery}) u join webknossos.user_team_roles on u._id = webknossos.user_team_roles._user
where webknossos.user_team_roles._team in #${writeStructTupleWithQuotes(teams.map(_.id))}
and (u.isDeactivated = false or u.isDeactivated = ${includeDeactivated})
order by _id""".as[UsersRow])
parsed <- Fox.combined(r.toList.map(parse))
} yield parsed

def findAdminsAndDatasetManagersByOrg(organizationId: ObjectId)(implicit ctx: DBAccessContext): Fox[List[User]] =
for {
accessQuery <- readAccessQuery
r <- run(sql"""select #${columns}
from #${existingCollectionName}
where #${accessQuery}
and (isDatasetManager
or isAdmin)
and not isDeactivated
and _organization = $organizationId
order by _id""".as[UsersRow])
parsed <- Fox.combined(r.toList.map(parse))
} yield parsed

def findAllByIds(ids: List[ObjectId])(implicit ctx: DBAccessContext): Fox[List[User]] =
for {
accessQuery <- readAccessQuery
Expand Down
7 changes: 3 additions & 4 deletions app/models/user/UserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class UserService @Inject()(conf: WkConf,
def defaultUser =
userDAO.findOneByEmail(defaultUserEmail)(GlobalAccessContext)

def findByTeams(teams: List[ObjectId])(implicit ctx: DBAccessContext) =
userDAO.findAllByTeams(teams)

def findOneById(userId: ObjectId, useCache: Boolean)(implicit ctx: DBAccessContext): Fox[User] =
if (useCache)
userCache.findUser(userId)
Expand Down Expand Up @@ -253,7 +250,7 @@ class UserService @Inject()(conf: WkConf,
}

def compactWrites(user: User): Fox[JsObject] = {
implicit val ctx = GlobalAccessContext
implicit val ctx: DBAccessContext = GlobalAccessContext
for {
teamMemberships <- teamMembershipsFor(user._id)
teamMembershipsJs <- Fox.serialCombined(teamMemberships)(tm => teamMembershipService.publicWrites(tm))
Expand All @@ -263,6 +260,8 @@ class UserService @Inject()(conf: WkConf,
"email" -> user.email,
"firstName" -> user.firstName,
"lastName" -> user.lastName,
"isAdmin" -> user.isAdmin,
"isDatasetManager" -> user.isDatasetManager,
"isAnonymous" -> false,
"teams" -> teamMembershipsJs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ export default class DatasetAccessListView extends React.PureComponent<Props, St
}
}

renderUserTags(user: APIUser): Array<React.Node> {
if (user.isAdmin) {
return [
<Tag key={`team_role_${user.id}`} color="red">
Admin
</Tag>,
];
} else {
const managerTags = user.isDatasetManager
? [
<Tag key={`dataset_manager_${user.id}`} color="geekblue">
Dataset Manager
</Tag>,
]
: [];
const teamTags = user.teams.map(team => (
<Tag color={stringToColor(team.name)} key={`${user.id}-${team.id}`}>
{team.name}
</Tag>
));
return managerTags.concat(teamTags);
}
}

renderTable() {
return (
<div>
Expand All @@ -49,11 +73,7 @@ export default class DatasetAccessListView extends React.PureComponent<Props, St
<div style={{ width: 150, display: "inline-block" }}>
{user.firstName} {user.lastName}
</div>
{user.teams.map(team => (
<Tag color={stringToColor(team.name)} key={`${user.id}-${team.id}`}>
{team.name}
</Tag>
))}
{this.renderUserTags(user)}
</li>
))}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -945,7 +947,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -1078,7 +1082,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -1167,7 +1173,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -1295,7 +1303,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: '570b9f4d2a7c0e4d008da6ef',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -1428,7 +1438,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down Expand Up @@ -1517,7 +1529,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: 'id',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_A',
id: '570b9f4d2a7c0e4d008da6ef',
isAdmin: true,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyA',
teams: [
{
Expand All @@ -35,7 +37,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_B',
id: '670b9f4d2a7c0e4d008da6ef',
isAdmin: false,
isAnonymous: false,
isDatasetManager: true,
lastName: 'BoyB',
teams: [
{
Expand All @@ -49,7 +53,9 @@ Generated by [AVA](https://ava.li).
email: '[email protected]',
firstName: 'user_C',
id: '770b9f4d2a7c0e4d008da6ef',
isAdmin: false,
isAnonymous: false,
isDatasetManager: false,
lastName: 'BoyC',
teams: [
{
Expand Down
Binary file not shown.
Loading