From 8d26c374ab086d6ce95203e6ffe61d5eeae43e55 Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 3 Mar 2020 22:42:02 +0100 Subject: [PATCH] #1237 Prevent a user from being in an organization more than once --- thehive/app/org/thp/thehive/services/UserSrv.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/thehive/app/org/thp/thehive/services/UserSrv.scala b/thehive/app/org/thp/thehive/services/UserSrv.scala index b4b81f9f51..8a6f5a2c48 100644 --- a/thehive/app/org/thp/thehive/services/UserSrv.scala +++ b/thehive/app/org/thp/thehive/services/UserSrv.scala @@ -59,11 +59,13 @@ class UserSrv @Inject() (configuration: Configuration, roleSrv: RoleSrv, auditSr implicit graph: Graph, authContext: AuthContext ): Try[RichUser] = - for { - _ <- roleSrv.create(user, organisation, profile) - richUser <- get(user).richUser(organisation.name).getOrFail() - _ <- auditSrv.user.create(user, richUser.toJson) - } yield richUser + get(user).richUser(organisation.name).getOrFail().orElse { + for { + _ <- roleSrv.create(user, organisation, profile) + richUser <- get(user).richUser(organisation.name).getOrFail() + _ <- auditSrv.user.create(user, richUser.toJson) + } yield richUser + } def addOrCreateUser(user: User, avatar: Option[FFile], organisation: Organisation with Entity, profile: Profile with Entity)( implicit graph: Graph,