Skip to content

Commit

Permalink
#1355 Attach audit to all shares of task/observable
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 7, 2020
1 parent 909fb25 commit e4d0b34
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 10 additions & 4 deletions thehive/app/org/thp/thehive/services/ObservableSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,16 @@ class ObservableSrv @Inject() (
def remove(observable: Observable with Entity)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
get(observable).alert.headOption() match {
case None =>
for {
share <- get(observable).share(authContext.organisation).getOrFail("Observable")
_ <- auditSrv.observable.delete(observable, share)
} yield get(observable).remove()
get(observable)
.shares
.toIterator
.toTry { share =>
auditSrv
.observable
.delete(observable, share)
.map(_ => get(observable).remove())
}
.map(_ => ())
case Some(alert) => alertSrv.removeObservable(alert, observable)
}

Expand Down
24 changes: 19 additions & 5 deletions thehive/app/org/thp/thehive/services/TaskSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,25 @@ class TaskSrv @Inject() (caseSrvProvider: Provider[CaseSrv], auditSrv: AuditSrv)
auditSrv.task.update(task, Json.obj("assignee" -> JsNull))
}

def cascadeRemove(task: Task with Entity)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
for {
share <- get(task).share(authContext.organisation).getOrFail("Task")
_ <- auditSrv.task.delete(task, share)
} yield get(task).remove()
def remove(task: Task with Entity)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
get(task).caseTemplate.headOption() match {
case None =>
get(task)
.shares
.toIterator
.toTry { share =>
auditSrv
.task
.delete(task, share)
.map(_ => get(task).remove())
}
.map(_ => ())
case Some(caseTemplate) =>
auditSrv
.caseTemplate
.update(caseTemplate, JsObject.empty)
.map(_ => get(task).remove())
}

override def update(
steps: TaskSteps,
Expand Down

0 comments on commit e4d0b34

Please sign in to comment.