Skip to content

Commit 42121fe

Browse files
authored
Merge pull request #12335 from nextcloud/fix/12319/respect-fixed-usernames
do not offer to change display name or password, if not possible.
2 parents 13d7a27 + 505722c commit 42121fe

9 files changed

Lines changed: 70 additions & 15 deletions

File tree

apps/provisioning_api/lib/Controller/AUserData.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace OCA\Provisioning_API\Controller;
2323

2424
use OC\Accounts\AccountManager;
25+
use OC\User\Backend;
2526
use OCP\AppFramework\OCS\OCSException;
2627
use OCP\AppFramework\OCS\OCSNotFoundException;
2728
use OCP\AppFramework\OCSController;
@@ -32,6 +33,8 @@
3233
use OCP\IRequest;
3334
use OCP\IUserManager;
3435
use OCP\IUserSession;
36+
use OCP\User\Backend\ISetDisplayNameBackend;
37+
use OCP\User\Backend\ISetPasswordBackend;
3538

3639
abstract class AUserData extends OCSController {
3740

@@ -125,6 +128,12 @@ protected function getUserData(string $userId): array {
125128
$data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang');
126129
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
127130

131+
$backend = $targetUserObject->getBackend();
132+
$data['backendCapabilities'] = [
133+
'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
134+
'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
135+
];
136+
128137
return $data;
129138
}
130139

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,22 @@
3838
use OCA\FederatedFileSharing\FederatedShareProvider;
3939
use OCA\Provisioning_API\FederatedFileSharingFactory;
4040
use OCP\App\IAppManager;
41-
use OCP\AppFramework\OCS\OCSException;
4241
use OCP\Mail\IEMailTemplate;
4342
use OC\Settings\Mailer\NewUserMailHelper;
4443
use OC\SubAdmin;
4544
use OCA\Provisioning_API\Controller\UsersController;
4645
use OCP\AppFramework\Http\DataResponse;
47-
use OCP\Defaults;
4846
use OCP\IConfig;
4947
use OCP\IGroup;
5048
use OCP\ILogger;
5149
use OCP\IL10N;
5250
use OCP\IRequest;
53-
use OCP\IURLGenerator;
5451
use OCP\IUser;
5552
use OCP\IUserManager;
5653
use OCP\IUserSession;
5754
use OCP\L10N\IFactory;
58-
use OCP\Mail\IMailer;
5955
use OCP\Security\ISecureRandom;
56+
use OCP\UserInterface;
6057
use PHPUnit_Framework_MockObject_MockObject;
6158
use Test\TestCase;
6259

@@ -800,6 +797,12 @@ public function testGetUserDataAsAdmin() {
800797
->method('fillStorageInfo')
801798
->with('UID')
802799
->will($this->returnValue(['DummyValue']));
800+
801+
$backend = $this->createMock(UserInterface::class);
802+
$backend->expects($this->any())
803+
->method('implementsActions')
804+
->willReturn(true);
805+
803806
$targetUser
804807
->expects($this->once())
805808
->method('getDisplayName')
@@ -816,6 +819,10 @@ public function testGetUserDataAsAdmin() {
816819
->expects($this->once())
817820
->method('getBackendClassName')
818821
->will($this->returnValue('Database'));
822+
$targetUser
823+
->expects($this->once())
824+
->method('getBackend')
825+
->willReturn($backend);
819826
$targetUser
820827
->expects($this->exactly(6))
821828
->method('getUID')
@@ -838,6 +845,10 @@ public function testGetUserDataAsAdmin() {
838845
'groups' => ['group0', 'group1', 'group2'],
839846
'language' => 'de',
840847
'locale' => null,
848+
'backendCapabilities' => [
849+
'setDisplayName' => true,
850+
'setPassword' => true,
851+
]
841852
];
842853
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
843854
}
@@ -906,6 +917,12 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
906917
->method('fillStorageInfo')
907918
->with('UID')
908919
->will($this->returnValue(['DummyValue']));
920+
921+
$backend = $this->createMock(UserInterface::class);
922+
$backend->expects($this->any())
923+
->method('implementsActions')
924+
->willReturn(true);
925+
909926
$targetUser
910927
->expects($this->once())
911928
->method('getDisplayName')
@@ -922,6 +939,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
922939
->expects($this->once())
923940
->method('getBackendClassName')
924941
->will($this->returnValue('Database'));
942+
$targetUser
943+
->expects($this->once())
944+
->method('getBackend')
945+
->willReturn($backend);
925946
$targetUser
926947
->expects($this->exactly(6))
927948
->method('getUID')
@@ -954,6 +975,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
954975
'groups' => [],
955976
'language' => 'da',
956977
'locale' => null,
978+
'backendCapabilities' => [
979+
'setDisplayName' => true,
980+
'setPassword' => true,
981+
]
957982
];
958983
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
959984
}
@@ -1054,6 +1079,12 @@ public function testGetUserDataAsSubAdminSelfLookup() {
10541079
->method('fillStorageInfo')
10551080
->with('UID')
10561081
->will($this->returnValue(['DummyValue']));
1082+
1083+
$backend = $this->createMock(UserInterface::class);
1084+
$backend->expects($this->atLeastOnce())
1085+
->method('implementsActions')
1086+
->willReturn(false);
1087+
10571088
$targetUser
10581089
->expects($this->once())
10591090
->method('getDisplayName')
@@ -1078,6 +1109,10 @@ public function testGetUserDataAsSubAdminSelfLookup() {
10781109
->expects($this->once())
10791110
->method('getBackendClassName')
10801111
->will($this->returnValue('Database'));
1112+
$targetUser
1113+
->expects($this->once())
1114+
->method('getBackend')
1115+
->willReturn($backend);
10811116
$this->config
10821117
->expects($this->at(0))
10831118
->method('getUserValue')
@@ -1110,6 +1145,10 @@ public function testGetUserDataAsSubAdminSelfLookup() {
11101145
'groups' => [],
11111146
'language' => 'ru',
11121147
'locale' => null,
1148+
'backendCapabilities' => [
1149+
'setDisplayName' => false,
1150+
'setPassword' => false,
1151+
]
11131152
];
11141153
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
11151154
}

lib/public/IUser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
namespace OCP;
2828

29+
use OCP\UserInterface;
30+
2931
/**
3032
* Interface IUser
3133
*
@@ -111,6 +113,7 @@ public function getBackendClassName();
111113
/**
112114
* Get the backend for the current user object
113115
*
116+
* @return UserInterface
114117
* @since 15.0.0
115118
*/
116119
public function getBackend();

settings/js/4.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/5.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/5.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/settings-admin-security.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/settings-vue.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/src/components/userList/userRow.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@
4242
<!-- dirty hack to ellipsis on two lines -->
4343
<div class="name">{{user.id}}</div>
4444
<form class="displayName" :class="{'icon-loading-small': loading.displayName}" v-on:submit.prevent="updateDisplayName">
45-
<input :id="'displayName'+user.id+rand" type="text"
46-
:disabled="loading.displayName||loading.all"
47-
:value="user.displayname" ref="displayName"
48-
autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" />
49-
<input type="submit" class="icon-confirm" value="" />
45+
<template v-if="user.backendCapabilities.setDisplayName">
46+
<input v-if="user.backendCapabilities.setDisplayName"
47+
:id="'displayName'+user.id+rand" type="text"
48+
:disabled="loading.displayName||loading.all"
49+
:value="user.displayname" ref="displayName"
50+
autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" />
51+
<input v-if="user.backendCapabilities.setDisplayName" type="submit" class="icon-confirm" value="" />
52+
</template>
53+
<div v-else class="name" v-tooltip.auto="t('settings', 'The backend does not support changing the display name')">{{user.displayname}}</div>
5054
</form>
51-
<form class="password" v-if="settings.canChangePassword" :class="{'icon-loading-small': loading.password}"
55+
<form class="password" v-if="settings.canChangePassword && user.backendCapabilities.setPassword" :class="{'icon-loading-small': loading.password}"
5256
v-on:submit.prevent="updatePassword">
5357
<input :id="'password'+user.id+rand" type="password" required
5458
:disabled="loading.password||loading.all" :minlength="minPasswordLength"

0 commit comments

Comments
 (0)