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

Allow Team Managers to create (and own) Scripts #3676

Merged
merged 7 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).

### Changed

- Team managers are now also allowed to create and own scripts. [#3676](https://github.com/scalableminds/webknossos/pull/3676)
- Statistics are now separated by organization, rather than showing the webKnossos instance’s totals. [#3663](https://github.com/scalableminds/webknossos/pull/3663)

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions app/assets/javascripts/admin/admin_rest_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export async function getUsers(): Promise<Array<APIUser>> {
return users;
}

export async function getTeamManagerOrAdminUsers(): Promise<Array<APIUser>> {
const users = await Request.receiveJSON("/api/users?isTeamManagerOrAdmin=true");
assertResponseLimit(users);

return users;
}

export async function getAdminUsers(): Promise<Array<APIUser>> {
const users = await Request.receiveJSON("/api/users?isAdmin=true");
assertResponseLimit(users);
Expand Down
9 changes: 7 additions & 2 deletions app/assets/javascripts/admin/scripts/script_create_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import React from "react";
import type { APIUser } from "admin/api_flow_types";
import type { OxalisState } from "oxalis/store";
import { enforceActiveUser } from "oxalis/model/accessors/user_accessor";
import { getAdminUsers, updateScript, createScript, getScript } from "admin/admin_rest_api";
import {
getTeamManagerOrAdminUsers,
updateScript,
createScript,
getScript,
} from "admin/admin_rest_api";

const FormItem = Form.Item;
const Option = Select.Option;
Expand Down Expand Up @@ -37,7 +42,7 @@ class ScriptCreateView extends React.PureComponent<Props, State> {
}

async fetchData() {
const users = await getAdminUsers();
const users = await getTeamManagerOrAdminUsers();
this.setState({ users: users.filter(user => user.isActive) });
}

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/ScriptController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.scalableminds.util.tools.{Fox, FoxImplicits}
import models.task._
import oxalis.security.WkEnv
import com.mohiva.play.silhouette.api.Silhouette
import models.user.UserService
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads._
import play.api.libs.json._
Expand All @@ -15,6 +16,7 @@ import scala.concurrent.ExecutionContext
class ScriptController @Inject()(scriptDAO: ScriptDAO,
taskDAO: TaskDAO,
scriptService: ScriptService,
userService: UserService,
sil: Silhouette[WkEnv])(implicit ec: ExecutionContext)
extends Controller
with FoxImplicits {
Expand All @@ -27,7 +29,8 @@ class ScriptController @Inject()(scriptDAO: ScriptDAO,
def create = sil.SecuredAction.async(parse.json) { implicit request =>
withJsonBodyUsing(scriptPublicReads) { script =>
for {
_ <- bool2Fox(request.identity.isAdmin) ?~> "notAllowed"
isTeamManagerOrAdmin <- userService.isTeamManagerOrAdminOfOrg(request.identity, request.identity._organization)
_ <- bool2Fox(isTeamManagerOrAdmin) ?~> "notAllowed"
_ <- scriptDAO.insertOne(script)
js <- scriptService.publicWrites(script) ?~> "script.write.failed"
} yield {
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/UserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ class UserController @Inject()(userService: UserService,
Filter("isEditable",
(value: Boolean, el: User) =>
for { isEditable <- userService.isEditableBy(el, request.identity) } yield isEditable == value),
Filter(
"isTeamManagerOrAdmin",
(value: Boolean, el: User) =>
for { isTeamManagerOrAdmin <- userService.isTeamManagerOrAdminOfOrg(el, request.identity._organization) } yield
isTeamManagerOrAdmin == value
),
Filter("isAdmin", (value: Boolean, el: User) => Fox.successful(el.isAdmin == value))
) { filter =>
for {
Expand Down