Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create or update rules #35

Open
karvit311 opened this issue Nov 28, 2017 · 3 comments
Open

Can't create or update rules #35

karvit311 opened this issue Nov 28, 2017 · 3 comments

Comments

@karvit311
Copy link

karvit311 commented Nov 28, 2017

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
Copy link

tihoho commented Jan 26, 2018

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
Copy link
Author

ok, thanx)

@Kelvinmbewe
Copy link
Contributor

Kelvinmbewe commented Oct 19, 2018

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']
    ];
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants