As designed applyGlobalPermission doesn't work until a permission save is done

Yugensoft

Well-known member
Affected version
2.0.1
I'm using $this->applyGlobalPermission in Setup classes. However after running the install step, it doesn't pass through to permissions in templates (e.g. "$xf.visitor.hasPermission('x', 'y')").

To make it pass through, I have to manually go to User group permissions in ACP and press save.

This is problematic, as the purpose is that a feature be immediately present to the user after the addon is installed.
 
This is not a bug. Please consider using the following code:

PHP:
    public function postInstall(array &$stateChanges)
    {
        $this->app->jobManager()->enqueueUnique(
            'permissionRebuild',
            'XF:PermissionRebuild',
            [],
            false
        );
    }

You can also apply a postUpgrade step to your Setup.php file. Example:

PHP:
public function postUpgrade($previousVersion, array &$stateChanges)
{
    $this->app->jobManager()->enqueueUnique(
        'permissionRebuild',
        'XF:PermissionRebuild',
        [],
        false
    );
}


Fillip
 
Top Bottom