Exemplo n.º 1
0
 public function actionDelete()
 {
     if (isset($_POST['delete'])) {
         foreach ($_POST['delete'] as $udrId) {
             $udr = UserDomainRole::findOne($udrId);
             $dom = $udr->getDomain();
             $domName = Yii::t("aaa", 'any');
             if ($dom) {
                 $domName = $dom->name;
             }
             if (!self::can("role/delete") && !self::can("user/update")) {
                 Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to delete roles'));
                 return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
             }
             if (!isset($dom) && !self::can("user/update")) {
                 Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to delete roles on domain {domain}', ['domain' => $domName]));
             }
             if (!self::can("role/delete", $domName)) {
                 Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to delete roles on domain {domain}', ['domain' => $domName]));
             } else {
                 AaaNotification::deleteRole($udr);
                 $groupType = Group::TYPE_DOMAIN;
                 $group = $udr->getGroup();
                 if ($group) {
                     $groupType = $group->type;
                 }
                 if ($udr->delete()) {
                     if ($groupType == Group::TYPE_DOMAIN) {
                         Yii::$app->getSession()->addFlash('success', Yii::t("aaa", 'The role associated with the domain {name} has been deleted', ['name' => $domName]));
                     } else {
                         Yii::$app->getSession()->addFlash('success', Yii::t("aaa", 'The system role has been deleted'));
                     }
                 } else {
                     if ($groupType == Group::TYPE_DOMAIN) {
                         Yii::$app->getSession()->setFlash('error', Yii::t("aaa", 'Error deleting the role associated with the domain') . ' ' . $domName);
                     } else {
                         Yii::$app->getSession()->addFlash('success', Yii::t("aaa", 'Error deleting the system role'));
                     }
                 }
             }
         }
         return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
     }
     return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
 }