From cfba2afd9b7ed2344c6b27a548ae070fd93198c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alfonso=20Pym=20Mej=C3=ADa?= Date: Wed, 28 Oct 2026 16:28:04 -0600 Subject: [PATCH] fix(provisioning_api): only count user files in quota usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Mario Alfonso Pym Mejía --- .../lib/Controller/AUserDataOCSController.php | 5 +- .../tests/Controller/UsersControllerTest.php | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php index abfc238314216..c35a2725afa52 100644 --- a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php +++ b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php @@ -346,7 +346,10 @@ protected function fillStorageInfo(IUser $user): array { self::USER_FIELD_QUOTA => $storage['quota'], ]; } else { - $userFileInfo = $this->rootFolder->getUserFolder($userId)->getStorage()->getCache()->get(''); + // Only files/ counts against the quota. On object store the home root + // also holds files_trashbin, files_versions and uploads. + $userFolder = $this->rootFolder->getUserFolder($userId); + $userFileInfo = $userFolder->getStorage()->getCache()->get($userFolder->getInternalPath()); $used = $userFileInfo->getSize(); if ($quota > 0) { diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 89884448c3577..f28c8b2f6f1cf 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -28,7 +28,11 @@ use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCSController; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; +use OCP\Files\Storage\IStorage; use OCP\Group\ISubAdmin; use OCP\IAppConfig; use OCP\IConfig; @@ -5371,4 +5375,59 @@ private function mockAccount($targetUser, $accountProperties) { ->with($targetUser) ->willReturn($account); } + + public function testFillStorageInfoCountsOnlyUserFiles(): void { + $user = $this->createMock(IUser::class); + $user->method('getUID')->willReturn('alice'); + $user->method('getQuota')->willReturn('10 MB'); + + $rootEntry = $this->createMock(ICacheEntry::class); + $rootEntry->method('getSize')->willReturn(10485760); + $filesEntry = $this->createMock(ICacheEntry::class); + $filesEntry->method('getSize')->willReturn(3145728); + // On object store the home root also includes trashbin, versions and uploads + $cache = $this->createMock(ICache::class); + $cache->method('get')->willReturnMap([ + ['', $rootEntry], + ['files', $filesEntry], + ]); + $storage = $this->createMock(IStorage::class); + $storage->method('getCache')->willReturn($cache); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getStorage')->willReturn($storage); + $userFolder->method('getInternalPath')->willReturn('files'); + $this->rootFolder->method('getUserFolder')->with('alice')->willReturn($userFolder); + + $api = new UsersController( + 'provisioning_api', + $this->request, + $this->userManager, + $this->config, + $this->groupManager, + $this->userSession, + $this->accountManager, + $this->subAdminManager, + $this->l10nFactory, + $this->rootFolder, + $this->urlGenerator, + $this->logger, + $this->newUserMailHelper, + $this->secureRandom, + $this->remoteWipe, + $this->knownUserService, + $this->eventDispatcher, + $this->phoneNumberUtil, + $this->appManager, + $this->appConfig, + $this->groupDisplayNameCache, + ); + + $this->assertSame([ + 'free' => 7340032, + 'used' => 3145728, + 'total' => 10485760, + 'relative' => 30.0, + 'quota' => 10485760, + ], self::invokePrivate($api, 'fillStorageInfo', [$user])); + } }