From 6de294bb545d8dd9e3f14a2cee58b611d72c470d Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 5 Mar 2026 11:26:13 +0100 Subject: [PATCH] fix(provisioning_api): Init FS for new users for group shares they are going to be added to Signed-off-by: provokateurin --- .../lib/Controller/UsersController.php | 6 ++++++ .../tests/Controller/UsersControllerTest.php | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index ef88985fdafeb..9a3bc246a521d 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -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; @@ -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); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index c135360b8f19e..233468cadf114 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -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; @@ -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() @@ -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)) @@ -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()); }