|
|
@@ -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() { |
|
|
|
|