diff --git a/ScalliGraph b/ScalliGraph index 7b27220f2c..e26dc5cd8d 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 7b27220f2cc0ad58f2ea5d28be405756d69d19e9 +Subproject commit e26dc5cd8d97527184c46c805ce50d596b9cce35 diff --git a/frontend/app/scripts/controllers/RootCtrl.js b/frontend/app/scripts/controllers/RootCtrl.js index 609ce267b3..3528ea8b11 100644 --- a/frontend/app/scripts/controllers/RootCtrl.js +++ b/frontend/app/scripts/controllers/RootCtrl.js @@ -95,9 +95,7 @@ angular.module('theHiveControllers').controller('RootCtrl', }); StreamQuerySrv('v1', [ - {_name: 'listAlert'}, - {_name: 'filter', _field: 'read', _value: false}, - {_name: 'count'} + {_name: 'countUnreadAlert'}, ], { scope: $scope, rootId: 'any', diff --git a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala index 53ff93d07d..90d7462dc3 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala @@ -56,6 +56,16 @@ class AlertCtrl @Inject() ( implicit val caseFilterParser: FieldsParser[Option[InputQuery[Traversal.Unk, Traversal.Unk]]] = FilterQuery.default(caseProperties).paramParser(ru.typeOf[Traversal.V[Case]]).optional.on("caseFilter") override val extraQueries: Seq[ParamQuery[_]] = Seq( + Query.init[Long]( + "countAlert", + (graph, authContext) => + graph.indexCountQuery(s"""v."_label":Alert AND v.organisationId:${organisationSrv.currentId(graph, authContext).value}""") + ), + Query.init[Long]( + "countUnreadAlert", + (graph, authContext) => + graph.indexCountQuery(s"""v."_label":Alert AND v.organisationId:${organisationSrv.currentId(graph, authContext).value} AND v.read:false""") + ), Query[Traversal.V[Alert], Traversal.V[Observable]]("observables", (alertSteps, _) => alertSteps.observables), Query[Traversal.V[Alert], Traversal.V[Case]]("case", (alertSteps, _) => alertSteps.`case`), Query.withParam[Option[InputQuery[Traversal.Unk, Traversal.Unk]], Traversal.V[Alert], Traversal[ diff --git a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala index c7af97fed4..b376bbecbd 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala @@ -56,6 +56,11 @@ class CaseCtrl @Inject() ( ) override val outputQuery: Query = Query.outputWithContext[RichCase, Traversal.V[Case]]((caseSteps, authContext) => caseSteps.richCase(authContext)) override val extraQueries: Seq[ParamQuery[_]] = Seq( + Query.init[Long]( + "countCase", + (graph, authContext) => + graph.indexCountQuery(s"""v."_label":Case AND v.organisationIds:${organisationSrv.currentId(graph, authContext).value} """) + ), Query[Traversal.V[Case], Traversal.V[Observable]]( "observables", (caseSteps, authContext) => diff --git a/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala index 3c8f8aa531..53df4dcc8a 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala @@ -74,6 +74,13 @@ class ObservableCtrl @Inject() ( override val outputQuery: Query = Query.output[RichObservable, Traversal.V[Observable]](_.richObservable) override val extraQueries: Seq[ParamQuery[_]] = Seq( + Query.initWithParam[InCase, Long]( + "countObservable", + (inCase, graph, authContext) => + graph.indexCountQuery( + s"""v."_label":Observable AND relatedId:${inCase.caseId.value} AND organisationIds:${organisationSrv.currentId(graph, authContext).value}""" + ) + ), Query[Traversal.V[Observable], Traversal.V[Organisation]]( "organisations", (observableSteps, authContext) => observableSteps.organisations.visible(authContext) diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala index 94841e27bd..e35ef1545f 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala @@ -45,6 +45,11 @@ class TagCtrl @Inject() ( ) override val extraQueries: Seq[ParamQuery[_]] = Seq( Query.init[Traversal.V[Tag]]("freetags", (graph, authContext) => tagSrv.startTraversal(graph).freetags(organisationSrv)(authContext)), + Query.init[Long]( + "countFreetags", + (graph, authContext) => + graph.indexCountQuery(s"""v."_label":Tag AND v.namespace:_freetags_${organisationSrv.currentId(graph, authContext).value}""") + ), Query[Traversal.V[Tag], Traversal.V[Tag]]("freetags", (tagSteps, authContext) => tagSteps.freetags(organisationSrv)(authContext)), Query.initWithParam[TagHint, Traversal[String, Vertex, Converter[String, Vertex]]]( "tagAutoComplete", diff --git a/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala index ce1450a715..c99aa1f038 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala @@ -53,13 +53,20 @@ class TaskCtrl @Inject() ( override val outputQuery: Query = Query.outputWithContext[RichTask, Traversal.V[Task]]((taskSteps, _) => taskSteps.richTask) override val extraQueries: Seq[ParamQuery[_]] = Seq( + Query.initWithParam[InCase, Long]( + "countTask", + (inCase, graph, authContext) => + graph.indexCountQuery( + s"""v."_label":Task AND relatedId:${inCase.caseId.value} AND organisationIds:${organisationSrv.currentId(graph, authContext).value}""" + ) + ), Query.init[Traversal.V[Task]]( "waitingTasks", - (graph, authContext) => taskSrv.startTraversal(graph).has(_.status, TaskStatus.Waiting).inCase.visible(organisationSrv)(authContext) + (graph, authContext) => taskSrv.startTraversal(graph).has(_.status, TaskStatus.Waiting).visible(organisationSrv)(authContext).inCase ), Query.init[Traversal.V[Task]]( // DEPRECATED "waitingTask", - (graph, authContext) => taskSrv.startTraversal(graph).has(_.status, TaskStatus.Waiting).inCase.visible(organisationSrv)(authContext) + (graph, authContext) => taskSrv.startTraversal(graph).has(_.status, TaskStatus.Waiting).visible(organisationSrv)(authContext).inCase ), Query.init[Traversal.V[Task]]( "myTasks", @@ -68,6 +75,7 @@ class TaskCtrl @Inject() ( .startTraversal(graph) .assignTo(authContext.userId) .visible(organisationSrv)(authContext) + .inCase ), Query[Traversal.V[Task], Traversal.V[User]]("assignableUsers", (taskSteps, authContext) => taskSteps.assignableUsers(authContext)), Query[Traversal.V[Task], Traversal.V[Log]]("logs", (taskSteps, _) => taskSteps.logs), diff --git a/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala b/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala index f6c0567967..33833f4eb7 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala @@ -1,5 +1,6 @@ package org.thp.thehive.controllers.v1 +import org.thp.scalligraph.EntityId import org.thp.scalligraph.controllers.{FObject, FieldsParser} import org.thp.scalligraph.models.Database import org.thp.scalligraph.query._ @@ -7,6 +8,8 @@ import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import javax.inject.{Inject, Singleton} +case class InCase(caseId: EntityId) + case class OutputParam(from: Long, to: Long, extraData: Set[String]) object OutputParam {