Skip to content

Commit

Permalink
Add missing meta-fields in output DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 26, 2020
1 parent 8a0c53b commit d40200a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
13 changes: 12 additions & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.thp.thehive.dto.v1

import java.util.Date

import play.api.libs.json.{Format, Json, Writes}

case class InputOrganisation(name: String, description: String)
Expand All @@ -8,7 +10,16 @@ object InputOrganisation {
implicit val writes: Writes[InputOrganisation] = Json.writes[InputOrganisation]
}

case class OutputOrganisation(name: String, description: String)
case class OutputOrganisation(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
_updatedAt: Option[Date] = None,
name: String,
description: String
)

object OutputOrganisation {
implicit val format: Format[OutputOrganisation] = Json.format[OutputOrganisation]
Expand Down
9 changes: 4 additions & 5 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ object InputProfile {

case class OutputProfile(
_id: String,
id: String,
createdBy: String,
updatedBy: Option[String] = None,
createdAt: Date,
updatedAt: Option[Date] = None,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
_updatedAt: Option[Date] = None,
name: String,
permissions: Seq[String],
editable: Boolean,
Expand Down
6 changes: 6 additions & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ object InputTask {
}

case class OutputTask(
_id: String,
_type: String,
_createdBy: String,
_updatedBy: Option[String] = None,
_createdAt: Date,
_updatedAt: Option[Date] = None,
title: String,
group: String,
description: Option[String],
Expand Down
18 changes: 11 additions & 7 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ object Conversion {
}

implicit val organisationRenderer: Renderer.Aux[Organisation with Entity, OutputOrganisation] =
Renderer.json[Organisation with Entity, OutputOrganisation](
_.asInstanceOf[Organisation]
Renderer.json[Organisation with Entity, OutputOrganisation](organisation =>
organisation
.asInstanceOf[Entity]
.into[OutputOrganisation]
.withFieldConst(_._type, "Organisation")
.withFieldConst(_.name, organisation.name)
.withFieldConst(_.description, organisation.description)
.transform
)

Expand All @@ -169,6 +173,7 @@ object Conversion {

implicit val taskOutput: Renderer.Aux[RichTask, OutputTask] = Renderer.json[RichTask, OutputTask](
_.into[OutputTask]
.withFieldConst(_._type, "Task")
.withFieldComputed(_.status, _.status.toString)
.transform
)
Expand Down Expand Up @@ -213,11 +218,10 @@ object Conversion {
.asInstanceOf[Profile]
.into[OutputProfile]
.withFieldConst(_._id, profile._id)
.withFieldConst(_.id, profile._id)
.withFieldConst(_.updatedAt, profile._updatedAt)
.withFieldConst(_.updatedBy, profile._updatedBy)
.withFieldConst(_.createdAt, profile._createdAt)
.withFieldConst(_.createdBy, profile._createdBy)
.withFieldConst(_._updatedAt, profile._updatedAt)
.withFieldConst(_._updatedBy, profile._updatedBy)
.withFieldConst(_._createdAt, profile._createdAt)
.withFieldConst(_._createdBy, profile._createdBy)
.withFieldConst(_._type, "Profile")
.withFieldComputed(_.permissions, _.permissions.asInstanceOf[Set[String]].toSeq.sorted) // Permission is String
.withFieldComputed(_.editable, ProfileSrv.isEditable)
Expand Down

0 comments on commit d40200a

Please sign in to comment.