Actually I've tested that even in 3 browsers
:
1) Modx manager with logged in as "admin". Here I can add/delete the "test" user to groups or just view the result of my front-end user-groups-manage page.
2) Front-end user-groups-manage page with logged in user "inquisitor" that have access to this page. Here I managing the groups of "test" user and also I can view the result by using:
$username = 'test';
$user = $modx->getObject('modUser', array('username' => $username));
print_r ($user->getUserGroupNames()); // returns all groups including newly assigned
print_r ($_SESSION["modx.user.{$user->get('id')}.userGroupNames"]); // returns all groups including newly assigned
3) Logged in "test" user at any page with my snippet just to see the result:
print_r ($modx->user->getUserGroupNames()); // returns only old grops from session, without recently assigned groups
$id = $modx->getLoginUserID() ? (string) $modx->getLoginUserID() : '0';
print_r ($_SESSION["modx.user.{$id}.userGroupNames"]); // the same if I wanted to get groups from the session directly
I also tried what you say. When I'm adding
unset($_SESSION["modx.user.{$user->get('id')}.userGroupNames"]);
to 2) page I have no effect
on 3) page after updating "test" user groups. Info about groups of "test" user on 2) page updates fine without adding that.
I should add
unset($_SESSION["modx.user.{$id}.userGroupNames"]);
to 3) page so the "test" user can refresh his groups by himself.
But this is not the way! Should I say to each managed user: "now go to that page or relogin to refresh your groups list"? I want to press only button on user-groups-manage page and specified user will be added to selected group AND his groups list will be refreshed. Without his relogin and even without any other his action.
Now I add to 2) page sql query that terminates "test" user session from modx_session table in DB. It logouts "test" user so he must login again. And of course his groups list updates successfully when he login again. This is rough way, so I'm trying to find out another.
P.S.: hope I'm clearly explaining on my imperfect English
[ed. note: Alexus last edited this post 11 years, 11 months ago.]