Skip to content

Commit

Permalink
#1565 Change task status when first log is added
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent 1d74258 commit 3e8dfea
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions thehive/app/org/thp/thehive/services/LogSrv.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,15 +21,18 @@ 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]

def create(log: Log, task: Task with Entity)(implicit graph: Graph, authContext: AuthContext): Try[Log with Entity] =
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

Expand Down

0 comments on commit 3e8dfea

Please sign in to comment.