From edf2b034e634057f0a6fd76e280760ab2c4e28a9 Mon Sep 17 00:00:00 2001 From: To-om Date: Sun, 17 May 2020 09:31:52 +0200 Subject: [PATCH] #1312 #1311 Use case template from user when importing an alert --- thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala index b65e336806..c368613377 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala @@ -271,14 +271,17 @@ class AlertCtrl @Inject() ( def createCase(alertId: String): Action[AnyContent] = entrypoint("create case from alert") + .extract("caseTemplate", FieldsParser.string.optional.on("caseTemplate")) .authTransaction(db) { implicit request => implicit graph => + val caseTemplate: Option[String] = request.body("caseTemplate") for { (alert, organisation) <- alertSrv .get(alertId) .can(Permissions.manageAlert) .alertUserOrganisation(Permissions.manageCase) - .getOrFail() - richCase <- alertSrv.createCase(alert, None, organisation) + .getOrFail("Alert") + alertWithCaseTemplate = caseTemplate.fold(alert)(ct => alert.copy(caseTemplate = Some(ct))) + richCase <- alertSrv.createCase(alertWithCaseTemplate, None, organisation) } yield Results.Created(richCase.toJson) }