Skip to content

Commit

Permalink
fix: adjust provisioning service to correctly update the display name…
Browse files Browse the repository at this point in the history
… on login

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Nov 6, 2024
1 parent 42fde60 commit bc6fcd3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function createUser(int $providerId, string $userId, ?string $displayName
*/
public function deleteUser(string $userId): DataResponse {
$user = $this->userManager->get($userId);
if (is_null($user) || $user->getBackendClassName() !== 'user_oidc') {
if (is_null($user) || $user->getBackendClassName() !== Application::APP_ID) {
return new DataResponse(['message' => 'User not found'], Http::STATUS_NOT_FOUND);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OcsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function createUser(int $providerId, string $userId, ?string $displayName
*/
public function deleteUser(string $userId): DataResponse {
$user = $this->userManager->get($userId);
if (is_null($user) || $user->getBackendClassName() !== 'user_oidc') {
if (is_null($user) || $user->getBackendClassName() !== Application::APP_ID) {
return new DataResponse(['message' => 'User not found'], Http::STATUS_NOT_FOUND);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Service/ProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\UserOIDC\Service;

use OCA\UserOIDC\AppInfo\Application;
use OCA\UserOIDC\Db\UserMapper;
use OCA\UserOIDC\Event\AttributeMappedEvent;
use OCP\Accounts\IAccountManager;
Expand Down Expand Up @@ -163,6 +164,12 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$oldDisplayName = $user->getDisplayName();
if ($newDisplayName !== $oldDisplayName) {
$user->setDisplayName($newDisplayName);
if ($user->getBackendClassName() === Application::APP_ID) {
$backendUser = $this->userMapper->getOrCreate($providerId, $user->getUID());
$backendUser->setDisplayName($newDisplayName);
$this->userMapper->update($backendUser);
}
$this->eventDispatcher->dispatchTyped(new UserChangedEvent($user, 'displayName', $newDisplayName, $oldDisplayName));
}
}
}
Expand Down

0 comments on commit bc6fcd3

Please sign in to comment.