johnitvn / yii2-rbac-plus

Database role base access control manager for yii2
49 stars 52 forks source link

Can't create or update rules #35

Open karvit311 opened 6 years ago

karvit311 commented 6 years ago

To create new Permission also before didn't work. But i changed file johnitvn\rbacplus\models**AuthItem.php how said https://github.com/NestorAcevedo by this link: https://gist.github.com/NestorAcevedo/f4db692aaf51470d23841952002fbd4b But still can't create new rule. When i'm trying to add or update new rule - i get this: rbacplus-problem _My example, how i'm creating new Rule:_ ---in field "Rule Name": isAdmin ---in field "Class Name": app/rbac/AdminRule My configuration: 'module' => [ 'rbac' => [ 'class' => 'johnitvn\rbacplus\Module', 'userModelClassName'=>null, 'userModelIdField'=>'id', 'userModelLoginField'=>'username', 'userModelLoginFieldLabel'=>null, 'userModelExtraDataColumls'=>null, 'beforeCreateController'=>null, 'beforeAction'=>null ], ... ], 'components' => [ 'authManager' => [ 'class' => 'dektrium\rbac\components\DbManager', ], ... ], Yii Version: 2.0.13 (basic template) PHP Version: 7.0.22-0 ubuntu0.17.04.1 Thank you in advance!**

tihoho commented 6 years ago

Bro, see other issues in it project. This bug has already been described earlier. Author leave it project (may be died, may be married.)

karvit311 commented 6 years ago

ok, thanx)

Kelvinmbewe commented 6 years ago

Update public function rules () on Rule.php to the code below and also delete public function unique() which is now merged to the rule function:

`public function rules() { return [ [['name', 'className'], 'required'], ['name', 'string', 'max' => 64], ['name', function() { // Moved the unique method code previously declared in the class to this method $authManager = Yii::$app->authManager; $value = $this->name; if ($authManager->getRule($value) !== null) { $message = Yii::t('yii', '{attribute} "{value}" has already been taken.'); $params = [ 'attribute' => $this->getAttributeLabel('name'), 'value' => $value, ]; $this->addError('name', Yii::$app->getI18n()->format($message, $params, Yii::$app->language)); } }, 'when' => function() { return $this->isNewRecord || ($this->item->name != $this->name); }],

        [['className'], 'string'],
        [['className'], 'classExists']
    ];
}`