From 99521658d35dbcdb828ec811bcf7016b6f9ba443 Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 7 Jul 2020 15:22:54 +0200 Subject: [PATCH] #1411 Add queries for tags --- thehive/app/org/thp/thehive/controllers/v0/Properties.scala | 1 + thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala | 5 +++++ thehive/app/org/thp/thehive/services/TagSrv.scala | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/Properties.scala b/thehive/app/org/thp/thehive/controllers/v0/Properties.scala index 7af0cac32c..c9095be753 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/Properties.scala @@ -372,6 +372,7 @@ class Properties @Inject() ( .property("predicate", UniMapping.string)(_.field.readonly) .property("value", UniMapping.string.optional)(_.field.readonly) .property("description", UniMapping.string.optional)(_.field.readonly) + .property("text", UniMapping.string)(_.select(_.displayName).readonly) .build lazy val task: List[PublicProperty[_, _]] = diff --git a/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala index ab1b463ba1..ca6e12dac4 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala @@ -38,6 +38,11 @@ class TagCtrl @Inject() ( (param, graph, _) => tagSrv.get(param.idOrName)(graph) ) + override val extraQueries: Seq[ParamQuery[_]] = Seq( + Query[TagSteps, TagSteps]("fromCase", (tagSteps, _) => tagSteps.fromCase), + Query.output[String, TagSteps](_.displayName) + ) + def importTaxonomy: Action[AnyContent] = entrypoint("import taxonomy") .extract("file", FieldsParser.file.optional.on("file")) diff --git a/thehive/app/org/thp/thehive/services/TagSrv.scala b/thehive/app/org/thp/thehive/services/TagSrv.scala index 33a581b5f8..ecc4e4086a 100644 --- a/thehive/app/org/thp/thehive/services/TagSrv.scala +++ b/thehive/app/org/thp/thehive/services/TagSrv.scala @@ -9,7 +9,7 @@ import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.scalligraph.services.{IntegrityCheckOps, VertexSrv} import org.thp.scalligraph.steps.StepsOps._ import org.thp.scalligraph.steps.{Traversal, VertexSteps} -import org.thp.thehive.models.Tag +import org.thp.thehive.models.{CaseTag, Tag} import scala.util.{Success, Try} @@ -81,6 +81,8 @@ class TagSteps(raw: GremlinScala[Vertex])(implicit db: Database, graph: Graph) e } def displayName: Traversal[String, String] = this.map(_.toString) + + def fromCase: TagSteps = this.filter(_.inTo[CaseTag]) } class TagIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: TagSrv) extends IntegrityCheckOps[Tag] {