From 711bfb4bba17beadf9f4afefbc87395563684de3 Mon Sep 17 00:00:00 2001 From: To-om Date: Wed, 21 Oct 2020 16:30:50 +0200 Subject: [PATCH] #1565 Change task status when first log is added --- thehive/app/org/thp/thehive/services/LogSrv.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thehive/app/org/thp/thehive/services/LogSrv.scala b/thehive/app/org/thp/thehive/services/LogSrv.scala index 9ad586caba..7f8f68b25d 100644 --- a/thehive/app/org/thp/thehive/services/LogSrv.scala +++ b/thehive/app/org/thp/thehive/services/LogSrv.scala @@ -1,7 +1,7 @@ package org.thp.thehive.services import java.util - +import scala.util.Success import javax.inject.{Inject, Named, Singleton} import org.apache.tinkerpop.gremlin.structure.Graph import org.thp.scalligraph.EntityIdOrName @@ -21,8 +21,9 @@ import play.api.libs.json.{JsObject, Json} import scala.util.Try @Singleton -class LogSrv @Inject() (attachmentSrv: AttachmentSrv, auditSrv: AuditSrv)(implicit @Named("with-thehive-schema") db: Database) - extends VertexSrv[Log] { +class LogSrv @Inject() (attachmentSrv: AttachmentSrv, auditSrv: AuditSrv, taskSrv: TaskSrv, userSrv: UserSrv)(implicit + @Named("with-thehive-schema") db: Database +) extends VertexSrv[Log] { val taskLogSrv = new EdgeSrv[TaskLog, Task, Log] val logAttachmentSrv = new EdgeSrv[LogAttachment, Log, Attachment] @@ -30,6 +31,8 @@ class LogSrv @Inject() (attachmentSrv: AttachmentSrv, auditSrv: AuditSrv)(implic for { createdLog <- createEntity(log) _ <- taskLogSrv.create(TaskLog(), task, createdLog) + user <- userSrv.current.getOrFail("User") // user is used only if task status is waiting but the code is cleaner + _ <- if (task.status == TaskStatus.Waiting) taskSrv.updateStatus(task, user, TaskStatus.InProgress) else Success(()) _ <- auditSrv.log.create(createdLog, task, RichLog(createdLog, Nil).toJson) } yield createdLog