[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsProducer($this->getUserCurrent()); } ] ], ], ]; } /** * Affiche les utilisateurs ayant accès à l'administration de ce producteur. * Gestion du formulaire permettant d'en ajouter de nouveaux. */ public function actionIndex() { $userModule = $this->getUserModule(); $producer = $this->getProducerCurrent(); $userSearch = new UserSearch(); $usersArray = $userSearch->search()->query->all(); $modelAccessUserProducerForm = new AccessUserProducerForm; if ($modelAccessUserProducerForm->load(\Yii::$app->request->post()) && $modelAccessUserProducerForm->validate()) { $user = $userModule->findOneUserById($modelAccessUserProducerForm->id_user); if($user && $userModule->grantAccess($user)) { $this->setFlash('success', 'Droits ajoutés à l\'utilisateur'); } else { $this->addFlash('error', "Une erreur est survenue."); } } return $this->render('index', [ 'usersArray' => $usersArray, 'usersAccessArray' => $userModule->findUsersByProducer($producer), 'producer' => $producer, 'modelAccessUserProducerForm' => $modelAccessUserProducerForm, ]); } public function actionDelete($idUser) { $userModule = $this->getUserModule(); $user = $userModule->findOneUserById($idUser); if ($user && $userModule->deleteAccess($user)) { $this->addFlash('success', 'Droits de l\'utilisateur supprimé.'); } else { $this->addFlash('error', "Une erreur est survenue."); } return $this->redirect(['index']); } }