diff --git a/thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala b/thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala index c56932088d..3f1c57023a 100644 --- a/thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala +++ b/thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala @@ -399,6 +399,19 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema { .removeIndex("Log", IndexType.fulltext, "message") .removeIndex("Tag", IndexType.fulltext, "description") .removeIndex("Task", IndexType.fulltext, "description") + .updateGraph("Set caseId in imported alerts", "Alert") { traversal => + traversal + .project( + _.by + .by(_.out("AlertCase")._id.option) + ) + .foreach { + case (vertex, caseId) => + caseId.foreach(vertex.property("caseId", _)) + case _ => + } + Success(()) + } val reflectionClasses = new Reflections( new ConfigurationBuilder() diff --git a/thehive/app/org/thp/thehive/services/AlertSrv.scala b/thehive/app/org/thp/thehive/services/AlertSrv.scala index 11db879d50..e237b30997 100644 --- a/thehive/app/org/thp/thehive/services/AlertSrv.scala +++ b/thehive/app/org/thp/thehive/services/AlertSrv.scala @@ -262,6 +262,7 @@ class AlertSrv @Inject() ( createdCase <- caseSrv.create(case0, assignee, organisation, customField, caseTemplate, Nil) _ <- importObservables(alert.alert, createdCase.`case`) _ <- alertCaseSrv.create(AlertCase(), alert.alert, createdCase.`case`) + _ <- get(alert.alert).update(_.caseId, Some(createdCase._id)).getOrFail("Alert") _ <- markAsRead(alert._id) _ = integrityCheckActor ! EntityAdded("Alert") } yield createdCase diff --git a/thehive/test/org/thp/thehive/controllers/v0/StatusCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/StatusCtrlTest.scala index e230120e39..1557f0ddeb 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/StatusCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/StatusCtrlTest.scala @@ -70,7 +70,7 @@ class StatusCtrlTest extends PlaySpecification with TestAppBuilder { "pollingDuration" -> 1000 ), "schemaStatus" -> Json.arr( - Json.obj("name" -> "thehive", "currentVersion" -> 66, "expectedVersion" -> 66, "error" -> JsNull) + Json.obj("name" -> "thehive", "currentVersion" -> 67, "expectedVersion" -> 67, "error" -> JsNull) ) )