Browse Source

Backend : modification d'utilisateurs

Pouvoir modifier les utilisateurs liés uniquement à l'établissement courant.
Pour les autres, affichage d'un message indiquant que l'utilisateur n'est pas modifiable.
prodstable
keun 8 years ago
parent
commit
7249a040ce
3 changed files with 47 additions and 11 deletions
  1. +20
    -10
      backend/controllers/UserController.php
  2. +22
    -1
      backend/views/user/index.php
  3. +5
    -0
      backend/web/js/lechatdesnoisettes.js

+ 20
- 10
backend/controllers/UserController.php View File

@@ -14,6 +14,7 @@ use common\helpers\Upload ;
use common\helpers\Password ;
use common\models\UserEtablissement ;
use common\models\Etablissement ;
use yii\base\UserException ;

/**
* UserController implements the CRUD actions for User model.
@@ -37,7 +38,8 @@ class UserController extends BackendController
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
if($action->actionMethod == 'actionIndex' ||
$action->actionMethod == 'actionCreate')
$action->actionMethod == 'actionCreate' ||
$action->actionMethod == 'actionUpdate')
{
return Yii::$app->user->identity->status == USER::STATUS_ADMIN
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER ;
@@ -66,7 +68,7 @@ class UserController extends BackendController
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
@@ -137,12 +139,20 @@ class UserController extends BackendController
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one() ;
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' =>$id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) ;
if(($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN)
{
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs boulangeries, soit parce qu'il n'est pas lié à la votre.");
}
}

@@ -152,12 +162,12 @@ class UserController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
/*public function actionDelete($id)
{
$this->findModel($id)->delete();

return $this->redirect(['index']);
}
}*/

public function actionMail() {

+ 22
- 1
backend/views/user/index.php View File

@@ -2,6 +2,7 @@

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
@@ -23,7 +24,27 @@ $this->params['breadcrumbs'][] = $this->title;
'nom',
'prenom',
'telephone',
'email'
'email',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}',
'headerOptions' => ['class' => 'actions'],
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['id']]) ;
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one() ;
if(count($user->userEtablissement) == 1)
{
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
}
else {
return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les utilisateurs qui appartiennent à plusieurs boulangeries."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ;
}
},
],
],
],
]); ?>


+ 5
- 0
backend/web/js/lechatdesnoisettes.js View File

@@ -10,10 +10,15 @@ $(document).ready(function() {
chat_btn_plus_moins() ;
chat_commandeauto() ;
chat_points_vente_acces() ;
chat_tooltip() ;
// admin
chat_select_etablissement() ;
}) ;

function chat_tooltip() {
$('[data-toggle="tooltip"]').tooltip();
}

function chat_points_vente_acces() {
$('#pointvente-acces_restreint').change(function() {
chat_points_vente_acces_event() ;

Loading…
Cancel
Save