From 615d8fa7785fc08e39b1f24cfcb40248bd1d0a65 Mon Sep 17 00:00:00 2001 From: To-om Date: Sat, 23 May 2020 11:29:24 +0200 Subject: [PATCH] #1353 Add _type to output objects --- .../main/scala/org/thp/thehive/dto/v1/Alert.scala | 1 + .../main/scala/org/thp/thehive/dto/v1/Audit.scala | 1 + dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala | 1 + .../scala/org/thp/thehive/dto/v1/CaseTemplate.scala | 1 + .../scala/org/thp/thehive/dto/v1/Dashboard.scala | 6 +++--- dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala | 2 +- .../scala/org/thp/thehive/dto/v1/Observable.scala | 2 +- .../org/thp/thehive/controllers/v1/Conversion.scala | 12 ++++++++---- .../thp/thehive/controllers/v1/AlertCtrlTest.scala | 2 ++ 9 files changed, 19 insertions(+), 9 deletions(-) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala index 8f15e27ca7..f1fd827080 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala @@ -29,6 +29,7 @@ object InputAlert { case class OutputAlert( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala index a6acd5a8d8..b079da7ae5 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala @@ -23,6 +23,7 @@ object OutputEntity { case class OutputAudit( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala index cf4196e8bf..667ffcd3e4 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala @@ -29,6 +29,7 @@ object InputCase { case class OutputCase( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala index 0f66d991c6..c77efbcbae 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/CaseTemplate.scala @@ -28,6 +28,7 @@ object InputCaseTemplate { case class OutputCaseTemplate( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Dashboard.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Dashboard.scala index cd23f6cfdb..0ba3907e42 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Dashboard.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Dashboard.scala @@ -12,11 +12,11 @@ object InputDashboard { case class OutputDashboard( _id: String, + _type: String, _createdBy: String, - _updatedBy: Option[String], + _updatedBy: Option[String] = None, _createdAt: Date, - _updatedAt: Option[Date], - _type: String, + _updatedAt: Option[Date] = None, title: String, description: String, status: String, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala index 15cf8c417c..53bc899048 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala @@ -10,11 +10,11 @@ case class InputLog(message: String, startDate: Option[Date] = None, attachment: case class OutputLog( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, _updatedAt: Option[Date] = None, - _type: String, message: String, startDate: Date, attachment: Option[OutputAttachment] = None, diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala index f28049e28c..83174f13c8 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala @@ -34,11 +34,11 @@ object InputObservable { case class OutputObservable( _id: String, + _type: String, _createdBy: String, _updatedBy: Option[String] = None, _createdAt: Date, _updatedAt: Option[Date] = None, - _type: String, dataType: String, data: Option[String], startDate: Date, diff --git a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala index 60ad71f478..f22b875fea 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala @@ -19,6 +19,7 @@ object Conversion { implicit val alertOutput: Renderer.Aux[RichAlert, OutputAlert] = Renderer.json[RichAlert, OutputAlert]( _.into[OutputAlert] + .withFieldConst(_._type, "Alert") .withFieldComputed(_.customFields, _.customFields.map(_.toOutput).toSet) .withFieldComputed(_.tags, _.tags.map(_.toString).toSet) .transform @@ -28,6 +29,7 @@ object Conversion { _.into[OutputAudit] .withFieldComputed(_.operation, _.action) .withFieldComputed(_._id, _._id) + .withFieldConst(_._type, "Audit") .withFieldComputed(_._createdAt, _._createdAt) .withFieldComputed(_._createdBy, _._createdBy) .withFieldComputed(_.obj, a => a.`object`.map(OutputEntity.apply)) @@ -63,6 +65,7 @@ object Conversion { implicit val caseOutput: Renderer.Aux[RichCase, OutputCase] = Renderer.json[RichCase, OutputCase]( _.into[OutputCase] + .withFieldConst(_._type, "Case") .withFieldComputed(_.customFields, _.customFields.map(_.toOutput).toSet) .withFieldComputed(_.tags, _.tags.map(_.toString).toSet) .withFieldComputed(_.status, _.status.toString) @@ -116,6 +119,7 @@ object Conversion { implicit val caseTemplateOutput: Renderer.Aux[RichCaseTemplate, OutputCaseTemplate] = Renderer.json[RichCaseTemplate, OutputCaseTemplate]( _.into[OutputCaseTemplate] + .withFieldConst(_._type, "CaseTemplate") .withFieldComputed(_.customFields, _.customFields.map(_.toOutput).toSet) .withFieldComputed(_.tags, _.tags.map(_.toString).toSet) .transform @@ -214,7 +218,7 @@ object Conversion { .withFieldConst(_.updatedBy, profile._updatedBy) .withFieldConst(_.createdAt, profile._createdAt) .withFieldConst(_.createdBy, profile._createdBy) - .withFieldConst(_._type, "profile") + .withFieldConst(_._type, "Profile") .withFieldComputed(_.permissions, _.permissions.asInstanceOf[Set[String]].toSeq.sorted) // Permission is String .withFieldComputed(_.editable, ProfileSrv.isEditable) .withFieldComputed(_.isAdmin, p => Permissions.containsRestricted(p.permissions)) @@ -226,7 +230,7 @@ object Conversion { .into[OutputDashboard] .withFieldConst(_._id, dashboard._id) .withFieldComputed(_.status, d => if (d.organisationShares.nonEmpty) "Shared" else "Private") - .withFieldConst(_._type, "dashboard") + .withFieldConst(_._type, "Dashboard") .withFieldConst(_._updatedAt, dashboard._updatedAt) .withFieldConst(_._updatedBy, dashboard._updatedBy) .withFieldConst(_._createdAt, dashboard._createdAt) @@ -246,7 +250,7 @@ object Conversion { implicit val observableOutput: Renderer.Aux[RichObservable, OutputObservable] = Renderer.json[RichObservable, OutputObservable](richObservable => richObservable .into[OutputObservable] - .withFieldConst(_._type, "case_artifact") + .withFieldConst(_._type, "Observable") .withFieldComputed(_._id, _.observable._id) .withFieldComputed(_._updatedAt, _.observable._updatedAt) .withFieldComputed(_._updatedBy, _.observable._updatedBy) @@ -264,7 +268,7 @@ object Conversion { implicit val logOutput: Renderer.Aux[RichLog, OutputLog] = Renderer.json[RichLog, OutputLog](richLog => richLog .into[OutputLog] - .withFieldConst(_._type, "case_task_log") + .withFieldConst(_._type, "Log") .withFieldComputed(_._id, _._id) .withFieldComputed(_._updatedAt, _._updatedAt) .withFieldComputed(_._updatedBy, _._updatedBy) diff --git a/thehive/test/org/thp/thehive/controllers/v1/AlertCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v1/AlertCtrlTest.scala index 299091593c..ec8011232f 100644 --- a/thehive/test/org/thp/thehive/controllers/v1/AlertCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v1/AlertCtrlTest.scala @@ -57,6 +57,7 @@ class AlertCtrlTest extends PlaySpecification with TestAppBuilder { val createdAlert = contentAsJson(result).as[OutputAlert] val expected = OutputAlert( _id = createdAlert._id, + _type = "Alert", _createdBy = createdAlert._createdBy, _updatedBy = None, _createdAt = createdAlert._createdAt, @@ -100,6 +101,7 @@ class AlertCtrlTest extends PlaySpecification with TestAppBuilder { val createdAlert = contentAsJson(result).as[OutputAlert] val expected = OutputAlert( _id = createdAlert._id, + _type = "Alert", _createdBy = createdAlert._createdBy, _updatedBy = None, _createdAt = createdAlert._createdAt,