From ec415b90f7bf791eb3f2c6170d9391bfb515cca6 Mon Sep 17 00:00:00 2001 From: Tristan Garwood Date: Thu, 29 Aug 2024 10:47:34 -0400 Subject: [PATCH] ID-1369 Repair cloud access followup, increment group version (#1530) --- .../dsde/workbench/sam/service/UserService.scala | 6 ++++-- .../dsde/workbench/sam/service/UserServiceSpec.scala | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala index 10c0cf376..5972106ad 100644 --- a/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala +++ b/src/main/scala/org/broadinstitute/dsde/workbench/sam/service/UserService.scala @@ -495,9 +495,11 @@ class UserService( maybeUser.flatMap { case Some(user) => for { - _ <- cloudExtensions.onUserCreate(user, samRequestContext) - _ <- cloudExtensions.onUserEnable(user, samRequestContext) + // if the user is already created and enabled, then recover and just add them to the groups they should be in + _ <- cloudExtensions.onUserCreate(user, samRequestContext).recover { case _ => () } + _ <- cloudExtensions.onUserEnable(user, samRequestContext).recover { case _ => () } groups <- directoryDAO.listUserDirectMemberships(user.id, samRequestContext) + _ = groups.map(g => directoryDAO.updateGroupUpdatedDateAndVersionWithSession(g, samRequestContext)) _ <- cloudExtensions.onGroupUpdate(groups, Set(user.id), samRequestContext) } yield IO.pure(()) case None => IO.raiseError(new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, s"User $workbenchUserId not found"))) diff --git a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala index 8096c8001..ae49cdf56 100644 --- a/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala +++ b/src/test/scala/org/broadinstitute/dsde/workbench/sam/service/UserServiceSpec.scala @@ -739,6 +739,11 @@ class OldUserServiceSpec(_system: ActorSystem) val updatedUserInPostgres = dirDAO.loadUser(invitedUserId, samRequestContext).unsafeRunSync() updatedUserInPostgres.value shouldBe SamUser(invitedUserId, registeringUser.googleSubjectId, inviteeEmail, None, true) + // add user to group + val group = BasicWorkbenchGroup(WorkbenchGroupName("testGroup"), Set.empty, WorkbenchEmail("fake@group.com")) + runAndWait(dirDAO.createGroup(group, None, samRequestContext)) + runAndWait(dirDAO.addGroupMember(group.id, invitedUserId, samRequestContext)) + val proxyGroup = WorkbenchGroupName(s"${googleServicesConfig.resourceNamePrefix.getOrElse("")}PROXY_${invitedUserId.value}@${googleServicesConfig.appsDomain}") // delete proxy group @@ -749,6 +754,10 @@ class OldUserServiceSpec(_system: ActorSystem) verify(googleExtensions).onUserCreate(updatedUserInPostgres.get, samRequestContext) verify(googleExtensions).onUserEnable(updatedUserInPostgres.get, samRequestContext) - verify(googleExtensions).onGroupUpdate(Seq(allUsersGroup.id), Set(invitedUserId), samRequestContext) + verify(googleExtensions).onGroupUpdate(Seq(allUsersGroup.id, group.id), Set(invitedUserId), samRequestContext) + + // get group from db + val groupWithUpdatedVersion = runAndWait(dirDAO.loadGroup(group.id, samRequestContext)) + groupWithUpdatedVersion.get.version shouldBe group.version + 1 } }