Пример #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);
     MenuHelper::invalidate();
     return true;
 }
Пример #2
0
 /**
  * Assign or remove items
  * @param string $action
  * @return array
  */
 public function actionRemove()
 {
     $routes = Yii::$app->getRequest()->post('items', []);
     $manager = Yii::$app->getAuthManager();
     $error = [];
     $count = 0;
     foreach ($routes as $route) {
         $route = $manager->createPermission($route);
         try {
             $manager->remove($route);
             $count++;
         } catch (Exception $exc) {
             $error[] = $exc->getMessage();
         }
     }
     MenuHelper::invalidate();
     return ['type' => 'S', 'count' => $count, 'errors' => $error];
 }
Пример #3
0
 /**
  * Assign or remove items
  * @param string $id
  * @param string $action
  * @return array
  */
 public function actionRemoveChild($id)
 {
     $items = Yii::$app->getRequest()->post('items', []);
     $manager = Yii::$app->getAuthManager();
     $parent = $this->findModel($id);
     $error = [];
     $count = 0;
     foreach ((array) $items as $item) {
         $child = $manager->getRole($item);
         $child = $child ?: $manager->getPermission($item);
         try {
             $manager->removeChild($parent, $child);
             $count++;
         } catch (\Exception $exc) {
             $error[] = $exc->getMessage();
         }
     }
     MenuHelper::invalidate();
     return ['type' => 'S', 'count' => $count, 'errors' => $error];
 }
Пример #4
0
 /**
  * Deletes an existing Menu model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param  integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     MenuHelper::invalidate();
     return true;
 }
Пример #5
0
 /**
  * Assign or revoke assignment to user
  * @param  integer $id
  * @param  string  $action
  * @return mixed
  */
 public function actionRevoke($id)
 {
     $items = Yii::$app->request->post('items', []);
     $manager = Yii::$app->authManager;
     $error = [];
     $count = 0;
     foreach ($items as $name) {
         try {
             $item = $manager->getRole($name);
             $item = $item ?: $manager->getPermission($name);
             $manager->revoke($item, $id);
             $count++;
         } catch (\Exception $exc) {
             $error[] = $exc->getMessage();
         }
     }
     MenuHelper::invalidate();
     return ['type' => 'S', 'count' => $count, 'errors' => $error];
 }