/**
  * Assign or revoke assignment to user
  * @param  integer $id
  * @param  string  $action
  * @return mixed
  */
 public function actionAsignarPermisos()
 {
     try {
         Yii::$app->response->format = 'json';
         if (Yii::$app->request->isAjax) {
             $usuario = SeguridadUsuarios::findOne(Yii::$app->request->post('id'));
             if ($usuario) {
                 $grupo = Grupo::findOne(Yii::$app->request->post('grupo'));
                 if ($grupo) {
                     $tipo = intval(Yii::$app->request->post('tipo'));
                     if ($tipo == 1) {
                         $model = new UsuarioGrupo();
                         $model->id_grupo = $grupo->id_grupo;
                         $model->id_usuario = $usuario->id_usuario;
                         $model->save();
                     } else {
                         if ($tipo == -1) {
                             $model = UsuarioGrupo::findOne(['id_grupo' => $grupo->id_grupo, 'id_usuario' => $usuario->id_usuario]);
                             if ($model) {
                                 $model->delete();
                             }
                         }
                     }
                     return ['success' => true];
                 }
             }
         }
     } catch (\yii\db\IntegrityException $ex) {
         return ['success' => false, 'message' => "El usuario ya tiene los permisos asignados."];
     } catch (Exception $ex) {
         return ['success' => false, 'message' => $ex->getMessage()];
     }
     return ['success' => false, 'message' => "No se pudo procesar la solicitud."];
 }
 /**
  * Finds the Grupo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Grupo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Grupo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }