Permissions not working immediately

Permalink 1 user found helpful
I have some code added to a page that automatically adds a user to a specific group:

$g = Group::getByID(5);
$u = new User();
$u->enterGroup($g);


The code is working but the permissions for that group aren't taking affect until after the user logs out and then logs back in? Is there a way to make C5 recognize the permissions of that group as soon as someone is added to it?

For example, I have a page that this group cannot access. After adding the user to that group with the code above, they are still able to access that page (even though the code did successfully add them to the group). After logging out and then logging back in, they are then unable to access that page.

How can I make the permissions go into affect before they log out (as soon as they are added to that group)?

Thanks.

 
TNTdesign replied on at Permalink Reply
Looking into this further, I still don't have an answer for this but now know that if a user is added to a group while their logged in, the permissions of that new group won't go into affect until the next time they log in.

Is there a way to force the user to log out? Not ideal, but that would be better than what I have.
TNTdesign replied on at Permalink Reply
So, I ended up just forcing a logout with /login/logout which reset the permissions. Not super user friendly but for what I'm trying to do, it'll be fine. Thanks.
jfhencken replied on at Permalink Reply
jfhencken
I am using v8.5.2 and basic permissions. I also have the same problem.
I programmatically use $user->enterGroup($groupIn); so that a page can now be seen by the user which was previously hidden after they submit a form.
But the page does not appear on the NAV immediately. I must logout and then login again for the change to take effect.
Is there a refresh() function call to make the enterGroup() function take effect immediately?
Will converting over to advanced permissions solve this problem?
hutman replied on at Permalink Reply
hutman
If I remember correctly it's this function

$user->refreshUserGroups();
jfhencken replied on at Permalink Reply
jfhencken
I found the same function and I am calling it without generating any errors but also without making the previously hidden (by permission) page appear on the NAV. Its still only appears on the NAV after a logout and re-login.

I'm wondering if this is standard behavior. It would sure be nice if someone knowledgeable in this area of C5 functionality could share their expertise with us.