Skip to content

Commit

Permalink
[stable16] cache the displayname after an LDAP plugin set it (#16000)
Browse files Browse the repository at this point in the history
[stable16] cache the displayname after an LDAP plugin set it
  • Loading branch information
skjnldsv authored Jun 19, 2019
2 parents c08f383 + c95da45 commit dce4a24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ public function getDisplayName($uid) {
*/
public function setDisplayName($uid, $displayName) {
if ($this->userPluginManager->implementsActions(Backend::SET_DISPLAYNAME)) {
return $this->userPluginManager->setDisplayName($uid, $displayName);
$this->userPluginManager->setDisplayName($uid, $displayName);
$this->access->cacheUserDisplayName($uid, $displayName);
return $displayName;
}
return false;
}
Expand Down
30 changes: 27 additions & 3 deletions apps/user_ldap/tests/User_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1391,23 +1391,47 @@ public function testCanChangeAvatarWithPlugin() {
}

public function testSetDisplayNameWithPlugin() {
$newDisplayName = 'J. Baker';
$this->pluginManager->expects($this->once())
->method('implementsActions')
->with(Backend::SET_DISPLAYNAME)
->willReturn(true);
$this->pluginManager->expects($this->once())
->method('setDisplayName')
->with('uid','displayName')
->willReturn('result');
->with('uid', $newDisplayName)
->willReturn($newDisplayName);
$this->access->expects($this->once())
->method('cacheUserDisplayName');

$this->assertEquals($newDisplayName, $this->backend->setDisplayName('uid', $newDisplayName));
}

/**
* @expectedException \OC\HintException
*/
public function testSetDisplayNameErrorWithPlugin() {
$newDisplayName = 'J. Baker';
$this->pluginManager->expects($this->once())
->method('implementsActions')
->with(Backend::SET_DISPLAYNAME)
->willReturn(true);
$this->pluginManager->expects($this->once())
->method('setDisplayName')
->with('uid', $newDisplayName)
->willThrowException(new HintException('something happned'));
$this->access->expects($this->never())
->method('cacheUserDisplayName');

$this->assertEquals($this->backend->setDisplayName('uid', 'displayName'),'result');
$this->backend->setDisplayName('uid', $newDisplayName);
}

public function testSetDisplayNameFailing() {
$this->pluginManager->expects($this->once())
->method('implementsActions')
->with(Backend::SET_DISPLAYNAME)
->willReturn(false);
$this->access->expects($this->never())
->method('cacheUserDisplayName');

$this->assertFalse($this->backend->setDisplayName('uid', 'displayName'));
}
Expand Down

0 comments on commit dce4a24

Please sign in to comment.