Skip to content

Commit

Permalink
#1636 Add customField option in describe
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent 51405c9 commit 8a1abb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,21 @@ class DescribeCtrl @Inject() (
implicit val propertyDescriptionWrites: Writes[PropertyDescription] =
Json.writes[PropertyDescription].transform((_: JsObject) + ("description" -> JsString("")))

def customFields: Seq[PropertyDescription] =
def customFields: Seq[PropertyDescription] = {
def jsonToString(v: JsValue): String =
v match {
case JsString(s) => s
case JsBoolean(b) => b.toString
case JsNumber(v) => v.toString
case other => other.toString
}
db.roTransaction { implicit graph =>
customFieldSrv.startTraversal.toSeq.map(cf => PropertyDescription(s"customFields.${cf.name}", cf.`type`.toString))
customFieldSrv
.startTraversal
.toSeq
.map(cf => PropertyDescription(s"customFields.${cf.name}", cf.`type`.toString, cf.options, cf.options.map(jsonToString)))
}
}

def customDescription(model: String, propertyName: String): Option[Seq[PropertyDescription]] =
(model, propertyName) match {
Expand Down
15 changes: 13 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,21 @@ class DescribeCtrl @Inject() (
implicit val propertyDescriptionWrites: Writes[PropertyDescription] =
Json.writes[PropertyDescription].transform((_: JsObject) + ("description" -> JsString("")))

def customFields: Seq[PropertyDescription] =
def customFields: Seq[PropertyDescription] = {
def jsonToString(v: JsValue): String =
v match {
case JsString(s) => s
case JsBoolean(b) => b.toString
case JsNumber(v) => v.toString
case other => other.toString
}
db.roTransaction { implicit graph =>
customFieldSrv.startTraversal.toSeq.map(cf => PropertyDescription(s"customFields.${cf.name}", cf.`type`.toString))
customFieldSrv
.startTraversal
.toSeq
.map(cf => PropertyDescription(s"customFields.${cf.name}", cf.`type`.toString, cf.options, cf.options.map(jsonToString)))
}
}

def impactStatus: PropertyDescription =
db.roTransaction { implicit graph =>
Expand Down

0 comments on commit 8a1abb0

Please sign in to comment.