I have been using RBAC (on advanced template) for some time without any problems on production and development servers. A while back I installed rmrevin/yii2-comments on the dev server and it works perfectly. Now I have deployed it to production, but the RBAC permissions are not working.
I have ruled out the database. If I point the production app to the dev db, or point the dev app to the production db, the problem follows the app, not the db. In addition, I can tell the comments extension to use any other existing rule (e.g. \Yii::$app->getUser()->can(‘createProfile’) and it works. It just will not recognize any new permission (with or without a rule), even those provided in the installation instructions of the extension:
<?php
use \rmrevin\yii\module\Comments\Permission;
use \rmrevin\yii\module\Comments\rbac\ItsMyComment;
$AuthManager = \Yii::$app->getAuthManager();
$ItsMyCommentRule = new ItsMyComment();
$AuthManager->add($ItsMyCommentRule);
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::CREATE,
'description' => 'Can create own comments',
]));
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::UPDATE,
'description' => 'Can update all comments',
]));
...etc.
I have even switched from johnitvn/yii2-rbac-plus to dektrium/yii2-rbac, but that hasn’t helped.
Here is my configuration in common/config/main.php:
'modules' => [
'rbac' => [
'class' => 'dektrium\rbac\RbacWebModule',
],
'comments' => [
'class' => 'rmrevin\yii\module\Comments\Module',
'userIdentityClass' => 'common\models\User',
'useRbac' => true,
],
],
'components' => [
'authManager' => [
'class' => 'dektrium\rbac\components\DbManager',
'cache' => 'yii\caching\FileCache',
],
],
What could possibly be causing the application to ignore new permissions?
UPDATE: Here’s another symptom that may have the same root cause. I created a controller console/controllers/RbacController.php. Whenever I try to run the console command “yii rbac/init” I get a not found error. If I rename rbac to anything else (e.g. RBacController and run “yii r-bac/init”) without changing anything in the file, it works fine.
In summary, I’m seeing two issues. RbacController is not recognized, and any new permissions I create are not recognized. I’m guessing these two things are related, but what is the root cause?