Skip to content

Commit

Permalink
#1599 Add metadata in custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 3, 2020
1 parent 2bf529a commit e622b42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/CustomFieldValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ object InputCustomField {
implicit val writes: Writes[InputCustomField] = Json.writes[InputCustomField]
}

case class OutputCustomField(name: String, description: String, `type`: String, options: Seq[JsValue], mandatory: Boolean)
case class OutputCustomField(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
_updatedAt: Option[Date] = None,
name: String,
description: String,
`type`: String,
options: Seq[JsValue],
mandatory: Boolean
)

object OutputCustomField {
implicit val format: OFormat[OutputCustomField] = Json.format[OutputCustomField]
Expand Down
11 changes: 9 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ object Conversion {
)

implicit val customFieldOutput: Renderer.Aux[CustomField with Entity, OutputCustomField] =
Renderer.toJson[CustomField with Entity, OutputCustomField](
_.asInstanceOf[CustomField]
Renderer.toJson[CustomField with Entity, OutputCustomField](customField =>
customField
.asInstanceOf[CustomField]
.into[OutputCustomField]
.withFieldConst(_._id, customField._id.toString)
.withFieldConst(_._type, "CustomField")
.withFieldConst(_._createdAt, customField._createdAt)
.withFieldConst(_._createdBy, customField._createdBy)
.withFieldConst(_._updatedAt, customField._updatedAt)
.withFieldConst(_._updatedBy, customField._updatedBy)
.withFieldComputed(_.`type`, _.`type`.toString)
.withFieldComputed(_.mandatory, _.mandatory)
.transform
Expand Down

0 comments on commit e622b42

Please sign in to comment.