Skip to content
Snippets Groups Projects
Commit a94489a6 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Utilisation du '''usernamefield''' pour les affichages

parent 7dbf8975
No related branches found
No related tags found
No related merge requests found
Pipeline #17883 passed
......@@ -58,6 +58,12 @@ class UtilisateurController extends AbstractActionController
$this->identityProvider = $provider;
}
private ?string $usernamefield;
public function setUsernamefield(?string $usernamefield): void
{
$this->usernamefield = $usernamefield;
}
public function indexAction()
{
$roles = $this->roleService->findAll();
......@@ -76,13 +82,13 @@ class UtilisateurController extends AbstractActionController
if (isset($this->searchServices[$source])) {
$sourceUser = $this->searchServices[$source]->findById($id);
$newUser = $this->userService->importFromRechercheIndividuResultatInterface($sourceUser, $source);
$user = $this->userService->findByUsername($newUser->getUsername());
$user = $this->userService->findByUsername($newUser->getUsername($this->usernamefield));
if (!$user) {
$user = $this->userService->create($newUser);
} else {
$this->flashMessenger()->addErrorMessage(
sprintf("L'utilisateur <strong>%s (%s)</strong> existe déjà dans l'application.", $user->getDisplayName(), $user->getUsername())
sprintf("L'utilisateur <strong>%s (%s)</strong> existe déjà dans l'application.", $user->getDisplayName(), $user->getUsername($this->usernamefield))
);
}
......@@ -263,12 +269,12 @@ class UtilisateurController extends AbstractActionController
foreach ($this->searchServices as $key => $service) {
$currentUsernames = array_map(function($u) {
/** @var RechercheIndividuResultatInterface $u */
return $u->getUsername();
return $u->getUsername($this->usernamefield);
}, $currentUsers);
$users = $service->findByTerm($term);
$usersFiltered = array_filter($users, function($e) use ($currentUsernames) {
/** @var RechercheIndividuResultatInterface $e */
return !in_array($e->getUsername(), $currentUsernames);
return !in_array($e->getUsername($this->usernamefield), $currentUsernames);
});
$currentUsers = array_merge($currentUsers, $usersFiltered);
$finalUsers[$key] = $usersFiltered;
......@@ -281,7 +287,7 @@ class UtilisateurController extends AbstractActionController
'id' => $key . '||' . $individu->getId(),
'label' => $individu->getDisplayName(),
'extra' => sprintf(' <span class="text-highlight">/</span> %s <span class="text-highlight">/</span> %s %s',
$individu->getUsername(),
$individu->getUsername($this->usernamefield),
$individu->getEmail() ?: "aucun email",
($key === 'app') ? '<i title="Utilisateur existant" class="fas fa-check-circle text-success"></i>' : '')
];
......@@ -311,7 +317,7 @@ class UtilisateurController extends AbstractActionController
$records = [];
foreach ($users as $user) {
$item = [];
$item[] = $user->getUsername();
$item[] = $user->getUsername($this->usernamefield);
$item[] = $user->getDisplayName();
$item[] = $user->getState();
......
......@@ -31,6 +31,7 @@ class UtilisateurControllerFactory
*/
$config = $container->get('Config');
$moduleConfig = $config['unicaen-utilisateur'];
$usernamefield = $config['unicaen-auth']['local']['ldap']['username'];
$roleService = $container->get(RoleService::class);
$userService = $container->get(UserService::class);
$initCompte = $container->get('FormElementManager')->get(InitCompteForm::class);
......@@ -63,6 +64,8 @@ class UtilisateurControllerFactory
$controller->setUserForm($userForm);
$controller->setUserRechercheForm($userRechercheForm);
$controller->setUsernameField($usernamefield);
return $controller;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment