Skip to content

Commit

Permalink
#1454 Add property "_id"
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 9, 2021
1 parent e9faba9 commit 2a52b3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 12 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v1/Properties.scala
Original file line number Diff line number Diff line change
@@ -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._
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions thehive/app/org/thp/thehive/services/TagSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2a52b3b

Please sign in to comment.