Add optional "displayName" parameter to add user endpoint

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-04-19 00:12:06 +02:00
parent c39bc1638b
commit 36326e38a0
2 changed files with 70 additions and 7 deletions

View File

@ -199,6 +199,7 @@ class UsersController extends AUserData {
* *
* @param string $userid * @param string $userid
* @param string $password * @param string $password
* @param string $displayName
* @param string $email * @param string $email
* @param array $groups * @param array $groups
* @param array $subadmins * @param array $subadmins
@ -209,6 +210,7 @@ class UsersController extends AUserData {
*/ */
public function addUser(string $userid, public function addUser(string $userid,
string $password = '', string $password = '',
string $displayName = '',
string $email = '', string $email = '',
array $groups = [], array $groups = [],
array $subadmin = [], array $subadmin = [],
@ -282,6 +284,10 @@ class UsersController extends AUserData {
$subAdminManager->createSubAdmin($newUser, $group); $subAdminManager->createSubAdmin($newUser, $group);
} }
if ($displayName !== '') {
$this->editUser($userid, 'display', $displayName);
}
if ($quota !== '') { if ($quota !== '') {
$this->editUser($userid, 'quota', $quota); $this->editUser($userid, 'quota', $quota);
} }

View File

@ -247,7 +247,7 @@ class UsersControllerTest extends TestCase {
->with('adminUser') ->with('adminUser')
->willReturn(true); ->willReturn(true);
$this->api->addUser('AlreadyExistingUser', 'password', '', []); $this->api->addUser('AlreadyExistingUser', 'password', '', '', []);
} }
/** /**
@ -283,7 +283,7 @@ class UsersControllerTest extends TestCase {
->with('NonExistingGroup') ->with('NonExistingGroup')
->willReturn(false); ->willReturn(false);
$this->api->addUser('NewUser', 'pass', '', ['NonExistingGroup']); $this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']);
} }
/** /**
@ -325,7 +325,7 @@ class UsersControllerTest extends TestCase {
['NonExistingGroup', false] ['NonExistingGroup', false]
])); ]));
$this->api->addUser('NewUser', 'pass', '', ['ExistingGroup', 'NonExistingGroup']); $this->api->addUser('NewUser', 'pass', '', '', ['ExistingGroup', 'NonExistingGroup']);
} }
public function testAddUserSuccessful() { public function testAddUserSuccessful() {
@ -362,6 +362,63 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()); $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() { public function testAddUserExistingGroup() {
$this->userManager $this->userManager
->expects($this->once()) ->expects($this->once())
@ -417,7 +474,7 @@ class UsersControllerTest extends TestCase {
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']] ['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() ->with()
->willReturn($subAdminManager); ->willReturn($subAdminManager);
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', []); $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []);
} }
/** /**
@ -544,7 +601,7 @@ class UsersControllerTest extends TestCase {
->with('ExistingGroup') ->with('ExistingGroup')
->willReturn(true); ->willReturn(true);
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData(); $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData();
} }
public function testAddUserAsSubAdminExistingGroups() { public function testAddUserAsSubAdminExistingGroups() {
@ -635,7 +692,7 @@ class UsersControllerTest extends TestCase {
) )
->willReturn(true); ->willReturn(true);
$this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()); $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
} }
/** /**