Assigning permissions from a package

Permalink
I have a package that creates user groups and pages and restricts access to the pages based on user groups. It also contains a custom registration page that logs in the user once registration has been completed.

The issue I am seeing is that the page permissions are set, but not active and the user is in the user group, but the group permission are not applied. That is, I can see that the page is restricted to the group in the sitemap in the dashboard, but the user cannot access the page until I manually edit the page's permissions and the user logs out and back in. Both these events need to take place to apply the permissions.

Is there a way to "refresh" the page and user permissions to make them active immediately?

Here is the code for adding the page in the package controller
// Add dashboard page
$pg = SinglePage::add('/dashboard', $pkg);
$pg->updateCollectionName(t('Dashboard'));
$pg->assignPermissions(Group::getByID(GUEST_GROUP_ID), array('view_page'), -1); // Remove the guest user group
$pg->assignPermissions(Group::getbyName('Employer'), array('view_page')); // Add the 'Employer' user group
$pg->refreshCache();


Here is the code that is loging in the user:
// Create the user
$ui = \UserInfo::add(array(
   'uName' => $this->post('uEmail'),
   'uEmail' => $this->post('uEmail'), 
   'uPassword' => $this->post('pswd1'),
   'uIsValidated' => 1
));
// Log in the user
$u = User::getByUserID($ui->getUserID(),1);
// Add the user to the Employer group
$g = \Concrete\Core\User\Group\Group::getByName('Employer');
$u->enterGroup($g);

ScottSandbakken
 
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
I found this post:
https://www.concrete5.org/community/forums/customizing_c5/permission...

Based on hutman's post, I have added this to the code that is logging in the user:
$u->refreshUserGroups();


Now the user can immediately access the pages so long as I manually click on each page in the sitemap and re-save the permissions.

I still need to find a way to reset the page permissions when adding a new page through a package. Any help would be appreciated!