From 4dff8072eed77fa1c018e34cb3e2861d09da7299 Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 5 Apr 2022 09:41:09 +0200 Subject: [PATCH] #2368 Add integrity check to remove orphan user --- .../thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala | 2 +- thehive/app/org/thp/thehive/services/UserSrv.scala | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala index dc1a7d6a8b..1aa7df543c 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala @@ -58,7 +58,7 @@ class JobCtrl @Inject() ( db.roTransaction { implicit graph => val artifactId: String = request.body("artifactId") for { - o <- observableSrv.get(EntityIdOrName(artifactId)).richObservable.getOrFail("Observable") + o <- observableSrv.get(EntityIdOrName(artifactId)).can(Permissions.manageAnalyse).richObservable.getOrFail("Observable") c <- observableSrv.get(EntityIdOrName(artifactId)).`case`.getOrFail("Case") } yield (o, c) }.fold( diff --git a/thehive/app/org/thp/thehive/services/UserSrv.scala b/thehive/app/org/thp/thehive/services/UserSrv.scala index b92e077de9..0e324fa4d4 100644 --- a/thehive/app/org/thp/thehive/services/UserSrv.scala +++ b/thehive/app/org/thp/thehive/services/UserSrv.scala @@ -353,6 +353,7 @@ class UserIntegrityCheck @Inject() ( (_.out("UserRole"), _.in("UserRole")), (_.out("RoleOrganisation"), _.in("RoleOrganisation")) ).flatMap(ElementSelector.firstCreatedElement(_)).map(e => removeVertices(e._2)).size - Map("duplicateRoleLinks" -> duplicateRoleLinks.toLong) + val orphanCount = service.startTraversal.filterNot(_.organisations).sideEffect(_.drop()).getCount + Map("duplicateRoleLinks" -> duplicateRoleLinks.toLong, "orphan" -> orphanCount) } }