From 2a52b3b592c398a907ff6bd4516b3e8d53fe380a Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 9 Mar 2021 16:18:18 +0100 Subject: [PATCH] #1454 Add property "_id" --- .../org/thp/thehive/controllers/v1/Properties.scala | 13 ++++++++++++- thehive/app/org/thp/thehive/services/TagSrv.scala | 4 +--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala index 4429c00d0f..6f6292cffe 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala @@ -1,10 +1,12 @@ package org.thp.thehive.controllers.v1 +import org.apache.tinkerpop.gremlin.structure.T import org.thp.scalligraph.controllers.{FPathElem, FPathEmpty, FString} import org.thp.scalligraph.models.{Database, UMapping} +import org.thp.scalligraph.query.PredicateOps._ import org.thp.scalligraph.query.{PublicProperties, PublicPropertyListBuilder} import org.thp.scalligraph.traversal.TraversalOps._ -import org.thp.scalligraph.{BadRequestError, EntityIdOrName, InvalidFormatAttributeError, RichSeq} +import org.thp.scalligraph.{BadRequestError, EntityId, EntityIdOrName, InvalidFormatAttributeError, RichSeq} import org.thp.thehive.dto.v1.InputCustomFieldValue import org.thp.thehive.models._ import org.thp.thehive.services.AlertOps._ @@ -46,6 +48,15 @@ class Properties @Inject() ( lazy val metaProperties: PublicProperties = PublicPropertyListBuilder .forType[Product](_ => true) + .property("_id", UMapping.entityId)( + _.select(_._id) + .filter[EntityId] { + case (_, t, _, Right(p)) => t.has(T.id, p.map(_.value)) + case (_, t, _, Left(true)) => t + case (_, t, _, _) => t.empty + } + .readonly + ) .property("_createdBy", UMapping.string)(_.field.readonly) .property("_createdAt", UMapping.date)(_.field.readonly) .property("_updatedBy", UMapping.string.optional)(_.field.readonly) diff --git a/thehive/app/org/thp/thehive/services/TagSrv.scala b/thehive/app/org/thp/thehive/services/TagSrv.scala index 45ada553d6..837974ac75 100644 --- a/thehive/app/org/thp/thehive/services/TagSrv.scala +++ b/thehive/app/org/thp/thehive/services/TagSrv.scala @@ -155,14 +155,12 @@ object TagOps { def autoComplete(namespace: Option[String], predicate: Option[String], value: Option[String])(implicit authContext: AuthContext - ): Traversal.V[Tag] = { - traversal.graph.db.mapPredicate(TextP.containing("")) + ): Traversal.V[Tag] = traversal .merge(namespace)((t, ns) => t.has(_.namespace, TextP.containing(ns))) .merge(predicate)((t, p) => t.has(_.predicate, TextP.containing(p))) .merge(value)((t, v) => t.has(_.value, TextP.containing(v))) .visible - } def visible(implicit authContext: AuthContext): Traversal.V[Tag] = traversal.filter(_.organisation.current)