From d4468057a4eb2f938a00ecc703edc0681d9a7bae Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 10 Nov 2020 16:06:47 +0100 Subject: [PATCH] #1636 Add customField option in describe --- .../thp/thehive/controllers/v0/DescribeCtrl.scala | 15 +++++++++++++-- .../thp/thehive/controllers/v1/DescribeCtrl.scala | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala index e7ee191d0d..16a8ceaaf5 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala @@ -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 { diff --git a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala index 8db4d8e430..ac393112f8 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala @@ -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 =>