Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-authclient": "*",
"faro/core": "dev-develop"
"faro/core": "dev-feature/v20221-integracion-agro-gonza"
},
"autoload": {
"psr-4": { "faro\\core\\user\\": "src" }
},
"extra": {
"branch-alias": {
"dev-develop": "2022.1-dev"
}
"branch-alias": {}
},
"repositories": [
{
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function init()
throw new ForbiddenHttpException('You are not allowed to perform this action.');
}

$this->view->params["navbar_menu_selected"] = "administracion";
$this->view->params["ocultar_selector_fechas"] = true;
parent::init();
}

Expand Down
124 changes: 66 additions & 58 deletions src/models/UserToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,11 @@ class UserToken extends ActiveRecord
public $module;

/**
* @inheritdoc
*/
public function init()
{
if (!$this->module) {
$this->module = Yii::$app->getModule("user");
}
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('user', 'ID'),
'user_id' => Yii::t('user', 'User ID'),
'type' => Yii::t('user', 'Type'),
'token' => Yii::t('user', 'Token'),
'data' => Yii::t('user', 'Data'),
'created_at' => Yii::t('user', 'Created At'),
'expired_at' => Yii::t('user', 'Expired At'),
];
}

/**
* @inheritdoc
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'updatedAtAttribute' => false,
'value' => function ($event) {
return gmdate("Y-m-d H:i:s");
},
],
];
}

/**
* @return \yii\db\ActiveQuery
* @return string
*/
public function getUser()
public static function tableName()
{
$user = $this->module->model("User");
return $this->hasOne($user::className(), ['id' => 'user_id']);
return "{{%core_acl_usuario_token}}";
}

/**
Expand Down Expand Up @@ -129,6 +86,18 @@ public static function generate($userId, $type, $data = null, $expireTime = null
return $model;
}

/**
* Find a userToken by userId
* @param int $userId
* @param array|int $type
* @param bool $checkExpiration
* @return static
*/
public static function findByUser($userId, $type, $checkExpiration = true)
{
return static::findBy("user_id", $userId, $type, $checkExpiration);
}

/**
* Find a userToken by specified field/value
* @param string $field
Expand All @@ -139,7 +108,7 @@ public static function generate($userId, $type, $data = null, $expireTime = null
*/
public static function findBy($field, $value, $type, $checkExpiration)
{
$query = static::find()->where([$field => $value, "type" => $type ]);
$query = static::find()->where([$field => $value, "type" => $type]);
if ($checkExpiration) {
$now = gmdate("Y-m-d H:i:s");
$query->andWhere("([[expired_at]] >= '$now' or [[expired_at]] is NULL)");
Expand All @@ -148,15 +117,15 @@ public static function findBy($field, $value, $type, $checkExpiration)
}

/**
* Find a userToken by userId
* @param int $userId
* Find a userToken by data
* @param string $data
* @param array|int $type
* @param bool $checkExpiration
* @return static
*/
public static function findByUser($userId, $type, $checkExpiration = true)
public static function findByData($data, $type, $checkExpiration = true)
{
return static::findBy("user_id", $userId, $type, $checkExpiration);
return static::findBy("data", $data, $type, $checkExpiration);
}

/**
Expand All @@ -172,14 +141,53 @@ public static function findByToken($token, $type, $checkExpiration = true)
}

/**
* Find a userToken by data
* @param string $data
* @param array|int $type
* @param bool $checkExpiration
* @return static
* @inheritdoc
*/
public static function findByData($data, $type, $checkExpiration = true)
public function init()
{
return static::findBy("data", $data, $type, $checkExpiration);
if (!$this->module) {
$this->module = Yii::$app->getModule("user");
}
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('user', 'ID'),
'user_id' => Yii::t('user', 'User ID'),
'type' => Yii::t('user', 'Type'),
'token' => Yii::t('user', 'Token'),
'data' => Yii::t('user', 'Data'),
'created_at' => Yii::t('user', 'Created At'),
'expired_at' => Yii::t('user', 'Expired At'),
];
}

/**
* @inheritdoc
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'updatedAtAttribute' => false,
'value' => function ($event) {
return gmdate("Y-m-d H:i:s");
},
],
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
$user = $this->module->model("User");
return $this->hasOne($user::className(), ['id' => 'user_id']);
}
}
48 changes: 32 additions & 16 deletions src/views/admin/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use faro\core\components\ControlUsuarios;
use faro\core\components\FaroGridView;
use faro\core\widgets\AccionesLayoutWidget;
use faro\core\widgets\Panel;
use yii\helpers\Html;
use yii\grid\GridView;
Expand All @@ -19,48 +21,64 @@
$role = $module->model("Role");

$this->title = Yii::t('user', 'Users');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Administración'), 'url' => ['/faro/admin']];
$this->params['breadcrumbs'][] = $this->title;

$this->params["navbar_menu_selected"] = "administracion";

if (ControlUsuarios::esAdmin()) {
AccionesLayoutWidget::agregarBoton(
\yii\bootstrap4\Html::a("<i class='fas fa-plus-circle'></i> Nuevo usuario", ['create'],
["class" => "dropdown-item"])
);
}
?>
<p>
<?= Html::a(Yii::t('user', 'Create {modelClass}', [
'modelClass' => 'User',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>

<div class="user-index">

<?php Panel::begin(['header' => 'Listado de usuarios']) ?>

<?php // echo $this->render('_search', ['model' => $searchModel]); ?>

<?php \yii\widgets\Pjax::begin(); ?>
<?= FaroGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'filterModel' => null,
'headerContainer' => ['class' => ''],
'striped' => false,
"bordered" => false,
"layout" => "{items}\n{pager}",
'columns' => [
'id',
[
'attribute' => 'role_id',
'label' => Yii::t('user', 'Role'),
'filter' => $role::dropdown(),
'value' => function($model, $index, $dataColumn) use ($role) {
'value' => function ($model, $index, $dataColumn) use ($role) {
$roleDropdown = $role::dropdown();
return $roleDropdown[$model->role_id];
},
],
'profile.full_name' => [
"attribute" => "profile.full_name",
"format" => "raw",
"value" => function ($model) {
return \yii\bootstrap4\Html::a($model->profile->full_name,
["view", "id" => $model->id]);
}
],
'email:email',
[
'attribute' => 'status',
'label' => Yii::t('user', 'Status'),
'filter' => $user::statusDropdown(),
'value' => function($model, $index, $dataColumn) use ($user) {
'value' => function ($model, $index, $dataColumn) use ($user) {
$statusDropdown = $user::statusDropdown();
return $statusDropdown[$model->status];
},
],
'email:email',
'profile.full_name',

'profile.timezone',
'created_at',
'created_at:relativeTime',
// 'username',
// 'password',
// 'auth_key',
Expand All @@ -71,8 +89,6 @@
// 'updated_at',
// 'banned_at',
// 'banned_reason',

['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php \yii\widgets\Pjax::end(); ?>
Expand Down
37 changes: 32 additions & 5 deletions src/views/admin/update.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use faro\core\widgets\Panel;
use yii\bootstrap4\Alert;
use yii\helpers\Html;

/**
Expand All @@ -8,20 +10,45 @@
* @var faro\core\user\models\Profile $profile
*/

$this->title = Yii::t('user', 'Update {modelClass}: ', [
'modelClass' => 'User',
]) . ' ' . $user->id;
$this->title = "Actualizar usuario " . $user->profile->full_name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Administración'), 'url' => ['/faro/admin']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $user->id, 'url' => ['view', 'id' => $user->id]];
$this->params['breadcrumbs'][] = ['label' => $user->profile->full_name, 'url' => ['view', 'id' => $user->id]];
$this->params['breadcrumbs'][] = Yii::t('user', 'Update');
?>
<div class="user-update">

<h1><?= Html::encode($this->title) ?></h1>
<?php Panel::begin(["header" => "Editar usuario"]) ?>

<?= $this->render('_form', [
'user' => $user,
'profile' => $profile,
]) ?>

<?php Panel::end() ?>


<?php Panel::begin(["header" => "Eliminar campaña", "margenTop" => true]) ?>

<p>Para eliminar este usuario ingresá desde acá. Si creés que en un futuro puede volver a ser
necesario te sugerimos que lo desactives.</p>

<?= Alert::widget([
"body" => "<i class='fas fa-exclamation-triangle mr-2'></i> Esta acción no puede deshacerse",
"closeButton" => false,
"options" => ["class" => "alert-danger"]
]) ?>

<?=
Html::a("Eliminar usuario", ['delete', 'id' => $user->id], [
'class' => 'btn btn-danger btn-block shadow-sm d-sm-inline-block',
'data' => [
'confirm' => Yii::t('app', 'Esta seguro que desea eliminar este usuario?'),
'method' => 'post',
],
])
?>

<?php Panel::end() ?>

</div>
23 changes: 10 additions & 13 deletions src/views/admin/view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use faro\core\components\ControlUsuarios;
use faro\core\widgets\AccionesLayoutWidget;
use faro\core\widgets\Panel;
use yii\helpers\Html;
use yii\widgets\DetailView;
Expand All @@ -9,22 +11,17 @@
* @var faro\core\user\models\User $user
*/

$this->title = $user->email;
$this->title = $user->profile->full_name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Administración'), 'url' => ['/faro/admin']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<p>
<?= Html::a(Yii::t('user', 'Update'), ['update', 'id' => $user->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('user', 'Delete'), ['delete', 'id' => $user->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('user', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>

if (ControlUsuarios::esAdmin()) {
AccionesLayoutWidget::agregarBoton(
\yii\bootstrap4\Html::a("<i class='fas fa-edit'></i> Editar usuario", ['update', "id" => $user->id], ["class" => "dropdown-item"])
);
}
?>

<div class="user-view">

Expand Down