diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 61bca680..130dd6ba 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -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); } diff --git a/lib/Controller/OcsApiController.php b/lib/Controller/OcsApiController.php index dec92024..fbabc5ff 100644 --- a/lib/Controller/OcsApiController.php +++ b/lib/Controller/OcsApiController.php @@ -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); } diff --git a/lib/Service/ProvisioningService.php b/lib/Service/ProvisioningService.php index 02122a1d..39ba4db4 100644 --- a/lib/Service/ProvisioningService.php +++ b/lib/Service/ProvisioningService.php @@ -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; @@ -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)); } } }