diff --git a/composer.json b/composer.json index e5cc81f..135dc13 100644 --- a/composer.json +++ b/composer.json @@ -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": [ { diff --git a/src/controllers/AdminController.php b/src/controllers/AdminController.php index cfd873e..8f903f8 100644 --- a/src/controllers/AdminController.php +++ b/src/controllers/AdminController.php @@ -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(); } diff --git a/src/models/UserToken.php b/src/models/UserToken.php index 56e629b..32dfb07 100644 --- a/src/models/UserToken.php +++ b/src/models/UserToken.php @@ -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}}"; } /** @@ -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 @@ -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)"); @@ -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); } /** @@ -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']); } } \ No newline at end of file diff --git a/src/views/admin/index.php b/src/views/admin/index.php index 17122d0..90e8ff6 100644 --- a/src/views/admin/index.php +++ b/src/views/admin/index.php @@ -1,6 +1,8 @@ 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(" Nuevo usuario", ['create'], + ["class" => "dropdown-item"]) + ); +} ?> -

- 'User', - ]), ['create'], ['class' => 'btn btn-success']) ?> -

- + 'Listado de usuarios']) ?> - + render('_search', ['model' => $searchModel]); ?> $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', @@ -71,8 +89,6 @@ // 'updated_at', // 'banned_at', // 'banned_reason', - - ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/src/views/admin/update.php b/src/views/admin/update.php index af64b49..96fd064 100644 --- a/src/views/admin/update.php +++ b/src/views/admin/update.php @@ -1,5 +1,7 @@ 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'); ?>
-

title) ?>

+ "Editar usuario"]) ?> render('_form', [ 'user' => $user, 'profile' => $profile, ]) ?> + + + + + "Eliminar campaña", "margenTop" => true]) ?> + +

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

+ + " Esta acción no puede deshacerse", + "closeButton" => false, + "options" => ["class" => "alert-danger"] + ]) ?> + + $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', + ], + ]) + ?> + +
diff --git a/src/views/admin/view.php b/src/views/admin/view.php index 3680921..0b91e7c 100644 --- a/src/views/admin/view.php +++ b/src/views/admin/view.php @@ -1,5 +1,7 @@ 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; -?> - -

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

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