only write when the displayname differs, but then announce it
refs #5212 and fixes #9112 Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
6ad7f32938
commit
bbe44108b5
|
@ -414,14 +414,21 @@ class User {
|
||||||
*
|
*
|
||||||
* @param string $displayName
|
* @param string $displayName
|
||||||
* @param string $displayName2
|
* @param string $displayName2
|
||||||
* @returns string the effective display name
|
* @return string the effective display name
|
||||||
*/
|
*/
|
||||||
public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
|
public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
|
||||||
$displayName2 = (string)$displayName2;
|
$displayName2 = (string)$displayName2;
|
||||||
if($displayName2 !== '') {
|
if($displayName2 !== '') {
|
||||||
$displayName .= ' (' . $displayName2 . ')';
|
$displayName .= ' (' . $displayName2 . ')';
|
||||||
}
|
}
|
||||||
$this->store('displayName', $displayName);
|
$oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', '');
|
||||||
|
if ($oldName !== $displayName) {
|
||||||
|
$this->store('displayName', $displayName);
|
||||||
|
$user = $this->userManager->get($this->getUsername());
|
||||||
|
if ($user instanceof \OC\User\User) {
|
||||||
|
$user->triggerChange('displayName', $displayName);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $displayName;
|
return $displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1010,11 +1010,36 @@ class UserTest extends \Test\TestCase {
|
||||||
public function testComposeAndStoreDisplayName($part1, $part2, $expected) {
|
public function testComposeAndStoreDisplayName($part1, $part2, $expected) {
|
||||||
$this->config->expects($this->once())
|
$this->config->expects($this->once())
|
||||||
->method('setUserValue');
|
->method('setUserValue');
|
||||||
|
$this->config->expects($this->once())
|
||||||
|
->method('getUserValue');
|
||||||
|
|
||||||
|
$ncUserObj = $this->createMock(\OC\User\User::class);
|
||||||
|
$ncUserObj->expects($this->once())
|
||||||
|
->method('triggerChange')
|
||||||
|
->with('displayName', $expected);
|
||||||
|
$this->userManager->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->willReturn($ncUserObj);
|
||||||
|
|
||||||
$displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
|
$displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
|
||||||
$this->assertSame($expected, $displayName);
|
$this->assertSame($expected, $displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testComposeAndStoreDisplayNameNoOverwrite() {
|
||||||
|
$displayName = 'Randall Flagg';
|
||||||
|
$this->config->expects($this->never())
|
||||||
|
->method('setUserValue');
|
||||||
|
$this->config->expects($this->once())
|
||||||
|
->method('getUserValue')
|
||||||
|
->willReturn($displayName);
|
||||||
|
|
||||||
|
$this->userManager->expects($this->never())
|
||||||
|
->method('get'); // Implicit: no triggerChange can be called
|
||||||
|
|
||||||
|
$composedDisplayName = $this->user->composeAndStoreDisplayName($displayName);
|
||||||
|
$this->assertSame($composedDisplayName, $displayName);
|
||||||
|
}
|
||||||
|
|
||||||
public function testHandlePasswordExpiryWarningDefaultPolicy() {
|
public function testHandlePasswordExpiryWarningDefaultPolicy() {
|
||||||
$this->connection->expects($this->any())
|
$this->connection->expects($this->any())
|
||||||
->method('__get')
|
->method('__get')
|
||||||
|
|
Loading…
Reference in New Issue