novaspatiepermissions icon indicating copy to clipboard operation
novaspatiepermissions copied to clipboard

Permissions are not refreshed when adding a role to a permission

Open puzzledmonkey opened this issue 2 years ago • 0 comments

When adding a permission to a role it works fine, but when adding a role to a permission, the ForgetCachedPermissions listener does not fire.

The fix is to just check for the role class as well (in ForgetCachedPermissions)

$permissionKey = (Nova::resourceForModel(app(PermissionRegistrar::class)->getPermissionClass()))::uriKey();
$roleKey = (Nova::resourceForModel(app(PermissionRegistrar::class)->getRoleClass()))::uriKey();

if ($request->viaRelationship === $permissionKey || $request->viaRelationship === $roleKey) {
    app(PermissionRegistrar::class)->forgetCachedPermissions();
}

puzzledmonkey avatar Jun 04 '22 12:06 puzzledmonkey