Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use InvalidArgumentException;
use OC\Authentication\Token\RemoteWipe;
use OC\Files\Filesystem;
use OC\Group\Group;
use OC\KnownUser\KnownUserService;
use OC\User\Backend;
Expand Down Expand Up @@ -551,6 +552,11 @@ public function addUser(
throw new OCSException($this->l10n->t('User creation failed'), 111);
}

if ($groups !== []) {
// Make sure we init the Filesystem for the user, in case we need to init some group shares.
Filesystem::init($newUser, '');
}

$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
foreach ($groups as $group) {
$this->groupManager->get($group)->addUser($newUser);
Expand Down
18 changes: 14 additions & 4 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\Security\ISecureRandom;
use OCP\UserInterface;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Test\TestCase;

#[Group(name: 'DB')]
class UsersControllerTest extends TestCase {
protected IUserManager&MockObject $userManager;
protected IConfig&MockObject $config;
Expand Down Expand Up @@ -805,13 +807,21 @@ public function testAddUserExistingGroup(): void {
->method('groupExists')
->with('ExistingGroup')
->willReturn(true);
$uid = 'NewUser';
$user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
$user
->method('getUID')
->willReturn($uid);
$user
->expects($this->once())
->method('getHome')
->willReturn($this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid);
$this->userManager
->expects($this->once())
->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser')
->with($uid, 'PasswordOfTheNewUser')
->willReturn($user);
$group = $this->getMockBuilder('OCP\IGroup')
->disableOriginalConstructor()
Expand All @@ -827,8 +837,8 @@ public function testAddUserExistingGroup(): void {
->willReturn($group);

$calls = [
['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']],
['Successful addUser call with userid: ' . $uid, ['app' => 'ocs_api']],
['Added userid ' . $uid . ' to group ExistingGroup', ['app' => 'ocs_api']],
];
$this->logger
->expects($this->exactly(2))
Expand All @@ -838,7 +848,7 @@ public function testAddUserExistingGroup(): void {
$this->assertEquals($expected, func_get_args());
});

$this->assertArrayHasKey('id', $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
$this->assertArrayHasKey('id', $this->api->addUser($uid, 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
}


Expand Down
Loading