/**
  * 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']);
 }
 public function actionAssign($action)
 {
     $post = Yii::$app->getRequest()->post();
     $routes = $post['routes'];
     $manager = Yii::$app->getAuthManager();
     if ($action == 'assign') {
         $this->saveNew($routes);
     } else {
         foreach ($routes as $route) {
             $child = $manager->getPermission($route);
             try {
                 $manager->remove($child);
             } catch (Exception $e) {
             }
         }
     }
     AccessHelper::refeshAuthCache();
     Yii::$app->getResponse()->format = Response::FORMAT_JSON;
     return [$this->actionRouteSearch('new', $post['search_av']), $this->actionRouteSearch('exists', $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'])];
 }
 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'])];
 }