Beispiel #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));
 }
Beispiel #2
0
 static function deleteRole($udr, $group = null, $domain = null)
 {
     if (!isset($group)) {
         $group = $udr->getGroup();
     }
     if (!isset($group)) {
         $domain = Domain::findOne(['name' => $udr->domain]);
     }
     //Remove notificações relativas ao antigo papel
     if ($domain) {
         AaaNotification::deleteNotificationsGroup($udr->user_id, $group, $domain->name);
     } else {
         AaaNotification::deleteNotificationsGroup($udr->user_id, $group, null);
     }
     //Notificação removido papel
     if ($domain) {
         AaaNotification::create($udr->user_id, Notification::NOTICE_TYPE_DEL_GROUP, $group->id, $domain->name);
     } else {
         AaaNotification::create($udr->user_id, Notification::NOTICE_TYPE_DEL_GROUP, $group->id, null);
     }
 }
Beispiel #3
0
 /**
  * GET NOTIFICATIONS
  * @param string $dateParam
  * @return string
  * Retorna o html com até 6 notificações, ja formatado para ser exibido.
  * Quando recebe uma data de entrada, a utiliza como limite, e retorna apenas o que vem depois dela
  */
 public static function getNotifications($dateParam)
 {
     $userId = Yii::$app->user->getId();
     if (!$dateParam) {
         AuthorizationNotification::clearAuthorizations($userId);
     }
     //Caso seja a primeira solicitação
     $array = "";
     $max = 0;
     $date = null;
     //Le todas reservas anteriores a data limite, ou todas reservas, caso não exista uma data limite
     if ($dateParam) {
         $notifications = Notification::find()->where(['user_id' => $userId])->andWhere(['<', 'date', $_POST['date']])->orderBy(['date' => SORT_DESC])->all();
     } else {
         $notifications = Notification::find()->where(['user_id' => $userId])->orderBy(['date' => SORT_DESC])->all();
     }
     //Se não contem, gera aviso de que o usuário não possui notificações
     if (count($notifications) == 0) {
         $info = [];
         $info['date'] = null;
         $info['array'] = "<li style='text-align: center;'><span style='float: none !important;'><h2>" . Yii::t("notify", 'You don`t have notifications yet.') . "</h2></span></li>";
         $info['more'] = false;
         return $info;
     }
     //Percorre as notificações gerando o HTML
     foreach ($notifications as $notification) {
         if ($max < 6) {
             $msg = "";
             switch ($notification->type) {
                 case self::TYPE_AUTHORIZATION:
                     $msg = AuthorizationNotification::makeHtml($notification);
                     break;
                 case self::TYPE_RESERVATION:
                     $msg = ReservationNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
                 case self::TYPE_NOTICE:
                     $msg = AaaNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
                 case self::TYPE_TOPOLOGY:
                     $msg = TopologyNotification::makeHtml($notification);
                     $notification->viewed = true;
                     $notification->save();
                     break;
             }
             if ($msg == "") {
                 $notification->delete();
             } else {
                 $array .= $msg;
                 $date = $notification->date;
             }
         }
         if ($msg != "") {
             $max++;
         }
         if ($max == 7) {
             break;
         }
     }
     $info = [];
     $info['date'] = $date;
     //Data da ultima notificação retornada, utilizada como limite para ler as proximas em leituras futuras
     $info['array'] = $array;
     //HTML a ser exibido
     if ($max == 7) {
         $info['more'] = true;
     } else {
         $info['more'] = false;
     }
     return $info;
 }