Skip to content

Commit

Permalink
Allow admins to view and cancel other users jobs (#8112)
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth authored Oct 7, 2024
1 parent 18fb4e0 commit 2cd6647
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.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.released

### Changed
- Some mesh-related actions were disabled in proofreading-mode when using meshfiles that were created for a mapping rather than an oversegmentation. [#8091](https://github.com/scalableminds/webknossos/pull/8091)
- Admins can now see and cancel all jobs. The owner of the job is shown in the job list. [#8112](https://github.com/scalableminds/webknossos/pull/8112)

### Fixed
- Fixed a bug during dataset upload in case the configured `datastore.baseFolder` is an absolute path. [#8098](https://github.com/scalableminds/webknossos/pull/8098) [#8103](https://github.com/scalableminds/webknossos/pull/8103)
Expand Down
4 changes: 3 additions & 1 deletion app/models/job/Job.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class JobDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext)
"""

private def listAccessQ(requestingUserId: ObjectId) =
q"""_owner = $requestingUserId"""
q"""_owner = $requestingUserId OR
((SELECT u._organization FROM webknossos.users_ u WHERE u._id = _owner) IN (SELECT _organization FROM webknossos.users_ WHERE _id = $requestingUserId AND isAdmin))
"""

override def findAll(implicit ctx: DBAccessContext): Fox[List[Job]] =
for {
Expand Down
2 changes: 2 additions & 0 deletions app/models/job/JobService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ class JobService @Inject()(wkConf: WkConf,
owner <- userDAO.findOne(job._owner) ?~> "user.notFound"
organization <- organizationDAO.findOne(owner._organization) ?~> "organization.notFound"
resultLink = job.resultLink(organization._id)
ownerJson <- userService.compactWrites(owner)
} yield {
Json.obj(
"id" -> job._id.id,
"owner" -> ownerJson,
"command" -> job.command,
"commandArgs" -> (job.commandArgs - "webknossos_token" - "user_auth_token"),
"state" -> job.state,
Expand Down
1 change: 1 addition & 0 deletions frontend/javascripts/admin/api/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { assertResponseLimit } from "./api_utils";
function transformBackendJobToAPIJob(job: any): APIJob {
return {
id: job.id,
owner: job.owner,
type: job.command,
datasetName: job.commandArgs.dataset_name,
organizationId: job.commandArgs.organization_name,
Expand Down
16 changes: 14 additions & 2 deletions frontend/javascripts/admin/job/job_list_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
InfoCircleOutlined,
} from "@ant-design/icons";
import type * as React from "react";
import { type APIJob, APIJobType } from "types/api_flow_types";
import { type APIJob, APIJobType, type APIUserBase } from "types/api_flow_types";
import { getJobs, cancelJob } from "admin/admin_rest_api";
import Persistence from "libs/persistence";
import * as Utils from "libs/utils";
Expand Down Expand Up @@ -375,7 +375,7 @@ function JobListView() {
</Tooltip>
</a>
<br />
WEBKNOSSOS will notfiy you via email when a job has finished or reload this page to track
WEBKNOSSOS will notify you via email when a job has finished or reload this page to track
progress.
</Typography.Paragraph>
<div
Expand Down Expand Up @@ -410,6 +410,18 @@ function JobListView() {
sorter={Utils.compareBy<APIJob>((job) => job.createdAt)}
defaultSortOrder="descend"
/>
<Column
title="Owner"
dataIndex="owner"
key="owner"
sorter={Utils.localeCompareBy<APIJob>((job) => job.owner.lastName)}
render={(owner: APIUserBase) => (
<>
<div>{owner.email ? `${owner.lastName}, ${owner.firstName}` : "-"}</div>
<div>{owner.email ? `(${owner.email})` : "-"}</div>
</>
)}
/>
<Column
title="State"
key="state"
Expand Down
1 change: 1 addition & 0 deletions frontend/javascripts/types/api_flow_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ export type WkLibsNdBoundingBox = BoundingBoxObject & {

export type APIJob = {
readonly id: string;
readonly owner: APIUserBase;
readonly datasetName: string | null | undefined;
readonly exportFileName: string | null | undefined;
readonly layerName: string | null | undefined;
Expand Down

0 comments on commit 2cd6647

Please sign in to comment.