From b879920ef5e7d284029357427af9ba5cae317a4c Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 10 Mar 2020 14:30:16 +0100 Subject: [PATCH] #1255 Ignore case template in alert if it doesn't exist --- .../app/org/thp/thehive/controllers/v0/AlertCtrl.scala | 4 ++-- .../app/org/thp/thehive/controllers/v1/AlertCtrl.scala | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala index 84ef31f308..a4e3bb6853 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala @@ -15,7 +15,7 @@ import org.thp.scalligraph.models.Database import org.thp.scalligraph.query.{ParamQuery, PropertyUpdater, PublicProperty, Query} import org.thp.scalligraph.steps.PagedResult import org.thp.scalligraph.steps.StepsOps._ -import org.thp.scalligraph.{RichOptionTry, RichSeq, _} +import org.thp.scalligraph.{RichSeq, _} import org.thp.thehive.controllers.v0.Conversion._ import org.thp.thehive.dto.v0.{InputAlert, InputObservable} import org.thp.thehive.models._ @@ -84,9 +84,9 @@ class AlertCtrl @Inject() ( val inputAlert: InputAlert = request.body("alert") val observables: Seq[InputObservable] = request.body("observables") val customFields = inputAlert.customFields.map(c => c.name -> c.value).toMap + val caseTemplate = caseTemplateName.flatMap(caseTemplateSrv.get(_).visible.headOption()) for { organisation <- userSrv.current.organisations(Permissions.manageAlert).get(request.organisation).getOrFail() - caseTemplate <- caseTemplateName.map(caseTemplateSrv.get(_).visible.getOrFail()).flip richObservables <- observables.toTry(createObservable).map(_.flatten) richAlert <- alertSrv.create(request.body("alert").toAlert, organisation, inputAlert.tags, customFields, caseTemplate) _ <- auditSrv.mergeAudits(richObservables.toTry(o => alertSrv.addObservable(richAlert.alert, o)))(_ => Success(())) diff --git a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala index ca694786c5..bf90f8d116 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala @@ -3,7 +3,6 @@ package org.thp.thehive.controllers.v1 import play.api.mvc.{Action, AnyContent, Results} import javax.inject.{Inject, Singleton} -import org.thp.scalligraph.RichOptionTry import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.scalligraph.models.Database import org.thp.scalligraph.query.{ParamQuery, PropertyUpdater, PublicProperty, Query} @@ -53,13 +52,8 @@ class AlertCtrl @Inject() ( .authTransaction(db) { implicit request => implicit graph => val caseTemplateName: Option[String] = request.body("caseTemplate") val inputAlert: InputAlert = request.body("alert") + val caseTemplate = caseTemplateName.flatMap(ct => caseTemplateSrv.get(ct).visible.headOption()) for { - caseTemplate <- caseTemplateName.map { ct => - caseTemplateSrv - .get(ct) - .visible - .getOrFail() - }.flip organisation <- userSrv.current.organisations(Permissions.manageAlert).getOrFail() customFields = inputAlert.customFieldValue.map(cf => cf.name -> cf.value).toMap richAlert <- alertSrv.create(request.body("alert").toAlert, organisation, inputAlert.tags, customFields, caseTemplate)