Skip to content

Commit aa811d2

Browse files
committed
make the user backend a ISetDisplayNameBackend one, this fixes incorrect photo in system addressbook vcard and simplifies the provisioning service
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 3ccad1e commit aa811d2

2 files changed

Lines changed: 17 additions & 25 deletions

File tree

lib/Service/ProvisioningService.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use InvalidArgumentException;
1111
use OC\Accounts\AccountManager;
12-
use OCA\UserOIDC\AppInfo\Application;
1312
use OCA\UserOIDC\Db\UserMapper;
1413
use OCA\UserOIDC\Event\AttributeMappedEvent;
1514
use OCP\Accounts\IAccountManager;
@@ -176,29 +175,10 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
176175
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
177176
$oidcGssUserData[$displaynameAttribute] = $event->getValue();
178177
$newDisplayName = $event->getValue();
179-
if ($existingLocalUser === null) {
180-
$oldDisplayName = $backendUser->getDisplayName();
181-
if ($newDisplayName !== $oldDisplayName) {
182-
$backendUser->setDisplayName($newDisplayName);
183-
$this->userMapper->update($backendUser);
184-
}
185-
// 2 reasons why we should update the display name: It does not match the one
186-
// - of our backend
187-
// - returned by the user manager (outdated one before the fix in https://github.com/nextcloud/user_oidc/pull/530)
188-
if ($newDisplayName !== $oldDisplayName || $newDisplayName !== $user->getDisplayName()) {
189-
$this->eventDispatcher->dispatchTyped(new UserChangedEvent($user, 'displayName', $newDisplayName, $oldDisplayName));
190-
}
191-
} else {
192-
$oldDisplayName = $user->getDisplayName();
193-
if ($newDisplayName !== $oldDisplayName) {
194-
$user->setDisplayName($newDisplayName);
195-
if ($user->getBackendClassName() === Application::APP_ID) {
196-
$backendUser = $this->userMapper->getOrCreate($providerId, $user->getUID());
197-
$backendUser->setDisplayName($newDisplayName);
198-
$this->userMapper->update($backendUser);
199-
}
200-
$this->eventDispatcher->dispatchTyped(new UserChangedEvent($user, 'displayName', $newDisplayName, $oldDisplayName));
201-
}
178+
$oldDisplayName = $user->getDisplayName();
179+
if ($newDisplayName !== $oldDisplayName) {
180+
$user->setDisplayName($newDisplayName);
181+
$this->eventDispatcher->dispatchTyped(new UserChangedEvent($user, 'displayName', $newDisplayName, $oldDisplayName));
202182
}
203183
}
204184

lib/User/Backend.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
use OCP\User\Backend\ICustomLogout;
3838
use OCP\User\Backend\IGetDisplayNameBackend;
3939
use OCP\User\Backend\IPasswordConfirmationBackend;
40+
use OCP\User\Backend\ISetDisplayNameBackend;
4041
use Psr\Log\LoggerInterface;
4142

42-
class Backend extends ABackend implements IPasswordConfirmationBackend, IGetDisplayNameBackend, IApacheBackend, ICustomLogout, ICountUsersBackend {
43+
class Backend extends ABackend implements IPasswordConfirmationBackend, IGetDisplayNameBackend, ISetDisplayNameBackend, IApacheBackend, ICustomLogout, ICountUsersBackend {
4344
private $tokenValidators = [
4445
SelfEncodedValidator::class,
4546
UserInfoValidator::class,
@@ -91,6 +92,17 @@ public function userExists($uid): bool {
9192
return $this->userMapper->userExists($uid);
9293
}
9394

95+
public function setDisplayName(string $uid, string $displayName): bool {
96+
try {
97+
$user = $this->userMapper->getUser($uid);
98+
$user->setDisplayName($displayName);
99+
$this->userMapper->update($user);
100+
return true;
101+
} catch (DoesNotExistException $e) {
102+
return false;
103+
}
104+
}
105+
94106
public function getDisplayName($uid): string {
95107
try {
96108
$user = $this->userMapper->getUser($uid);

0 commit comments

Comments
 (0)