re #25 allow rules edition + assignment
This commit is contained in:
@ -13,6 +13,7 @@ namespace Da\User\Model;
|
||||
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
use Da\User\Validator\RbacItemsValidator;
|
||||
use Da\User\Validator\RbacRuleExistsValidator;
|
||||
use Da\User\Validator\RbacRuleValidator;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
@ -41,7 +42,7 @@ abstract class AbstractAuthItem extends Model
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $children;
|
||||
public $children = [];
|
||||
/**
|
||||
* @var \yii\rbac\Role|\yii\rbac\Permission
|
||||
*/
|
||||
@ -60,7 +61,7 @@ abstract class AbstractAuthItem extends Model
|
||||
$this->description = $this->item->description;
|
||||
$this->children = array_keys($this->getAuthManager()->getChildren($this->item->name));
|
||||
if ($this->item->ruleName !== null) {
|
||||
$this->rule = get_class($this->getAuthManager()->getRule($this->item->ruleName));
|
||||
$this->rule = $this->item->ruleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,7 +112,7 @@ abstract class AbstractAuthItem extends Model
|
||||
},
|
||||
],
|
||||
['children', RbacItemsValidator::class],
|
||||
['rule', RbacRuleValidator::class],
|
||||
['rule', RbacRuleExistsValidator::class],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
60
src/User/Model/Rule.php
Normal file
60
src/User/Model/Rule.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Model;
|
||||
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
use Da\User\Validator\RbacRuleNameValidator;
|
||||
use Da\User\Validator\RbacRuleValidator;
|
||||
use yii\base\Model;
|
||||
|
||||
class Rule extends Model
|
||||
{
|
||||
use AuthManagerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @var string fully qualified class name. Not to be confused with className() method
|
||||
*/
|
||||
public $className;
|
||||
/**
|
||||
* @var string holds the name of the rule previous update
|
||||
*/
|
||||
public $previousName;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
return [
|
||||
'create' => ['name', 'className'],
|
||||
'update' => ['name', 'className', 'previousName'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'className'], 'trim'],
|
||||
[['name', 'className'], 'required'],
|
||||
[['name', 'previousName'], 'match', 'pattern' => '/^[\w][\w-.:]+[\w]$/'],
|
||||
[['name'], RbacRuleNameValidator::class, 'previousName' => $this->previousName],
|
||||
[['className'], RbacRuleValidator::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user