Skip to content

Commit

Permalink
#1779 Fix custom fields aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 5, 2021
1 parent bf4dc9f commit 41a7eec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 13 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.TagOps._
import org.thp.thehive.services.UserOps._
import org.thp.thehive.services._
import play.api.libs.json.{JsArray, JsObject, JsValue, Json}
import play.api.libs.json.{JsArray, JsBoolean, JsNumber, JsObject, JsString, JsValue, Json}
import play.api.mvc.{Action, AnyContent, Results}

import java.util.{Base64, Date, List => JList, Map => JMap}
Expand Down Expand Up @@ -430,9 +430,18 @@ class PublicAlert @Inject() (
.property("summary", UMapping.string.optional)(_.field.updatable)
.property("user", UMapping.string)(_.field.updatable)
.property("customFields", UMapping.jsonNative)(_.subSelect {
case (FPathElem(_, FPathElem(name, _)), alertSteps) =>
alertSteps.customFields(EntityIdOrName(name)).jsonValue
case (_, alertSteps) => alertSteps.customFields.nameJsonValue.fold.domainMap(JsObject(_))
case (FPathElem(_, FPathElem(name, _)), alerts) =>
db
.roTransaction(implicit graph => customFieldSrv.get(EntityIdOrName(name)).value(_.`type`).getOrFail("CustomField"))
.map {
case CustomFieldType.boolean => alerts.customFields(EntityIdOrName(name)).value(_.booleanValue).domainMap(v => JsBoolean(v))
case CustomFieldType.date => alerts.customFields(EntityIdOrName(name)).value(_.dateValue).domainMap(v => JsNumber(v.getTime))
case CustomFieldType.float => alerts.customFields(EntityIdOrName(name)).value(_.floatValue).domainMap(v => JsNumber(v))
case CustomFieldType.integer => alerts.customFields(EntityIdOrName(name)).value(_.integerValue).domainMap(v => JsNumber(v))
case CustomFieldType.string => alerts.customFields(EntityIdOrName(name)).value(_.stringValue).domainMap(v => JsString(v))
}
.getOrElse(alerts.constant2(null))
case (_, caseSteps) => caseSteps.customFields.nameJsonValue.fold.domainMap(JsObject(_))
}
.filter {
case (FPathElem(_, FPathElem(idOrName, _)), alerts) =>
Expand Down
8 changes: 3 additions & 5 deletions thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.thp.thehive.controllers.v0

import java.lang.{Long => JLong}
import java.util.Date

import javax.inject.{Inject, Named, Singleton}
import org.thp.scalligraph.controllers.{Entrypoint, FPathElem, FPathEmpty, FieldsParser}
import org.thp.scalligraph.models.{Database, UMapping}
import org.thp.scalligraph.query._
Expand All @@ -24,6 +20,8 @@ import org.thp.thehive.services._
import play.api.libs.json._
import play.api.mvc.{Action, AnyContent, Results}

import java.util.Date
import javax.inject.{Inject, Named, Singleton}
import scala.util.{Failure, Success}

@Singleton
Expand Down Expand Up @@ -328,7 +326,7 @@ class PublicCase @Inject() (
case CustomFieldType.integer => new Converter[Any, JsValue] { def apply(x: JsValue): Any = x.as[Long] }
case CustomFieldType.string => new Converter[Any, JsValue] { def apply(x: JsValue): Any = x.as[String] }
}
.getOrElse(new Converter[Any, JsValue] { def apply(x: JsValue): Any = x })
.getOrElse((x: JsValue) => x)
case _ => (x: JsValue) => x
}
.custom {
Expand Down

0 comments on commit 41a7eec

Please sign in to comment.