Skip to content

Commit

Permalink
#1973 Don't remove observables/tasks when a share is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 15, 2021
1 parent 0aa353f commit 5b0e05b
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions thehive/app/org/thp/thehive/services/ShareSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,14 @@ class ShareSrv @Inject() (implicit
} yield newShareProfile
}

private def delete(shareId: EntityIdOrName)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
for {
share <- getOrFail(shareId)
tasks = get(share).tasks.toSeq
obs = get(share).observables.toSeq
_ <- tasks.toTry(taskSrv.delete(_))
_ <- obs.toTry(observableSrv.delete(_))
} yield get(shareId).remove()

def unshareCase(shareId: EntityIdOrName)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
for {
organisation <- get(shareId).organisation.getOrFail("Organisation")
case0 <- get(shareId).`case`.removeValue(_.organisationIds, organisation._id).getOrFail("Case")
_ = get(shareId).observables.removeValue(_.organisationIds, organisation._id).barrier().filterNot(_.shares.range(1, 2)).remove()
_ = get(shareId).tasks.removeValue(_.organisationIds, organisation._id).barrier().filterNot(_.shares.range(1, 2)).remove()
_ <- auditSrv.share.unshareCase(case0, organisation)
_ <- delete(shareId)
} yield ()
} yield get(shareId).remove()

def unshareTask(
task: Task with Entity,
Expand Down

0 comments on commit 5b0e05b

Please sign in to comment.