Example #1
0
 /**
  * Deletes an existing AuthItem model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     Yii::$app->authManager->remove($model->item);
     AccessHelper::refeshAuthCache();
     return $this->redirect(['index']);
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['name'], 'required'], [['parent_name'], 'filterParent'], [['parent_name'], 'in', 'range' => self::find()->select(['name'])->column(), 'message' => 'Menu "{value}" not found.'], [['parent', 'route', 'data', 'order'], 'default'], [['order'], 'integer'], [['route'], 'in', 'range' => AccessHelper::getSavedRoutes(), 'message' => 'Route "{value}" not found.']];
 }
 public function actionAssign($id, $action)
 {
     $post = Yii::$app->getRequest()->post();
     $roles = $post['roles'];
     $manager = Yii::$app->getAuthManager();
     $parent = $manager->getPermission($id);
     if ($action == 'assign') {
         foreach ($roles as $role) {
             $child = $manager->getPermission($role);
             try {
                 $manager->addChild($parent, $child);
             } catch (\Exception $e) {
             }
         }
     } else {
         foreach ($roles as $role) {
             $child = $manager->getPermission($role);
             try {
                 $manager->removeChild($parent, $child);
             } catch (\Exception $e) {
             }
         }
     }
     AccessHelper::refeshAuthCache();
     Yii::$app->getResponse()->format = Response::FORMAT_JSON;
     return [$this->actionRoleSearch($id, 'avaliable', $post['search_av']), $this->actionRoleSearch($id, 'assigned', $post['search_asgn'])];
 }
 public function actionAssign($id, $action)
 {
     $post = Yii::$app->request->post();
     $roles = $post['roles'];
     $manager = Yii::$app->authManager;
     if ($action == 'assign') {
         foreach ($roles as $role) {
             try {
                 $manager->assign($manager->getRole($role), $id);
             } catch (\Exception $exc) {
             }
         }
     } else {
         foreach ($roles as $role) {
             try {
                 $manager->revoke($manager->getRole($role), $id);
             } catch (\Exception $exc) {
             }
         }
     }
     AccessHelper::refeshAuthCache();
     Yii::$app->response->format = Response::FORMAT_JSON;
     return [$this->actionRoleSearch($id, 'avaliable', $post['search_av']), $this->actionRoleSearch($id, 'assigned', $post['search_asgn'])];
 }
Example #5
0
 private function saveNew($routes)
 {
     $manager = Yii::$app->getAuthManager();
     foreach ($routes as $route) {
         try {
             $r = explode('&', $route);
             $item = $manager->createPermission('/' . trim($route, '/'));
             if (count($r) > 1) {
                 $action = '/' . trim($r[0], '/');
                 if (($itemAction = $manager->getPermission($action)) === null) {
                     $itemAction = $manager->createPermission($action);
                     $manager->add($itemAction);
                 }
                 unset($r[0]);
                 foreach ($r as $part) {
                     $part = explode('=', $part);
                     $item->data['params'][$part[0]] = isset($part[1]) ? $part[1] : '';
                 }
                 AccessHelper::setDefaultRouteRule();
                 $item->ruleName = AccessHelper::ROUTE_RULE_NAME;
                 $manager->add($item);
                 $manager->addChild($item, $itemAction);
             } else {
                 $manager->add($item);
             }
         } catch (Exception $e) {
         }
     }
 }