Skip to content

Commit

Permalink
fix: Synchronize LDAP users using their identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Aug 14, 2023
1 parent 2acfbb7 commit baa12e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/MessageHandler/SynchronizeLdapHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public function __invoke(SynchronizeLdap $message): void
$countErrors = 0;

foreach ($ldapUsers as $ldapUser) {
$user = $userRepository->findOneBy(['email' => $ldapUser->getEmail()]);
$user = $userRepository->findOneBy([
'ldapIdentifier' => $ldapUser->getLdapIdentifier(),
]);

if ($user) {
$user->setLdapIdentifier($ldapUser->getLdapIdentifier());
$user->setEmail($ldapUser->getEmail());
$user->setName($ldapUser->getName());

Expand Down
6 changes: 3 additions & 3 deletions tests/MessageHandler/SynchronizeLdapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public function testInvokeUpdateUsers(): void
/** @var MessageBusInterface */
$bus = $container->get(MessageBusInterface::class);
$user = UserFactory::createOne([
'email' => 'charlie@example.com',
'email' => 'cgature@example.com',
'name' => 'C. Gature',
'ldapIdentifier' => 'cgature',
'ldapIdentifier' => 'charlie',
]);

$bus->dispatch(new SynchronizeLdap());

$user->refresh();
$this->assertSame('charlie', $user->getLdapIdentifier());
$this->assertSame('[email protected]', $user->getEmail());
$this->assertSame('Charlie Gature', $user->getName());
$this->assertSame('charlie', $user->getLdapIdentifier());
}
}

0 comments on commit baa12e6

Please sign in to comment.