Skip to content

Commit

Permalink
#1353 Query: "assignableUsers" of a case
Browse files Browse the repository at this point in the history
An user is assignable to a case if he has manageCase on it and is in a visible organisation (from current user)
  • Loading branch information
To-om committed May 23, 2020
1 parent 6dc0736 commit 7ab137d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class CaseCtrl @Inject() (
)
override val outputQuery: Query = Query.outputWithContext[RichCase, CaseSteps]((caseSteps, authContext) => caseSteps.richCase(authContext))
override val extraQueries: Seq[ParamQuery[_]] = Seq(
Query[CaseSteps, TaskSteps]("tasks", (caseSteps, authContext) => caseSteps.tasks(authContext))
Query[CaseSteps, TaskSteps]("tasks", (caseSteps, authContext) => caseSteps.tasks(authContext)),
Query[CaseSteps, ObservableSteps]("observables", (caseSteps, authContext) => caseSteps.observables(authContext)),
Query[CaseSteps, UserSteps]("assignableUsers", (caseSteps, authContext) => caseSteps.assignableUsers(authContext))
)

def create: Action[AnyContent] =
Expand Down
9 changes: 9 additions & 0 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ class CaseSteps(raw: GremlinScala[Vertex])(implicit db: Database, graph: Graph)

def organisations: OrganisationSteps = new OrganisationSteps(raw.inTo[ShareCase].inTo[OrganisationShare])

def organisations(permission: Permission) =
new OrganisationSteps(raw.inTo[ShareCase].filter(_.outTo[ShareProfile].has(Key("permissions") of permission)).inTo[OrganisationShare])

def origin: OrganisationSteps = new OrganisationSteps(raw.inTo[ShareCase].has(Key("owner") of true).inTo[OrganisationShare])

// Warning: this method doesn't generate audit log
Expand Down Expand Up @@ -603,6 +606,12 @@ class CaseSteps(raw: GremlinScala[Vertex])(implicit db: Database, graph: Graph)
.outTo[ShareObservable]
)

def assignableUsers(implicit authContext: AuthContext): UserSteps =
organisations(Permissions.manageCase)
.visible
.users(Permissions.manageCase)
.dedup

def alert: AlertSteps = new AlertSteps(raw.inTo[AlertCase])
}

Expand Down

0 comments on commit 7ab137d

Please sign in to comment.