Exemplo n.º 1
0
 public function actionScanAction()
 {
     $params = Yii::$app->request->queryParams;
     $module = isset($params['module']) ? $params['module'] : '';
     $controller = isset($params['controller']) ? $params['controller'] : '';
     $this->validateController($module, $controller);
     $controllerActions = $this->getPublicActions($controller, $module);
     // 已经存在数据库中的action
     $existsActions = models\RbacAuthitems::getExistsControllerAction($module, $controller);
     // 新增的actions
     $newActions = array_diff($controllerActions, $existsActions);
     // 添加新的授权项
     $actions = Yii::$app->request->post('actions');
     if ($actions) {
         $allowed = Yii::$app->request->post('allowed', []);
         if (is_array($allowed)) {
             $allowed = array_intersect($newActions, $allowed);
         }
         // 过滤只能新增的action
         $actions = array_intersect($newActions, $actions);
         if (models\RbacAuthitems::addAuthItems($module, $controller, $actions, $allowed)) {
             $newActions = array_diff($newActions, $actions);
         }
     }
     return $this->render('/rbac/authitems/scanAction', ['module' => $module, 'controller' => $controller, 'controllerActions' => $newActions, 'existsActions' => $existsActions]);
 }