<![CDATA[ User Group Access - My Forums]]> https://forums.modx.com/thread/?thread=82389 <![CDATA[User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-454706
After install I have "Forum Members" group that have access to all globally accessible boards. I've added here a "test" user (not admin user, now it is member of "Forum Members" group only).

My "test" user have access all over the forum.
Good, but I want to have some boards that will be accessible to selected user groups only.

First, I have created a new group "OXC":
give it one context "web" "Member - 9999" "Load, List and View"
and a "test" user as "Member - 9999" ("test" user now is member of "Forum Members" & "OXC" groups).

Question: Should I add second context "web" "Member - 9999" "Discuss Member Policy" to my "OXC" group? Seems that is not necessary, but I have to ask to be sure smiley

Then, I have created a standard board "OXC members only".

As I understand there are two ways to edit access to boards:

#1. Components -> Discuss -> Boards -> "OXC members only" -> Edit Board -> User Group Access
And add here "OXC" group.

#2. Components -> Discuss -> User Groups -> "OXC" -> Update User Group -> Boards
And check here boards to access.

Adding "OXC" group to "OXC members only" board settings causes changes in "OXC"'s checked boards - (#1) causes changes of (#2).
But checking "OXC members only" board in "OXC" group settings not causes changes in "OXC members only" board settings - (#2) not causes changes of (#1).
And it not take effect at all - even after value have been saved, when update-user-group-page reloaded it takes value of board settings (#1), not its own new (allegedly "saved") value. Seems that mechanism (#2) is not working?..

Alright.. let's simply add a group to our board (#1). Save, clear the cache, flush permissions - new settings displays successfully on both pages. But "test" user still do not have access to "OXC members only" board. While Admin and Guest do have! Smiling through tears))) Exactly the opposite result)) What I'm doing wrong?]]>
Alexus Feb 11, 2013, 05:51 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-454706
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-553354
$user->joinGroup('someGroup');
$user->loadAttributes($user, 'web', true);



The second argument is the context key. If empty, the current context will be used.]]>
BobRay Aug 26, 2017, 04:28 PM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-553354
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-553335 For example, a web user logged in at this time was added to the group by using a method call in the snippet, so that the changes take effect, it must be re-login.

How can I make the changes take effect without a web user relogin?

In general, the problem is the same as that of Alexus.
It seems to me that the issue (https://github.com/modxcms/revolution/issues/3860) is not solved correctly.]]>
snowrider Aug 25, 2017, 06:40 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-553335
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456286
I'm thinking about adding this issue to tracker.modx

splittingred, you're the one who fixed similar issue http://tracker.modx.com/issues/3860. I'll be glad to hear some words about my situation.]]>
Alexus Feb 23, 2013, 02:19 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456286
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456278
Anyway, congratulations on finding something that works. smiley
]]>
BobRay Feb 23, 2013, 01:12 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456278
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456212 It works for the current user ("inquisitor", "admin" etc. - any I logged in), not for specified edited user ("test").
Or I am just don't know how to specify the user to which I want to apply these methods.

Also I tried:
$username = 'test';
$user = $modx->getObject('modUser', array('username' => $username));
$user->endSession();

But it ends the current user session! The "test" user remains logged-in.

That's why I use a custom sql query that terminates specified ("test") user session from modx_session table in DB - to logout "test" user:
$sql = "UPDATE modx_session INNER JOIN modx_user_attributes ON modx_user_attributes.sessionid = modx_session.id SET data = '' WHERE modx_user_attributes.id = 2"; // id of "test" user = 2
$q = $modx->prepare($sql);
$q->execute();


So the question remains open... Is there any internal modx methods to refresh specified user session? Or to end specified user session?]]>
Alexus Feb 22, 2013, 09:30 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456212
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456176
$modx->reloadConfig();

$modx->getUser();

$modx->getUser('', true);


$modx->reloadContext();

$modx->reloadContext('mgr');
$modx->reloadContext('web');
]]>
BobRay Feb 22, 2013, 01:38 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456176
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456171 :
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 smiley]]>
Alexus Feb 22, 2013, 12:06 AM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456171
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456155

This should get you a fresh list, unless MODX is refreshing that $_SESSION variable from the cache on each request:

$id = $modx->getLoginUserID();
unset($_SESSION["modx.user.{$id}.userGroupNames"]);



Putting a snippet with this code on another page and forwarding to it after the above code runs might be informative:

$id = $modx->getLoginUserID();
if (isset(($_SESSION["modx.user.{$id}.userGroupNames"])) {
   return 'User Groups are set';
} else {
   return 'User Groups are NOT set'; 
}
]]>
BobRay Feb 21, 2013, 09:50 PM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456155
<![CDATA[Re: User Group Access]]> https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456137
while logged in under any other user (different from the "test") I can get truthful information about "test" user:
$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


while logged in under the "test" user I use the same methods - getUserGroupNames() and $_SESSION[..]:
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 need to logout and login under the "test" user to see updated groups.

Why results of using the same method are different?


Seems that Bug #3860 was fixed for the first case only.]]>
Alexus Feb 21, 2013, 04:26 PM https://forums.modx.com/thread/82389/user-group-access?page=2#dis-post-456137