-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
lib/private/User: always pass old value to 'triggerChange' in User class, do not change user properties if value has not changed #14566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8cd34d1
edef164
569e280
fe9f121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,16 +138,16 @@ public function getDisplayName() { | |
| */ | ||
| public function setDisplayName($displayName) { | ||
| $displayName = trim($displayName); | ||
| if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { | ||
| $oldDisplayName = $this->getDisplayName(); | ||
| if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName) && $displayName !== $oldDisplayName) { | ||
| $result = $this->backend->setDisplayName($this->uid, $displayName); | ||
| if ($result) { | ||
| $this->displayName = $displayName; | ||
| $this->triggerChange('displayName', $displayName); | ||
| $this->triggerChange('displayName', $displayName, $oldDisplayName); | ||
| } | ||
| return $result !== false; | ||
| } else { | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -159,12 +159,12 @@ public function setDisplayName($displayName) { | |
| */ | ||
| 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 +365,8 @@ public function setEnabled(bool $enabled = true) { | |
| $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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with moving it one line to the bottom to be after the change was made. 👍 Could you make this change?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this will change behavior: Everyone currently rejecting an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was never meant for this and doing this is also not the way to handle such stuff. It's highly recommended to not manipulate data via this mechanism. This is also documented and communicated like this. Also I couldn't find any code that does it like that. Do you know any app that does this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also those events are pure one way only events.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, where?
Our (Struktur-proprietary) app needs to reject modifications to a user under certain conditions, throwing an exception from a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought it was - but https://docs.nextcloud.com/server/stable/developer_manual/app/hooks.html doesn't has it. Maybe it was only on Github and never made it into the docs 😢.
If at all then there needs to be a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, see #14565. |
||
| $this->triggerChange('enabled', $enabled, $oldStatus); | ||
| $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false'); | ||
| } | ||
| } | ||
|
|
@@ -407,9 +408,9 @@ public function setQuota($quota) { | |
| $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); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,14 +676,8 @@ public function testSetEMailAddressNoChange() { | |
| $config->expects($this->any()) | ||
| ->method('getUserValue') | ||
| ->willReturn('[email protected]'); | ||
| $config->expects($this->once()) | ||
| ->method('setUserValue') | ||
| ->with( | ||
| 'foo', | ||
| 'settings', | ||
| 'email', | ||
| '[email protected]' | ||
| ); | ||
| $config->expects($this->never()) | ||
| ->method('setUserValue'); | ||
|
|
||
| $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); | ||
| $user->setEMailAddress('[email protected]'); | ||
|
|
@@ -741,14 +735,8 @@ public function testSetQuotaAddressNoChange() { | |
| $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'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the other places where this hook is triggered:
lib/private/User/User.php(remove or adapt?)Also there is
apps/user_ldap/lib/User/User.phpbecause it is not called externally, but when changes in LDAP were discovered. This cannot be removed, should be adopted. It should not intervene with User:setDisplayName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.