Преглед на файлове

Merge pull request #15052 from nextcloud/fix/noid/pass-oldvalue

Pass old value to user triggerChange hook & do not update unchanged attributes
tags/v16.0.0RC1
Morris Jobke преди 5 години
родител
ревизия
757a841d14
No account linked to committer's email address
променени са 3 файла, в които са добавени 15 реда и са изтрити 27 реда
  1. 1
    1
      apps/user_ldap/lib/User/User.php
  2. 10
    10
      lib/private/User/User.php
  3. 4
    16
      tests/lib/User/UserTest.php

+ 1
- 1
apps/user_ldap/lib/User/User.php Целия файл

@@ -436,7 +436,7 @@ class User {
if (!empty($oldName) && $user instanceof \OC\User\User) {
// if it was empty, it would be a new record, not a change emitting the trigger could
// potentially cause a UniqueConstraintViolationException, depending on some factors.
$user->triggerChange('displayName', $displayName);
$user->triggerChange('displayName', $displayName, $oldName);
}
}
return $displayName;

+ 10
- 10
lib/private/User/User.php Целия файл

@@ -145,9 +145,8 @@ class User implements IUser {
$this->triggerChange('displayName', $displayName);
}
return $result !== false;
} else {
return false;
}
return false;
}

/**
@@ -159,12 +158,12 @@ class User implements IUser {
*/
public function setEMailAddress($mailAddress) {
$oldMailAddress = $this->getEMailAddress();
if($mailAddress === '') {
$this->config->deleteUserValue($this->uid, 'settings', 'email');
} else {
$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
}
if($oldMailAddress !== $mailAddress) {
if($mailAddress === '') {
$this->config->deleteUserValue($this->uid, 'settings', 'email');
} else {
$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
}
$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
}
}
@@ -365,7 +364,8 @@ class User implements IUser {
$oldStatus = $this->isEnabled();
$this->enabled = $enabled;
if ($oldStatus !== $this->enabled) {
$this->triggerChange('enabled', $enabled);
// TODO: First change the value, then trigger the event as done for all other properties.
$this->triggerChange('enabled', $enabled, $oldStatus);
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
}
}
@@ -407,9 +407,9 @@ class User implements IUser {
$quota = OC_Helper::computerFileSize($quota);
$quota = OC_Helper::humanFileSize($quota);
}
$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
if($quota !== $oldQuota) {
$this->triggerChange('quota', $quota);
$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
$this->triggerChange('quota', $quota, $oldQuota);
}
}


+ 4
- 16
tests/lib/User/UserTest.php Целия файл

@@ -676,14 +676,8 @@ class UserTest extends TestCase {
$config->expects($this->any())
->method('getUserValue')
->willReturn('foo@bar.com');
$config->expects($this->once())
->method('setUserValue')
->with(
'foo',
'settings',
'email',
'foo@bar.com'
);
$config->expects($this->never())
->method('setUserValue');

$user = new User('foo', $backend, $this->dispatcher, $emitter, $config);
$user->setEMailAddress('foo@bar.com');
@@ -741,14 +735,8 @@ class UserTest extends TestCase {
$config->expects($this->any())
->method('getUserValue')
->willReturn('23 TB');
$config->expects($this->once())
->method('setUserValue')
->with(
'foo',
'files',
'quota',
'23 TB'
);
$config->expects($this->never())
->method('setUserValue');

$user = new User('foo', $backend, $this->dispatcher, $emitter, $config);
$user->setQuota('23 TB');

Loading…
Отказ
Запис