Skip to content

Commit 18f48bb

Browse files
authored
[stable15] cache the displayname after an LDAP plugin set it (#16001)
[stable15] cache the displayname after an LDAP plugin set it
2 parents df6f8e4 + c765c3c commit 18f48bb

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

apps/user_ldap/lib/User_LDAP.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,9 @@ public function getDisplayName($uid) {
508508
*/
509509
public function setDisplayName($uid, $displayName) {
510510
if ($this->userPluginManager->implementsActions(Backend::SET_DISPLAYNAME)) {
511-
return $this->userPluginManager->setDisplayName($uid, $displayName);
511+
$this->userPluginManager->setDisplayName($uid, $displayName);
512+
$this->access->cacheUserDisplayName($uid, $displayName);
513+
return $displayName;
512514
}
513515
return false;
514516
}

apps/user_ldap/tests/User_LDAPTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,23 +1391,47 @@ public function testCanChangeAvatarWithPlugin() {
13911391
}
13921392

13931393
public function testSetDisplayNameWithPlugin() {
1394+
$newDisplayName = 'J. Baker';
13941395
$this->pluginManager->expects($this->once())
13951396
->method('implementsActions')
13961397
->with(Backend::SET_DISPLAYNAME)
13971398
->willReturn(true);
13981399
$this->pluginManager->expects($this->once())
13991400
->method('setDisplayName')
1400-
->with('uid','displayName')
1401-
->willReturn('result');
1401+
->with('uid', $newDisplayName)
1402+
->willReturn($newDisplayName);
1403+
$this->access->expects($this->once())
1404+
->method('cacheUserDisplayName');
1405+
1406+
$this->assertEquals($newDisplayName, $this->backend->setDisplayName('uid', $newDisplayName));
1407+
}
1408+
1409+
/**
1410+
* @expectedException \OC\HintException
1411+
*/
1412+
public function testSetDisplayNameErrorWithPlugin() {
1413+
$newDisplayName = 'J. Baker';
1414+
$this->pluginManager->expects($this->once())
1415+
->method('implementsActions')
1416+
->with(Backend::SET_DISPLAYNAME)
1417+
->willReturn(true);
1418+
$this->pluginManager->expects($this->once())
1419+
->method('setDisplayName')
1420+
->with('uid', $newDisplayName)
1421+
->willThrowException(new HintException('something happned'));
1422+
$this->access->expects($this->never())
1423+
->method('cacheUserDisplayName');
14021424

1403-
$this->assertEquals($this->backend->setDisplayName('uid', 'displayName'),'result');
1425+
$this->backend->setDisplayName('uid', $newDisplayName);
14041426
}
14051427

14061428
public function testSetDisplayNameFailing() {
14071429
$this->pluginManager->expects($this->once())
14081430
->method('implementsActions')
14091431
->with(Backend::SET_DISPLAYNAME)
14101432
->willReturn(false);
1433+
$this->access->expects($this->never())
1434+
->method('cacheUserDisplayName');
14111435

14121436
$this->assertFalse($this->backend->setDisplayName('uid', 'displayName'));
14131437
}

0 commit comments

Comments
 (0)