Skip to content

Commit

Permalink
#1875 Include task parent in logs in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 25, 2021
1 parent 56c37fc commit c2f8b23
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ case class OutputLog(
startDate: Date,
attachment: Option[OutputAttachment] = None,
status: String,
owner: String
owner: String,
case_task: Option[OutputTask]
)

object OutputLog {
Expand Down
22 changes: 22 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v0/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,31 @@ object Conversion {
.withFieldComputed(_.owner, _._createdBy)
.withFieldConst(_.status, "Ok")
.withFieldComputed(_.attachment, _.attachments.headOption.map(_.toValue))
.withFieldConst(_.task, None)
.transform
)

implicit val logOutputWithParent: Renderer.Aux[(RichLog, (RichTask, Option[RichCase])), OutputLog] =
Renderer.toJson[(RichLog, (RichTask, Option[RichCase])), OutputLog] {
case (richLog, richTask) =>
richLog
.into[OutputLog]
.withFieldConst(_._type, "case_task_log")
.withFieldComputed(_.id, _._id.toString)
.withFieldComputed(_._id, _._id.toString)
.withFieldComputed(_.updatedAt, _._updatedAt)
.withFieldComputed(_.updatedBy, _._updatedBy)
.withFieldComputed(_.createdAt, _._createdAt)
.withFieldComputed(_.createdBy, _._createdBy)
.withFieldComputed(_.message, _.message)
.withFieldComputed(_.startDate, _._createdAt)
.withFieldComputed(_.owner, _._createdBy)
.withFieldConst(_.status, "Ok")
.withFieldComputed(_.attachment, _.attachments.headOption.map(_.toValue))
.withFieldConst(_.task, Some(richTask.toValue))
.transform
}

implicit class InputLogOps(inputLog: InputLog) {

def toLog: Log =
Expand Down
15 changes: 14 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.thp.scalligraph.traversal.{IteratorOutput, Traversal}
import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.dto.v0.InputLog
import org.thp.thehive.models.{Log, Permissions, RichLog}
import org.thp.thehive.services.CaseOps._
import org.thp.thehive.services.LogOps._
import org.thp.thehive.services.TaskOps._
import org.thp.thehive.services.{LogSrv, OrganisationSrv, TaskSrv}
Expand Down Expand Up @@ -82,8 +83,20 @@ class PublicLog @Inject() (logSrv: LogSrv, organisationSrv: OrganisationSrv) ext
)
override val pageQuery: ParamQuery[OutputParam] = Query.withParam[OutputParam, Traversal.V[Log], IteratorOutput](
"page",
(range, logSteps, _) => logSteps.richPage(range.from, range.to, withTotal = true)(_.richLog)
{

case (OutputParam(from, to, _, 0), logSteps, _) => logSteps.richPage(from, to, withTotal = true)(_.richLog)
case (OutputParam(from, to, _, _), logSteps, authContext) =>
logSteps.richPage(from, to, withTotal = true)(
_.richLogWithCustomRenderer(
_.task.richTaskWithCustomRenderer(
_.`case`.richCase(authContext).option
)
)
)
}
)

override val outputQuery: Query = Query.output[RichLog, Traversal.V[Log]](_.richLog)
override val publicProperties: PublicProperties =
PublicPropertyListBuilder[Log]
Expand Down

0 comments on commit c2f8b23

Please sign in to comment.