Skip to content

Commit

Permalink
#1353 Add _type to output objects
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 23, 2020
1 parent 7ab137d commit 615d8fa
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Alert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object InputAlert {

case class OutputAlert(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
Expand Down
1 change: 1 addition & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Audit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object OutputEntity {

case class OutputAudit(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
Expand Down
1 change: 1 addition & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Case.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object InputCase {

case class OutputCase(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object InputCaseTemplate {

case class OutputCaseTemplate(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
Expand Down
6 changes: 3 additions & 3 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Dashboard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/Log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 615d8fa

Please sign in to comment.