Skip to content

Commit

Permalink
Fix issue which removes users from all team (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
shishir-intelli authored May 31, 2023
1 parent 56f012c commit d1d2848
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions modules/apigee_edge_teams/src/TeamMembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,22 @@ public function removeMembers(string $team, array $developers): void {
$controller->removeMember($developer);
// Remove team member's roles from Drupal.
if (array_key_exists($developer, $users_by_mail)) {
/** @var \Drupal\apigee_edge_teams\Entity\TeamMemberRoleInterface[] $team_member_roles_in_teams */
$team_member_roles_in_teams = $team_member_role_storage->loadByDeveloper($users_by_mail[$developer]);
foreach ($team_member_roles_in_teams as $team_member_roles_in_team) {
try {
/** @var \Drupal\user\Entity\User $account */
$account = user_load_by_mail($users_by_mail[$developer]->getEmail());
$team_entity = $this->entityTypeManager->getStorage('team')->load($team);

/** @var \Drupal\apigee_edge_teams\Entity\TeamMemberRoleInterface[] $team_member_roles_in_team */
$team_member_roles_in_team = $team_member_role_storage->loadByDeveloperAndTeam($account, $team_entity);
try {
if (!empty($team_member_roles_in_team)) {
$team_member_roles_in_team->delete();
}
catch (EntityStorageException $e) {
$this->logger->critical("Failed to remove %developer team member's roles in %team team with its membership.", [
'%developer' => $developer,
'%team' => $team_member_roles_in_team->getTeam()->id(),
]);
}
}
catch (EntityStorageException $e) {
$this->logger->critical("Failed to remove %developer team member's roles in %team team with its membership.", [
'%developer' => $developer,
'%team' => $team_member_roles_in_team->getTeam()->id(),
]);
}
}
}
Expand Down

0 comments on commit d1d2848

Please sign in to comment.