소스 검색

[Backend] Access : refactoring

feature/souke
Guillaume Bourgeois 1 년 전
부모
커밋
5d8e45666a
3개의 변경된 파일40개의 추가작업 그리고 14개의 파일을 삭제
  1. +16
    -11
      backend/controllers/AccessController.php
  2. +6
    -0
      common/logic/User/User/Repository/UserRepository.php
  3. +18
    -3
      common/logic/User/User/Service/UserBuilder.php

+ 16
- 11
backend/controllers/AccessController.php 파일 보기

@@ -75,25 +75,28 @@ class AccessController extends BackendController
/**
* Affiche les utilisateurs ayant accès à l'administration de ce producteur.
* Gestion du formulaire permettant d'en ajouter de nouveaux.
*
* @return string
*/
public function actionIndex()
{
$userManager = $this->getUserManager();
$producer = $this->getProducerCurrent();
$userSearch = new UserSearch();
$usersArray = $userSearch->search()->query->all();

$modelAccessUserProducerForm = new AccessUserProducerForm;
if ($modelAccessUserProducerForm->load(\Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) {
$this->setFlash('success', 'Droits ajoutés à l\'utilisateur');
if ($modelAccessUserProducerForm->load(\Yii::$app->request->post()) && $modelAccessUserProducerForm->validate()) {
$user = $userManager->findOneUserById($modelAccessUserProducerForm->id_user);
if($user && $userManager->grantAccess($user)) {
$this->setFlash('success', 'Droits ajoutés à l\'utilisateur');
}
else {
$this->addFlash('error', "Une erreur est survenue.");
}
}

$producer = $this->getProducerCurrent();
$usersAccessArray = $this->getUserManager()->findUsersByProducer($producer);

return $this->render('index', [
'usersArray' => $usersArray,
'usersAccessArray' => $usersAccessArray,
'usersAccessArray' => $userManager->findUsersByProducer($producer),
'producer' => $producer,
'modelAccessUserProducerForm' => $modelAccessUserProducerForm,
]);
@@ -104,9 +107,11 @@ class AccessController extends BackendController
$userManager = $this->getUserManager();
$user = $userManager->findOneUserById($idUser);

if ($user) {
$userManager->deleteAccess($user);
$this->setFlash('success', 'Droits de l\'utilisateur supprimé.');
if ($user && $userManager->deleteAccess($user)) {
$this->addFlash('success', 'Droits de l\'utilisateur supprimé.');
}
else {
$this->addFlash('error', "Une erreur est survenue.");
}

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

+ 6
- 0
common/logic/User/User/Repository/UserRepository.php 파일 보기

@@ -224,4 +224,10 @@ class UserRepository extends AbstractRepository

return count($results);
}

public function isActive(User $user)
{
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
return $userProducer ? $userProducer->active : false;
}
}

+ 18
- 3
common/logic/User/User/Service/UserBuilder.php 파일 보기

@@ -76,10 +76,25 @@ class UserBuilder extends AbstractBuilder
$user->password_reset_token = null;
}

public function grantAccess(User $user): bool
{
if($this->userRepository->isActive($user)) {
$user->id_producer = $this->getProducerContextId();
$user->status = User::STATUS_PRODUCER;
return $user->save();
}

return false;
}

public function deleteAccess(User $user): bool
{
$user->id_producer = 0;
$user->status = User::STATUS_ACTIVE;
return $user->save();
if($this->userRepository->isActive($user)) {
$user->id_producer = null;
$user->status = User::STATUS_ACTIVE;
return $user->save();
}

return false;
}
}

Loading…
취소
저장