Skip to content

Commit

Permalink
Merge pull request #886 from nextcloud/fix/log-attribute-update
Browse files Browse the repository at this point in the history
fix: Log attribute updates
  • Loading branch information
blizzz authored Oct 8, 2024
2 parents a8139e3 + f0f870d commit e08e742
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
33 changes: 31 additions & 2 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,23 +564,52 @@ public function updateAttributes(string $uid, array $attributes): void {
}

if ($user !== null) {
$currentEmail = (string)(method_exists($user, 'getSystemEMailAddress') ? $user->getSystemEMailAddress() : $user->getEMailAddress());
$this->logger->debug('Updating attributes for existing user', ['app' => 'user_saml', 'user' => $user->getUID()]);
$currentEmail = (string)$user->getSystemEMailAddress();
if ($newEmail !== null
&& $currentEmail !== $newEmail) {
$user->setEMailAddress($newEmail);
$user->setSystemEMailAddress($newEmail);
$this->logger->debug('Email address updated', ['app' => 'user_saml', 'user' => $user->getUID()]);
} else {
$this->logger->debug('Email address not updated', [
'app' => 'user_saml',
'user' => $user->getUID(),
'currentEmail' => $currentEmail,
'newEmail' => $newEmail,
]);
}
$currentDisplayname = $this->getDisplayName($uid);
if ($newDisplayname !== null
&& $currentDisplayname !== $newDisplayname) {
$this->setDisplayName($uid, $newDisplayname);
$this->logger->debug('Display name updated', ['app' => 'user_saml', 'user' => $user->getUID()]);
$this->eventDispatcher->dispatchTyped(new UserChangedEvent($user, 'displayName', $newDisplayname, $currentDisplayname));
$this->logger->debug('Display name update event dispatched', ['app' => 'user_saml', 'user' => $user->getUID()]);
} else {
$this->logger->debug('Display name not updated', [
'app' => 'user_saml',
'user' => $user->getUID(),
'newDisplayname' => $newDisplayname,
'currentDisplayname' => $currentDisplayname,
]);
}

if ($newQuota !== null) {
$user->setQuota($newQuota);
$this->logger->debug('Quota updated', ['app' => 'user_saml', 'user' => $user->getUID()]);
} else {
$this->logger->debug('Quota not updated', [
'app' => 'user_saml',
'user' => $user->getUID(),
]);
}

$this->groupManager->handleIncomingGroups($user, $newGroups ?? []);
$this->logger->debug('Incoming groups updated', [
'app' => 'user_saml',
'user' => $user->getUID(),
'groups' => $newGroups,
]);
}
}

Expand Down
51 changes: 15 additions & 36 deletions tests/unit/UserBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,13 @@ public function testUpdateAttributesWithoutAttributes() {
->method('get')
->with('ExistingUser')
->willReturn($user);
if (method_exists($user, 'getSystemEMailAddress')) {
$user
->expects($this->once())
->method('getSystemEMailAddress')
->willReturn(null);
} else {
$user
->expects($this->once())
->method('getEMailAddress')
->willReturn(null);
}
$user
->expects($this->once())
->method('getSystemEMailAddress')
->willReturn(null);
$user
->expects($this->never())
->method('setEMailAddress');
->method('setSystemEMailAddress');
$this->userBackend
->expects($this->once())
->method('getDisplayName')
Expand Down Expand Up @@ -187,20 +180,13 @@ public function testUpdateAttributes() {
->method('get')
->with('ExistingUser')
->willReturn($user);
if (method_exists($user, 'getSystemEMailAddress')) {
$user
->expects($this->once())
->method('getSystemEMailAddress')
->willReturn('[email protected]');
} else {
$user
->expects($this->once())
->method('getEMailAddress')
->willReturn('[email protected]');
}
$user
->expects($this->once())
->method('setEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$user
->expects($this->once())
->method('setSystemEMailAddress')
->with('[email protected]');
$user
->expects($this->once())
Expand Down Expand Up @@ -251,20 +237,13 @@ public function testUpdateAttributesQuotaDefaultFallback() {
->method('get')
->with('ExistingUser')
->willReturn($user);
if (method_exists($user, 'getSystemEMailAddress')) {
$user
->expects($this->once())
->method('getSystemEMailAddress')
->willReturn('[email protected]');
} else {
$user
->expects($this->once())
->method('getEMailAddress')
->willReturn('[email protected]');
}
$user
->expects($this->once())
->method('setEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$user
->expects($this->once())
->method('setSystemEMailAddress')
->with('[email protected]');
$user
->expects($this->once())
Expand Down

0 comments on commit e08e742

Please sign in to comment.