Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-04-19 01:12:06 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-07-31 14:33:55 +0300
commit36326e38a08a4269416b6defe460e2a65609ad9a (patch)
treea02d67c5a218b988b9220033b0c382bf0401061c /apps/provisioning_api
parentc39bc1638b812ef9660cfdb0ab6ca58d70ad68d8 (diff)
Add optional "displayName" parameter to add user endpoint
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php6
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php71
2 files changed, 70 insertions, 7 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 52021ec2486..d5e568b9184 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -199,6 +199,7 @@ class UsersController extends AUserData {
*
* @param string $userid
* @param string $password
+ * @param string $displayName
* @param string $email
* @param array $groups
* @param array $subadmins
@@ -209,6 +210,7 @@ class UsersController extends AUserData {
*/
public function addUser(string $userid,
string $password = '',
+ string $displayName = '',
string $email = '',
array $groups = [],
array $subadmin = [],
@@ -282,6 +284,10 @@ class UsersController extends AUserData {
$subAdminManager->createSubAdmin($newUser, $group);
}
+ if ($displayName !== '') {
+ $this->editUser($userid, 'display', $displayName);
+ }
+
if ($quota !== '') {
$this->editUser($userid, 'quota', $quota);
}
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index af4d5958b53..adbdb9d8685 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -247,7 +247,7 @@ class UsersControllerTest extends TestCase {
->with('adminUser')
->willReturn(true);
- $this->api->addUser('AlreadyExistingUser', 'password', '', []);
+ $this->api->addUser('AlreadyExistingUser', 'password', '', '', []);
}
/**
@@ -283,7 +283,7 @@ class UsersControllerTest extends TestCase {
->with('NonExistingGroup')
->willReturn(false);
- $this->api->addUser('NewUser', 'pass', '', ['NonExistingGroup']);
+ $this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']);
}
/**
@@ -325,7 +325,7 @@ class UsersControllerTest extends TestCase {
['NonExistingGroup', false]
]));
- $this->api->addUser('NewUser', 'pass', '', ['ExistingGroup', 'NonExistingGroup']);
+ $this->api->addUser('NewUser', 'pass', '', '', ['ExistingGroup', 'NonExistingGroup']);
}
public function testAddUserSuccessful() {
@@ -362,6 +362,63 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData());
}
+ public function testAddUserSuccessfulWithDisplayName() {
+ $api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController')
+ ->setConstructorArgs([
+ 'provisioning_api',
+ $this->request,
+ $this->userManager,
+ $this->config,
+ $this->appManager,
+ $this->groupManager,
+ $this->userSession,
+ $this->accountManager,
+ $this->logger,
+ $this->l10nFactory,
+ $this->newUserMailHelper,
+ $this->federatedFileSharingFactory,
+ $this->secureRandom
+ ])
+ ->setMethods(['editUser'])
+ ->getMock();
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('userExists')
+ ->with('NewUser')
+ ->will($this->returnValue(false));
+ $this->userManager
+ ->expects($this->once())
+ ->method('createUser')
+ ->with('NewUser', 'PasswordOfTheNewUser');
+ $this->logger
+ ->expects($this->once())
+ ->method('info')
+ ->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('adminUser'));
+ $this->userSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($loggedInUser));
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+ $api
+ ->expects($this->once())
+ ->method('editUser')
+ ->with('NewUser', 'display', 'DisplayNameOfTheNewUser');
+
+ $this->assertEquals([], $api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData());
+ }
+
public function testAddUserExistingGroup() {
$this->userManager
->expects($this->once())
@@ -417,7 +474,7 @@ class UsersControllerTest extends TestCase {
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
);
- $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData());
+ $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
}
/**
@@ -495,7 +552,7 @@ class UsersControllerTest extends TestCase {
->with()
->willReturn($subAdminManager);
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', []);
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []);
}
/**
@@ -544,7 +601,7 @@ class UsersControllerTest extends TestCase {
->with('ExistingGroup')
->willReturn(true);
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData();
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData();
}
public function testAddUserAsSubAdminExistingGroups() {
@@ -635,7 +692,7 @@ class UsersControllerTest extends TestCase {
)
->willReturn(true);
- $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
+ $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
}
/**