Example #1
0
 /** @inheritdoc */
 protected function validateValue($value)
 {
     if (!is_array($value)) {
         return [\Yii::t('rbac', 'Invalid value'), []];
     }
     foreach ($value as $val) {
         if ($this->manager->getItem($val) == null) {
             return [\Yii::t('rbac', 'There is neither role nor permission with name "{0}"', [$val]), []];
         }
     }
 }
Example #2
0
 /**
  * Updated items children.
  */
 protected function updateChildren()
 {
     $children = $this->manager->getChildren($this->item->name);
     $childrenNames = array_keys($children);
     if (is_array($this->children)) {
         // remove children that
         foreach (array_diff($childrenNames, $this->children) as $item) {
             $this->manager->removeChild($this->item, $children[$item]);
         }
         // add new children
         foreach (array_diff($this->children, $childrenNames) as $item) {
             $this->manager->addChild($this->item, $this->manager->getItem($item));
         }
     } else {
         $this->manager->removeChildren($this->item);
     }
 }
Example #3
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     // register translations
     if (!isset($app->get('i18n')->translations['rbac*'])) {
         $app->get('i18n')->translations['rbac*'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => __DIR__ . '/messages'];
     }
     if ($this->checkRbacModuleInstalled($app)) {
         // register auth manager
         if (!$this->checkAuthManagerConfigured($app)) {
             $app->set('authManager', ['class' => DbManager::className()]);
         }
         // if dektrium/user extension is installed, copy admin list from there
         if ($this->checkUserModuleInstalled($app)) {
             $app->getModule('rbac')->admins = $app->getModule('user')->admins;
         }
     }
 }
Example #4
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     // register translations
     if (!isset($app->get('i18n')->translations['rbac*'])) {
         $app->get('i18n')->translations['rbac*'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => __DIR__ . '/messages'];
     }
     if ($this->checkRbacModuleInstalled($app)) {
         $authManager = $app->get('authManager', false);
         if (!$authManager) {
             $app->set('authManager', ['class' => DbManager::className()]);
         } else {
             if (!$authManager instanceof ManagerInterface) {
                 throw new InvalidConfigException('You have wrong authManager configuration');
             }
         }
         // if dektrium/user extension is installed, copy admin list from there
         if ($this->checkUserModuleInstalled($app) && $app instanceof WebApplication) {
             $app->getModule('rbac')->admins = $app->getModule('user')->admins;
         }
     }
 }
Example #5
0
 /**
  * Returns all available auth items to be attached to user.
  * @return array
  */
 public function getAvailableItems()
 {
     return ArrayHelper::map($this->manager->getItems(), 'name', function ($item) {
         return empty($item->description) ? $item->name : $item->name . ' (' . $item->description . ')';
     });
 }
Example #6
0
 /**
  * This method will set [[authManager]] to be the 'authManager' application component, if it is `null`.
  */
 public function init()
 {
     parent::init();
     $this->authManager = Instance::ensure($this->authManager, DbManager::className());
 }