From 785a248ccc5da280dd75181c3cf170305f4a8b9f Mon Sep 17 00:00:00 2001 From: To-om Date: Sun, 11 Apr 2021 09:44:22 +0200 Subject: [PATCH] #1946 Filter tag usage by organisation --- .../thehive/controllers/v1/TagRenderer.scala | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala index 31246eb65a..4809deacbd 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala @@ -4,6 +4,7 @@ import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.traversal.TraversalOps._ import org.thp.scalligraph.traversal.{Converter, Traversal} import org.thp.thehive.models.Tag +import org.thp.thehive.services.OrganisationSrv import org.thp.thehive.services.TagOps._ import play.api.libs.json._ @@ -11,6 +12,7 @@ import java.util.{Map => JMap} trait TagRenderer extends BaseRenderer[Tag] { val limitedCountThreshold: Long + val organisationSrv: OrganisationSrv def usageStats(implicit authContext: AuthContext @@ -22,9 +24,24 @@ trait TagRenderer extends BaseRenderer[Tag] { ).domainMap { case (tag, caseTemplateCount) => Json.obj( - "case" -> t.graph.indexCountQuery(s"""v."_label":Case AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), - "alert" -> t.graph.indexCountQuery(s"""v."_label":Alert AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), - "observable" -> t.graph.indexCountQuery(s"""v."_label":Observable AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), + "case" -> t + .graph + .indexCountQuery( + s"""v."_label":Case AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}" AND """ + + s"v.organisationIds:${organisationSrv.currentId(t.graph, authContext).value}" + ), + "alert" -> t + .graph + .indexCountQuery( + s"""v."_label":Alert AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}" AND """ + + s"v.organisationId:${organisationSrv.currentId(t.graph, authContext).value}" + ), + "observable" -> t + .graph + .indexCountQuery( + s"""v."_label":Observable AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}" AND """ + + s"v.organisationIds:${organisationSrv.currentId(t.graph, authContext).value}" + ), "caseTemplate" -> caseTemplateCount ) }