Skip to content

Commit

Permalink
#1310 Add bulk delete API
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 17, 2020
1 parent edf2b03 commit 1deef45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ class AlertCtrl @Inject() (
} yield Results.NoContent
}

def bulkDelete: Action[AnyContent] =
entrypoint("bulk delete alerts")
.extract("ids", FieldsParser.string.sequence.on("ids"))
.authTransaction(db) { implicit request => implicit graph =>
val ids: Seq[String] = request.body("ids")
ids
.toTry { alertId =>
for {
alert <- alertSrv
.get(alertId)
.can(Permissions.manageAlert)
.getOrFail()
_ <- alertSrv.cascadeRemove(alert)
} yield ()
}
.map(_ => Results.NoContent)
}

def mergeWithCase(alertId: String, caseId: String): Action[AnyContent] =
entrypoint("merge alert with case")
.authTransaction(db) { implicit request => implicit graph =>
Expand Down
1 change: 1 addition & 0 deletions thehive/app/org/thp/thehive/controllers/v0/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Router @Inject() (
case POST(p"/alert/$alertId/createCase") => alertCtrl.createCase(alertId) // Audit ok
case POST(p"/alert/_search") => queryExecutor.alert.search
// PATCH /alert/_bulk controllers.AlertCtrl.bulkUpdate
case POST(p"/alert/delete/_bulk") => alertCtrl.bulkDelete
case POST(p"/alert/_stats") => queryExecutor.alert.stats
case DELETE(p"/alert/$alertId") => alertCtrl.delete(alertId) // Audit ok
case POST(p"/alert/$alertId/merge/$caseId") => alertCtrl.mergeWithCase(alertId, caseId) // Audit ok
Expand Down

0 comments on commit 1deef45

Please # to comment.