public function init()
 {
     $rule = ['allow' => true, 'matchCallback' => function ($rule, $action) {
         return RoleManager::checkAccess($action);
     }];
     $this->rules[] = \Yii::createObject(array_merge($this->ruleConfig, $rule));
     parent::init();
 }
Esempio n. 2
0
 protected function renderDataCellContent($model, $key, $index)
 {
     return preg_replace_callback('/\\{([\\w\\-\\/]+)\\}/', function ($matches) use($model, $key, $index) {
         $action = $matches[1];
         $name = Inflector::camelize(strtr($matches[1], ['/' => '_', '\\' => '_']));
         if (isset($this->buttons[$name]) && $this->buttonIsVisible($name, $model, $key, $index)) {
             $url = $this->createUrl($action, $model, $key, $index);
             if (!$this->checkUrlAccess || RoleManager::checkAccessByUrl($url)) {
                 return call_user_func($this->buttons[$name], $url, $model, $key);
             } else {
                 return '';
             }
         } else {
             return '';
         }
     }, $this->template);
 }
Esempio n. 3
0
 public function normalizePermission($expressionPermission)
 {
     if (strpos($expressionPermission, '*') !== false) {
         $arr = explode(':', $expressionPermission);
         $modules = $this->collectModules($arr[0]);
         $controllers = $this->collectControllers($modules, $arr[1]);
         $actions = $this->collectActions($controllers, $arr[2]);
         $permissions = [];
         foreach ($actions as $action) {
             $permissions[] = RoleManager::formPermissionByAction($action);
         }
         return $permissions;
     } else {
         return [$expressionPermission];
     }
 }