Skip to content

Commit 411387d

Browse files
authored
Merge pull request #9242 from nextcloud/fix-display-name-ignored-when-creating-new-user
Fix display name ignored when creating new user
2 parents 3e0668e + f05d30c commit 411387d

File tree

8 files changed

+140
-13
lines changed

8 files changed

+140
-13
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function getUsersDetails(string $search = '', $limit = null, $offset = 0)
199199
*
200200
* @param string $userid
201201
* @param string $password
202+
* @param string $displayName
202203
* @param string $email
203204
* @param array $groups
204205
* @param array $subadmins
@@ -209,6 +210,7 @@ public function getUsersDetails(string $search = '', $limit = null, $offset = 0)
209210
*/
210211
public function addUser(string $userid,
211212
string $password = '',
213+
string $displayName = '',
212214
string $email = '',
213215
array $groups = [],
214216
array $subadmin = [],
@@ -282,6 +284,10 @@ public function addUser(string $userid,
282284
$subAdminManager->createSubAdmin($newUser, $group);
283285
}
284286

287+
if ($displayName !== '') {
288+
$this->editUser($userid, 'display', $displayName);
289+
}
290+
285291
if ($quota !== '') {
286292
$this->editUser($userid, 'quota', $quota);
287293
}

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function testAddUserAlreadyExisting() {
247247
->with('adminUser')
248248
->willReturn(true);
249249

250-
$this->api->addUser('AlreadyExistingUser', 'password', '', []);
250+
$this->api->addUser('AlreadyExistingUser', 'password', '', '', []);
251251
}
252252

253253
/**
@@ -283,7 +283,7 @@ public function testAddUserNonExistingGroup() {
283283
->with('NonExistingGroup')
284284
->willReturn(false);
285285

286-
$this->api->addUser('NewUser', 'pass', '', ['NonExistingGroup']);
286+
$this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']);
287287
}
288288

289289
/**
@@ -325,7 +325,7 @@ public function testAddUserExistingGroupNonExistingGroup() {
325325
['NonExistingGroup', false]
326326
]));
327327

328-
$this->api->addUser('NewUser', 'pass', '', ['ExistingGroup', 'NonExistingGroup']);
328+
$this->api->addUser('NewUser', 'pass', '', '', ['ExistingGroup', 'NonExistingGroup']);
329329
}
330330

331331
public function testAddUserSuccessful() {
@@ -362,6 +362,63 @@ public function testAddUserSuccessful() {
362362
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData());
363363
}
364364

365+
public function testAddUserSuccessfulWithDisplayName() {
366+
$api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController')
367+
->setConstructorArgs([
368+
'provisioning_api',
369+
$this->request,
370+
$this->userManager,
371+
$this->config,
372+
$this->appManager,
373+
$this->groupManager,
374+
$this->userSession,
375+
$this->accountManager,
376+
$this->logger,
377+
$this->l10nFactory,
378+
$this->newUserMailHelper,
379+
$this->federatedFileSharingFactory,
380+
$this->secureRandom
381+
])
382+
->setMethods(['editUser'])
383+
->getMock();
384+
385+
$this->userManager
386+
->expects($this->once())
387+
->method('userExists')
388+
->with('NewUser')
389+
->will($this->returnValue(false));
390+
$this->userManager
391+
->expects($this->once())
392+
->method('createUser')
393+
->with('NewUser', 'PasswordOfTheNewUser');
394+
$this->logger
395+
->expects($this->once())
396+
->method('info')
397+
->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
398+
$loggedInUser = $this->getMockBuilder(IUser::class)
399+
->disableOriginalConstructor()
400+
->getMock();
401+
$loggedInUser
402+
->expects($this->any())
403+
->method('getUID')
404+
->will($this->returnValue('adminUser'));
405+
$this->userSession
406+
->expects($this->any())
407+
->method('getUser')
408+
->will($this->returnValue($loggedInUser));
409+
$this->groupManager
410+
->expects($this->once())
411+
->method('isAdmin')
412+
->with('adminUser')
413+
->willReturn(true);
414+
$api
415+
->expects($this->once())
416+
->method('editUser')
417+
->with('NewUser', 'display', 'DisplayNameOfTheNewUser');
418+
419+
$this->assertEquals([], $api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData());
420+
}
421+
365422
public function testAddUserExistingGroup() {
366423
$this->userManager
367424
->expects($this->once())
@@ -417,7 +474,7 @@ public function testAddUserExistingGroup() {
417474
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
418475
);
419476

420-
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData());
477+
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
421478
}
422479

423480
/**
@@ -495,7 +552,7 @@ public function testAddUserAsSubAdminNoGroup() {
495552
->with()
496553
->willReturn($subAdminManager);
497554

498-
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', []);
555+
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []);
499556
}
500557

501558
/**
@@ -544,7 +601,7 @@ public function testAddUserAsSubAdminValidGroupNotSubAdmin() {
544601
->with('ExistingGroup')
545602
->willReturn(true);
546603

547-
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData();
604+
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData();
548605
}
549606

550607
public function testAddUserAsSubAdminExistingGroups() {
@@ -635,7 +692,7 @@ public function testAddUserAsSubAdminExistingGroups() {
635692
)
636693
->willReturn(true);
637694

638-
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
695+
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
639696
}
640697

641698
/**

settings/js/settings-vue.js

Lines changed: 2 additions & 2 deletions
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.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export default {
324324
this.$store.dispatch('addUser', {
325325
userid: this.newUser.id,
326326
password: this.newUser.password,
327+
displayName: this.newUser.displayName,
327328
email: this.newUser.mailAddress,
328329
groups: this.newUser.groups.map(group => group.id),
329330
subadmin: this.newUser.subAdminsGroups.map(group => group.id),

settings/src/store/users.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,17 @@ const actions = {
415415
* @param {Object} context
416416
* @param {Object} options
417417
* @param {string} options.userid User id
418-
* @param {string} options.password User password
418+
* @param {string} options.password User password
419+
* @param {string} options.displayName User display name
419420
* @param {string} options.email User email
420421
* @param {string} options.groups User groups
421422
* @param {string} options.subadmin User subadmin groups
422423
* @param {string} options.quota User email
423424
* @returns {Promise}
424425
*/
425-
addUser({commit, dispatch}, { userid, password, email, groups, subadmin, quota, language }) {
426+
addUser({commit, dispatch}, { userid, password, displayName, email, groups, subadmin, quota, language }) {
426427
return api.requireAdmin().then((response) => {
427-
return api.post(OC.linkToOCS(`cloud/users`, 2), { userid, password, email, groups, subadmin, quota, language })
428+
return api.post(OC.linkToOCS(`cloud/users`, 2), { userid, password, displayName, email, groups, subadmin, quota, language })
428429
.then((response) => dispatch('addUserData', userid))
429430
.catch((error) => {throw error;});
430431
}).catch((error) => commit('API_FAILURE', { userid, error }));

tests/acceptance/features/bootstrap/UsersSettingsContext.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public static function userNameFieldForNewUser() {
4444
describedAs("User name field for new user in Users Settings");
4545
}
4646

47+
/**
48+
* @return Locator
49+
*/
50+
public static function displayNameFieldForNewUser() {
51+
return Locator::forThe()->field("newdisplayname")->
52+
describedAs("Display name field for new user in Users Settings");
53+
}
54+
4755
/**
4856
* @return Locator
4957
*/
@@ -96,6 +104,13 @@ public static function inputForUserInCell($cell, $user) {
96104
describedAs("$cell input for user $user in Users Settings");
97105
}
98106

107+
/**
108+
* @return Locator
109+
*/
110+
public static function displayNameCellForUser($user) {
111+
return self::inputForUserInCell("displayName", $user);
112+
}
113+
99114
/**
100115
* @return Locator
101116
*/
@@ -161,6 +176,34 @@ public function iOpenTheActionsMenuOf($user) {
161176
$this->actor->find(self::actionsMenuOf($user))->click();
162177
}
163178

179+
/**
180+
* @When I set the user name for the new user to :user
181+
*/
182+
public function iSetTheUserNameForTheNewUserTo($user) {
183+
$this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user);
184+
}
185+
186+
/**
187+
* @When I set the display name for the new user to :displayName
188+
*/
189+
public function iSetTheDisplayNameForTheNewUserTo($displayName) {
190+
$this->actor->find(self::displayNameFieldForNewUser(), 10)->setValue($displayName);
191+
}
192+
193+
/**
194+
* @When I set the password for the new user to :password
195+
*/
196+
public function iSetThePasswordForTheNewUserTo($password) {
197+
$this->actor->find(self::passwordFieldForNewUser(), 10)->setValue($password);
198+
}
199+
200+
/**
201+
* @When I create the new user
202+
*/
203+
public function iCreateTheNewUser() {
204+
$this->actor->find(self::createNewUserButton(), 10)->click();
205+
}
206+
164207
/**
165208
* @When I create user :user with password :password
166209
*/
@@ -242,6 +285,13 @@ public function iSeeThatTheFieldOfUserIs($field, $user, $value) {
242285
$this->actor->find(self::inputForUserInCell($field, $user), 10)->getValue(), $value);
243286
}
244287

288+
/**
289+
* @Then I see that the display name for the user :user is :displayName
290+
*/
291+
public function iSeeThatTheDisplayNameForTheUserIs($user, $displayName) {
292+
PHPUnit_Framework_Assert::assertEquals($displayName, $this->actor->find(self::displayNameCellForUser($user), 10)->getValue());
293+
}
294+
245295
/**
246296
* @Then I see that the :cell cell for user :user is done loading
247297
*/

tests/acceptance/features/users.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ Feature: users
99
When I create user unknownUser with password 123456acb
1010
Then I see that the list of users contains the user unknownUser
1111

12+
Scenario: create a new user with a custom display name
13+
Given I am logged in as the admin
14+
And I open the User settings
15+
When I click the New user button
16+
And I see that the new user form is shown
17+
And I set the user name for the new user to "test"
18+
And I set the display name for the new user to "Test display name"
19+
And I set the password for the new user to "123456acb"
20+
And I create the new user
21+
Then I see that the list of users contains the user "test"
22+
And I see that the display name for the user "test" is "Test display name"
23+
1224
Scenario: delete a user
1325
Given I act as Jane
1426
And I am logged in as the admin

0 commit comments

Comments
 (0)