diff --git a/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala b/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala index ec0b7d077a..9e691401d7 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala @@ -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 { diff --git a/thehive/app/org/thp/thehive/controllers/v0/Conversion.scala b/thehive/app/org/thp/thehive/controllers/v0/Conversion.scala index e1c739654d..c43f3c45fe 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/Conversion.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/Conversion.scala @@ -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 = diff --git a/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala index 7f3135ee2d..d15aa34020 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala @@ -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} @@ -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]