Skip to content

Commit

Permalink
#1353 Add queries to navigate on entities
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 26, 2020
1 parent d40200a commit 257d854
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
7 changes: 5 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class AlertCtrl @Inject() (
alertSteps
.richPage(range.from, range.to, withTotal = true)(_.richAlert)
)
override val outputQuery: Query = Query.output[RichAlert, AlertSteps](_.richAlert)
override val extraQueries: Seq[ParamQuery[_]] = Seq()
override val outputQuery: Query = Query.output[RichAlert, AlertSteps](_.richAlert)
override val extraQueries: Seq[ParamQuery[_]] = Seq(
Query[AlertSteps, ObservableSteps]("observables", (alertSteps, _) => alertSteps.observables),
Query[AlertSteps, CaseSteps]("case", (alertSteps, _) => alertSteps.`case`)
)

def create: Action[AnyContent] =
entrypoint("create alert")
Expand Down
3 changes: 2 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class CaseCtrl @Inject() (
override val extraQueries: Seq[ParamQuery[_]] = Seq(
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))
Query[CaseSteps, UserSteps]("assignableUsers", (caseSteps, authContext) => caseSteps.assignableUsers(authContext)),
Query[CaseSteps, OrganisationSteps]("organisations", (caseSteps, authContext) => caseSteps.organisations.visible(authContext))
)

def create: Action[AnyContent] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class ObservableCtrl @Inject() (
)
override val outputQuery: Query = Query.output[RichObservable, ObservableSteps](_.richObservable)

override val extraQueries: Seq[ParamQuery[_]] = Seq(
Query[ObservableSteps, OrganisationSteps]("organisations", (observableSteps, authContext) => observableSteps.organisations.visible(authContext)),
Query[ObservableSteps, ObservableSteps]("similar", (observableSteps, authContext) => observableSteps.similar.visible(authContext)),
Query[ObservableSteps, CaseSteps]("case", (observableSteps, _) => observableSteps.`case`)
)

def create(caseId: String): Action[AnyContent] =
entryPoint("create artifact")
.extract("artifact", FieldsParser[InputObservable])
Expand Down
7 changes: 5 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.thp.scalligraph.steps.StepsOps._
import org.thp.thehive.controllers.v1.Conversion._
import org.thp.thehive.dto.v1.InputTask
import org.thp.thehive.models.{Permissions, RichTask}
import org.thp.thehive.services.{CaseSrv, OrganisationSrv, ShareSrv, TaskSrv, TaskSteps, UserSteps}
import org.thp.thehive.services.{CaseSrv, CaseSteps, LogSteps, OrganisationSrv, OrganisationSteps, ShareSrv, TaskSrv, TaskSteps, UserSteps}
import play.api.mvc.{Action, AnyContent, Results}

import scala.util.Success
Expand Down Expand Up @@ -41,7 +41,10 @@ class TaskCtrl @Inject() (
)
override val outputQuery: Query = Query.output[RichTask, TaskSteps](_.richTask)
override val extraQueries: Seq[ParamQuery[_]] = Seq(
Query[TaskSteps, UserSteps]("assignableUsers", (taskSteps, authContext) => taskSteps.assignableUsers(authContext))
Query[TaskSteps, UserSteps]("assignableUsers", (taskSteps, authContext) => taskSteps.assignableUsers(authContext)),
Query[TaskSteps, LogSteps]("logs", (taskSteps, _) => taskSteps.logs),
Query[TaskSteps, CaseSteps]("case", (taskSteps, _) => taskSteps.`case`),
Query[TaskSteps, OrganisationSteps]("organisations", (taskSteps, authContext) => taskSteps.organisations.visible(authContext))
)

def create: Action[AnyContent] =
Expand Down
2 changes: 2 additions & 0 deletions thehive/app/org/thp/thehive/services/ObservableSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class ObservableSteps(raw: GremlinScala[Vertex])(implicit db: Database, graph: G
.has("login", authContext.userId)
)

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

override def newInstance(): ObservableSteps = new ObservableSteps(raw.clone())

def richObservable: Traversal[RichObservable, RichObservable] =
Expand Down

0 comments on commit 257d854

Please sign in to comment.