Example #1
0
 /**
  * 
  * @param int $id
  * @return boolean
  */
 public static function disable($id)
 {
     $workflow = BpmWorkflow::findOne(['id' => $id]);
     $workflow->active = 0;
     $domain = Domain::findOne(['name' => $workflow->domain]);
     if (!$domain) {
         return false;
     }
     if (!$workflow->save()) {
         return false;
     }
     // Procura por execuções em aberto envolvendo o workflow.
     $flows = BpmFlow::find()->where(['workflow_id' => $id])->all();
     foreach ($flows as $flow) {
         $conId = $flow->connection_id;
         //Deleta o fluxo
         $flow->delete();
         //Deleta autorizações
         ConnectionAuth::deleteAll(['connection_id' => $conId, 'domain' => $domain->name]);
         //Cria novo fluxo, com workflow desativado
         BpmFlow::startFlow($conId, $domain->name);
         //Dispara continuidade dos workflows
         Connection::continueWorkflows($conId, true);
     }
     return true;
 }
 static function clearAuthorizations($userId)
 {
     //Limpa as notificações de autorização que ja foram respondidas
     $notAuth = Notification::find()->where(['user_id' => $userId, 'type' => Notification::TYPE_AUTHORIZATION, 'viewed' => false])->all();
     foreach ($notAuth as $not) {
         //Confere todas notificações do tipo autorização
         $auth = ConnectionAuth::findOne($not->info);
         if ($auth) {
             $connection = Connection::findOne($auth->connection_id);
             if ($connection) {
                 $connections = Connection::find()->where(['reservation_id' => $connection->reservation_id])->all();
                 $answered = true;
                 foreach ($connections as $conn) {
                     //Confere todas conexões da reserva conferindo se alguma ainda esta pendente
                     $auths = ConnectionAuth::find()->where(['domain' => $auth->domain, 'connection_id' => $conn->id])->all();
                     foreach ($auths as $a) {
                         //Confere as autorizaçòes daquela conexão
                         if ($a->type != ConnectionAuth::TYPE_WORKFLOW && $a->status == Connection::AUTH_STATUS_PENDING) {
                             $answered = false;
                             break;
                         }
                     }
                     if ($answered == false) {
                         break;
                     }
                 }
                 if ($answered) {
                     //Se ja foi respondida modifica notificação para visualizada
                     $not->viewed = true;
                     $not->save();
                 }
             }
         }
     }
 }
 /**
  * ACTION REJECT
  * @param string $id
  * @param string $message
  */
 public function actionReject($id = null, $message = null)
 {
     Yii::trace("Reject");
     Yii::trace("ID: " . $id);
     Yii::trace("Msg: " . $message);
     if ($id) {
         $req = ConnectionAuth::findOne(['id' => $id]);
         if ($req->type == ConnectionAuth::TYPE_GROUP) {
             $req->manager_user_id = Yii::$app->user->getId();
         }
         if ($message != null) {
             $req->manager_message = $message;
         }
         $req->status = Connection::AUTH_STATUS_REJECTED;
         $req->save();
         $flow = new BpmFlow();
         $flow->response($req->connection_id, $req->domain, BpmFlow::STATUS_NO);
     }
 }
Example #4
0
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\data\ArrayDataProvider;
use meican\base\components\LinkColumn;
use meican\circuits\models\Reservation;
use meican\circuits\models\Connection;
use meican\circuits\models\ConnectionPath;
use meican\circuits\models\ConnectionAuth;
use meican\aaa\models\User;
$this->params['header'] = [Yii::t('circuits', 'Pending Authorization'), ['Home', Yii::t('circuits', 'Circuits')]];
?>

<div class="box box-default">
    <div class="box-body">      
	<?php 
echo Grid::widget(['options' => ['class' => 'list'], 'dataProvider' => $data, 'id' => 'gridInfo', 'filterModel' => $searchModel, 'layout' => "{items}{summary}{pager}", 'columns' => array(['label' => Yii::t('circuits', 'Reply request as '), 'value' => 'domain', 'filter' => Html::activeDropDownList($searchModel, 'domain', ArrayHelper::map(ConnectionAuth::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'contentOptions' => ['style' => 'font-weight: bold;'], 'headerOptions' => ['style' => 'width: 23%;']], ['label' => Yii::t('circuits', 'Source Domain'), 'value' => function ($aut) {
    if ($aut->source) {
        return $aut->source;
    } else {
        return Yii::t('circuits', 'deleted');
    }
}, 'filter' => Html::activeDropDownList($searchModel, 'src_domain', ArrayHelper::map(ConnectionPath::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'headerOptions' => ['style' => 'width: 21%;']], ['label' => Yii::t('circuits', 'Destination Domain'), 'value' => function ($aut) {
    if ($aut->destination) {
        return $aut->destination;
    } else {
        return Yii::t('circuits', 'deleted');
    }
}, 'filter' => Html::activeDropDownList($searchModel, 'dst_domain', ArrayHelper::map(ConnectionPath::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'headerOptions' => ['style' => 'width: 21%;']], ['label' => Yii::t('circuits', 'Requester'), 'value' => function ($aut) {
    $user_id = $aut->request_user_id;
    return User::findOne(['id' => $user_id])->name;
}, 'headerOptions' => ['style' => 'width: 12%;']], ['label' => Yii::t('circuits', 'Bandwidth'), 'value' => function ($aut) {
 public function searchByDomains($params)
 {
     $this->load($params);
     $userId = Yii::$app->user->getId();
     $now = DateUtils::now();
     $authorizations = [];
     //Armazena os pedidos
     $reservationsVisited = [];
     //Armazena as reservas ja incluidas nos pedidos e o dominio ao qual o pedido foi feito.
     //Pega todas requisições feitas para o usuário
     if ($this->domain) {
         $userRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all();
     } else {
         $userRequests = ConnectionAuth::find()->where(['manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all();
     }
     foreach ($userRequests as $request) {
         //Limpa mantendo apenas 1 por reserva
         $uniq = true;
         $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one();
         if (isset($conn)) {
             $request->changeStatusToExpired();
             $conn->auth_status = Connection::AUTH_STATUS_EXPIRED;
             $conn->save();
             ReservationNotification::create($conn->id);
         } else {
             $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one();
             foreach ($reservationsVisited as $res) {
                 if ($conn->reservation_id == $res[0] && $request->domain == $res[1]) {
                     $uniq = false;
                 }
             }
             if ($uniq) {
                 $aux = [];
                 $aux[0] = $conn->reservation_id;
                 $aux[1] = $request->domain;
                 $reservationsVisited[] = $aux;
                 $source = $conn->getFirstPath()->one();
                 $destination = $conn->getLastPath()->one();
                 if (!$this->src_domain || $this->src_domain == $source->domain) {
                     if (!$this->dst_domain || $this->dst_domain == $destination->domain) {
                         $form = new AuthorizationForm();
                         $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain);
                         $authorizations[] = $form;
                     }
                 }
             }
         }
     }
     //Pega todos os papeis do usuário
     $domainRoles = User::findOne(['id' => $userId])->getRoles()->all();
     foreach ($domainRoles as $role) {
         //Passa por todos papeis
         if ($this->domain) {
             $groupRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all();
         } else {
             $groupRequests = ConnectionAuth::find()->where(['manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all();
         }
         foreach ($groupRequests as $request) {
             //Passa por todas requisições para testar se o dominio corresponde
             $domain = Domain::findOne(['name' => $request->domain]);
             if ($domain) {
                 if ($role->domain == NULL || $role->domain == $domain->name) {
                     $uniq = true;
                     $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one();
                     if (isset($conn)) {
                         $request->changeStatusToExpired();
                         $conn->auth_status = Connection::AUTH_STATUS_EXPIRED;
                         $conn->save();
                         ReservationNotification::create($conn->id);
                     } else {
                         $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one();
                         foreach ($reservationsVisited as $res) {
                             if ($conn->reservation_id == $res[0] && $domain->name == $res[1]) {
                                 $uniq = false;
                             }
                         }
                         if ($uniq) {
                             $aux = [];
                             $aux[0] = $conn->reservation_id;
                             $aux[1] = $request->domain;
                             $reservationsVisited[] = $aux;
                             $source = $conn->getFirstPath()->one();
                             $destination = $conn->getLastPath()->one();
                             if (!$this->src_domain || $this->src_domain == $source->domain) {
                                 if (!$this->dst_domain || $this->dst_domain == $destination->domain) {
                                     $form = new AuthorizationForm();
                                     $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain);
                                     $authorizations[] = $form;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $dataProvider = new ArrayDataProvider(['allModels' => $authorizations, 'sort' => false, 'pagination' => ['pageSize' => 15]]);
     return $dataProvider;
 }
Example #6
0
 public function createUserAuth($flow, $reservation)
 {
     Yii::trace("Criando Request User Authorization");
     //Confere se o usuário ja respondeu exatamente mesma requisição, se sim, não questiona novamente.
     $auth = ConnectionAuth::findOne(['type' => ConnectionAuth::TYPE_USER, 'domain' => $flow->domain, 'manager_user_id' => $flow->value, 'connection_id' => $flow->connection_id]);
     if ($auth) {
         return true;
     }
     //Confere se usuário requisitante é o mesmo que deve responder. Se sim, não pergunta, considera aceito.
     if ($flow->value == $reservation->request_user_id) {
         $flow->status = self::STATUS_YES;
         $flow->save();
         return true;
     }
     $auth = new ConnectionAuth();
     $auth->domain = $flow->domain;
     $auth->status = Connection::AUTH_STATUS_PENDING;
     $auth->type = ConnectionAuth::TYPE_USER;
     $auth->manager_user_id = $flow->value;
     $auth->connection_id = $flow->connection_id;
     $auth->save();
     AuthorizationNotification::createToUser($flow->value, $flow->domain, $reservation->id, $auth->id);
     return false;
 }
Example #7
0
 static function deleteNotificationsGroup($user_id, $group, $domain)
 {
     $user = User::findOne($user_id);
     if ($user && $group) {
         Yii::trace("Remover notificações do grupo " . $group->name . " para usuário " . $user->name);
         //Busca todas autorizações do grupo
         //Se tem domínio, procura só as relacionadas ao domínio do papel
         if ($domain) {
             $auths = ConnectionAuth::find()->where(['domain' => $domain, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         } else {
             $auths = ConnectionAuth::find()->where(['type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all();
         }
         //Passa por todas deletando uma notificação
         foreach ($auths as $auth) {
             $notification = Notification::findOne(['user_id' => $user_id, 'type' => Notification::TYPE_AUTHORIZATION, 'info' => $auth->id]);
             if ($notification) {
                 $notification->delete();
             }
         }
     }
 }
Example #8
0
 public static function cancelConnAuthRequest($connId)
 {
     $types = [self::TYPE_USER, self::TYPE_GROUP];
     $auth = ConnectionAuth::find()->where(['connection_id' => $connId, 'status' => Connection::AUTH_STATUS_PENDING])->andWhere(['in', 'type', $types])->one();
     if ($auth) {
         $auth->changeStatusToExpired();
         $connection = Connection::findOne($connId);
         $connection->auth_status = Connection::AUTH_STATUS_EXPIRED;
         $connection->save();
     }
 }
Example #9
0
 public static function continueWorkflows($id, $asking = true)
 {
     Yii::trace("CONTINUA WORKFLOWS");
     $paths = ConnectionPath::find()->select('DISTINCT `domain`')->where(['conn_id' => $id])->all();
     Yii::trace("Dominios envolvidos:");
     foreach ($paths as $path) {
         Yii::trace($path->domain);
     }
     //Analisa se existem pedidos em espera. Neste momento, realiza as perguntas aos admins.
     foreach ($paths as $path) {
         if (Connection::findOne(['id' => $id])->auth_status == self::AUTH_STATUS_REJECTED) {
             break;
         } else {
             $domain = Domain::findOne(['name' => $path->domain]);
             if (isset($domain)) {
                 BpmFlow::doRequest($id, $domain->name, $asking);
             }
         }
         if (ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) {
             break;
         }
         //Se tem uma pergunta ativa.
     }
     if (!$asking || ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) {
         return;
     }
     $conn = Connection::findOne(['id' => $id]);
     if ($conn->auth_status == self::AUTH_STATUS_PENDING) {
         $conn->auth_status = self::AUTH_STATUS_APPROVED;
         if (!$conn->save()) {
         }
         if (!$conn->isCancelStatus()) {
             $conn->requestProvision();
         }
     }
     //Remove fluxos não finalizados
     BpmFlow::removeFlows($id);
 }