X Tutup
Skip to content

Commit 9d263e4

Browse files
author
Jan
authored
Merge pull request #39288 from /issues/35101-1
Decouple change email from 'allow_user_to_change_display_name' setting
2 parents e58db20 + 298f0f3 commit 9d263e4

File tree

19 files changed

+230
-19
lines changed

19 files changed

+230
-19
lines changed

changelog/unreleased/39288

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Bugfix: Decouple change email from 'allow_user_to_change_display_name' setting
2+
3+
Before this change, with setting 'allow_user_to_change_display_name' false,
4+
the user was not able to change the mail address in Settings->Personal->General
5+
via the webUI.
6+
7+
With this change, the setting 'allow_user_to_change_mail_address' has been
8+
introduced and change mail address has been decoupled from setting
9+
`allow_user_to_change_display_name`.
10+
11+
'allow_user_to_change_mail_address' must be set explicitly to false, to take effect.
12+
13+
https://github.com/owncloud/core/pull/39288
14+
https://github.com/owncloud/core/issues/35103

config/config.sample.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@
205205
*/
206206
'allow_user_to_change_display_name' => true,
207207

208+
/**
209+
* Allow or disallow users to change their email addresses
210+
* `true` allows users to change their email address (on their Personal pages),
211+
* `false` prevents them from changing their email address.
212+
*/
213+
'allow_user_to_change_mail_address' => true,
214+
208215
/**
209216
* Define the lifetime of the remember-login cookie
210217
* The remember-login cookie is set when the user clicks the `remember` checkbox
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
namespace OC\Migrations;
3+
4+
use OCP\Migration\ISimpleMigration;
5+
use OCP\Migration\IOutput;
6+
7+
/**
8+
* Set allow_user_to_change_mail_address equal to allow_user_to_change_display_name
9+
* so the behaviour does not change.
10+
*/
11+
class Version20210928123126 implements ISimpleMigration {
12+
13+
/**
14+
* @param IOutput $out
15+
*/
16+
public function run(IOutput $out) {
17+
$value = \OC::$server->getSystemConfig()->getValue('allow_user_to_change_display_name');
18+
if ($value !== null) {
19+
\OC::$server->getSystemConfig()->setValue('allow_user_to_change_mail_address', $value);
20+
}
21+
}
22+
}

lib/private/User/DeletedUser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function canChangeDisplayName() {
178178
return false;
179179
}
180180

181+
public function canChangeMailAddress() {
182+
return false;
183+
}
184+
181185
public function isEnabled() {
182186
return false;
183187
}

lib/private/User/RemoteUser.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ public function canChangeDisplayName() {
141141
return false;
142142
}
143143

144+
/**
145+
* @inheritdoc
146+
*/
147+
public function canChangeMailAddress() {
148+
return false;
149+
}
150+
144151
/**
145152
* @inheritdoc
146153
*/

lib/private/User/User.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,26 @@ public function canChangeDisplayName() {
410410
return $backend->implementsActions(Backend::SET_DISPLAYNAME);
411411
}
412412

413+
/**
414+
* check if the backend supports changing email addresses
415+
*
416+
* @return bool
417+
*/
418+
public function canChangeMailAddress() {
419+
if ($this->userSession instanceof IUserSession) {
420+
$user = $this->userSession->getUser();
421+
if (
422+
($this->config->getSystemValue('allow_user_to_change_mail_address') === false) &&
423+
(($user !== null) && (!$this->groupManager->isAdmin($user->getUID()))) &&
424+
(($user !== null) && (!$this->groupManager->getSubAdmin()->isSubAdmin($user)))
425+
) {
426+
return false;
427+
}
428+
}
429+
430+
return true;
431+
}
432+
413433
/**
414434
* check if the user is enabled
415435
*

lib/public/IUser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ public function canChangePassword();
161161
*/
162162
public function canChangeDisplayName();
163163

164+
/**
165+
* check if the backend supports changing email addresses
166+
*
167+
* @return bool
168+
* @since 10.9.0
169+
*/
170+
public function canChangeMailAddress();
171+
164172
/**
165173
* check if the user is enabled
166174
*

settings/Controller/UsersController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ public function setMailAddress($id, $mailAddress) {
929929

930930
// this is the only permission a backend provides and is also used
931931
// for the permission of setting a email address
932-
if (!$user->canChangeDisplayName()) {
932+
if (!$user->canChangeMailAddress()) {
933933
return new DataResponse(
934934
[
935935
'status' => 'error',
@@ -1062,7 +1062,7 @@ public function setDisplayName($username, $displayName) {
10621062
return new DataResponse([
10631063
'status' => 'error',
10641064
'data' => [
1065-
'message' => $this->l10n->t('Authentication error'),
1065+
'message' => $this->l10n->t('Unable to change display name'),
10661066
],
10671067
]);
10681068
}

settings/Panels/Personal/Profile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function getPanel() {
101101
$tmpl->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true) === true);
102102
$tmpl->assign('avatarChangeSupported', $this->userSession->getUser()->canChangeAvatar());
103103
$tmpl->assign('displayNameChangeSupported', $this->userSession->getUser()->canChangeDisplayName());
104+
$tmpl->assign('mailAddressChangeSupported', $this->userSession->getUser()->canChangeMailAddress());
104105
$tmpl->assign('passwordChangeSupported', $this->userSession->getUser()->canChangePassword());
105106
$groups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
106107
\sort($groups);

settings/css/settings.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ input#webdav {
5050
#displaynameform,
5151
#groups,
5252
#language,
53-
#lostpassword,
53+
#emailform,
5454
#passwordform {
5555
display: inline-block;
5656
margin-bottom: 0;

0 commit comments

Comments
 (0)
X Tutup