Skip to content

Commit

Permalink
Merge pull request #98 from UIUCLibrary/no_team
Browse files Browse the repository at this point in the history
Handle cases when user has no team and selects "Change Team"; fixes #97
  • Loading branch information
alexdryden authored Nov 4, 2022
2 parents ddd2ec2 + dd94593 commit bd3f351
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Controller/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,24 +567,27 @@ public function currentTeamAction()
$old_current->setCurrent(null);
$em->flush();
}
$new_current->setCurrent(true);
$em->flush();
$team = $new_current->getTeam();
if ($new_current) {
$new_current->setCurrent(true);
$em->flush();
$team = $new_current->getTeam();

//the sites for the team the user just switched to
//the sites for the team the user just switched to

$team_sites = $team->getTeamSites();
$site_ids = [];
foreach ($team_sites as $team_site):
$site_ids[] = strval($team_site->getSite()->getId());
endforeach;
$team_sites = $team->getTeamSites();
$site_ids = [];
foreach ($team_sites as $team_site):
$site_ids[] = strval($team_site->getSite()->getId());
endforeach;

//update so those are the user's default sites for items
$settingId = 'default_item_sites';
$settingValue = $site_ids;
$this->userSettings()->set($settingId, $settingValue, $user_id);
//update so those are the user's default sites for items
$settingId = 'default_item_sites';
$settingValue = $site_ids;
$this->userSettings()->set($settingId, $settingValue, $user_id);
} else {
$this->messenger()->addError("Team not found");
}

// $em->flush();


return $this->redirect()->toUrl($data['return_url']);
Expand Down

0 comments on commit bd3f351

Please sign in to comment.