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

Dont warn if team has transitive dataset access #4711

Merged
merged 6 commits into from
Jul 20, 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
10 changes: 9 additions & 1 deletion app/controllers/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TaskController @Inject()(annotationDAO: AnnotationDAO,
projectDAO: ProjectDAO,
taskTypeDAO: TaskTypeDAO,
dataSetDAO: DataSetDAO,
userTeamRolesDAO: UserTeamRolesDAO,
userService: UserService,
dataSetService: DataSetService,
tracingStoreService: TracingStoreService,
Expand Down Expand Up @@ -439,12 +440,19 @@ class TaskController @Inject()(annotationDAO: AnnotationDAO,
projects: List[Project] <- Fox.serialCombined(projectNames)(projectDAO.findOneByName(_))
dataSetTeams <- teamDAO.findAllForDataSet(dataSet._id)
noAccessTeamIds = projects.map(_._team).diff(dataSetTeams.map(_._id))
noAccessTeams: List[Team] <- Fox.serialCombined(noAccessTeamIds)(id => teamDAO.findOne(id))
noAccessTeamIdsTransitive <- Fox.serialCombined(noAccessTeamIds)(id =>
filterOutTransitiveSubteam(id, dataSetTeams.map(_._id)))
noAccessTeams: List[Team] <- Fox.serialCombined(noAccessTeamIdsTransitive.flatten)(id => teamDAO.findOne(id))
warnings = noAccessTeams.map(team =>
s"Project team “${team.name}” has no read permission to dataset “${dataSet.name}”.")
} yield warnings
}

private def filterOutTransitiveSubteam(subteamId: ObjectId, dataSetTeams: List[ObjectId]): Fox[Option[ObjectId]] =
for {
memberDifference <- userTeamRolesDAO.findMemberDifference(subteamId, dataSetTeams)
} yield if (memberDifference.isEmpty) None else Some(subteamId)

private def validateScript(scriptIdOpt: Option[String])(implicit request: SecuredRequest[WkEnv, _]): Fox[Unit] =
scriptIdOpt match {
case Some(scriptId) =>
Expand Down
13 changes: 13 additions & 0 deletions app/models/user/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ class UserTeamRolesDAO @Inject()(userDAO: UserDAO, sqlClient: SQLClient)(implici
r <- run(sqlu"delete from webknossos.user_team_roles where _team = ${teamId}")
} yield ()

def findMemberDifference(potentialSubteam: ObjectId, superteams: List[ObjectId]): Fox[List[User]] =
for {
r <- run(sql"""select #${userDAO.columnsWithPrefix("u.")} from webknossos.users_ u
join webknossos.user_team_roles tr on u._id = tr._user
where not u.isAdmin
and not u.isDeactivated
and tr._team = $potentialSubteam
and u._id not in
(select _user from webknossos.user_team_roles
where _team in #${writeStructTupleWithQuotes(superteams.map(_.id))})
""".as[UsersRow])
parsed <- Fox.combined(r.toList.map(userDAO.parse))
} yield parsed
}

class UserExperiencesDAO @Inject()(sqlClient: SQLClient, userDAO: UserDAO)(implicit ec: ExecutionContext)
Expand Down