diff --git a/thehive/app/org/thp/thehive/services/OrganisationSrv.scala b/thehive/app/org/thp/thehive/services/OrganisationSrv.scala index 6d4115acd8..bc8221e55c 100644 --- a/thehive/app/org/thp/thehive/services/OrganisationSrv.scala +++ b/thehive/app/org/thp/thehive/services/OrganisationSrv.scala @@ -108,11 +108,12 @@ class OrganisationSrv @Inject() ( authContext: AuthContext, graph: Graph ): Try[Unit] = { + val toOrgIds = toOrganisations.map(_.fold(identity, getByName(_)._id.getOrFail("Organisation").get)).toSet val (orgToAdd, orgToRemove) = get(fromOrg) .links ._id .toIterator - .foldLeft((toOrganisations.toSet, Set.empty[EntityId])) { + .foldLeft((toOrgIds, Set.empty[EntityId])) { case ((toAdd, toRemove), o) if toAdd.contains(o) => (toAdd - o, toRemove) case ((toAdd, toRemove), o) => (toAdd, toRemove + o) }