Skip to content

Commit

Permalink
#1557 Use the case returned by mergeInCase to prevent case retrieving…
Browse files Browse the repository at this point in the history
… for each alert
  • Loading branch information
To-om committed Oct 27, 2020
1 parent d73bfd3 commit 3479b14
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,26 @@ class AlertCtrl @Inject() (
.authTransaction(db) { implicit request => implicit graph =>
val alertIds: Seq[String] = request.body("alertIds")
val caseId: String = request.body("caseId")
for {
_ <- alertIds.toTry { alertId =>
caseSrv.get(EntityIdOrName(caseId))
.can(Permissions.manageCase)
.getOrFail("Case")
.flatMap(`case` =>
alertSrv
.get(EntityIdOrName(alertId))
.can(Permissions.manageAlert)
.getOrFail("Alert")
.flatMap(alertSrv.mergeInCase(_, `case`))
)

val destinationCase = caseSrv
.get(EntityIdOrName(caseId))
.can(Permissions.manageCase)
.getOrFail("Case")

alertIds
.foldLeft(destinationCase) { (caseTry, alertId) =>
for {
case0 <- caseTry
alert <-
alertSrv
.get(EntityIdOrName(alertId))
.can(Permissions.manageAlert)
.getOrFail("Alert")
updatedCase <- alertSrv.mergeInCase(alert, case0)
} yield updatedCase
}
richCase <- caseSrv.get(EntityIdOrName(caseId)).richCase.getOrFail("Case")
} yield Results.Ok(richCase.toJson)
.flatMap(c => caseSrv.get(c._id).richCase.getOrFail("Case"))
.map(rc => Results.Ok(rc.toJson))
}

def markAsRead(alertId: String): Action[AnyContent] =
Expand Down

0 comments on commit 3479b14

Please sign in to comment.