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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
59 changes: 59 additions & 0 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]));
}
}
Loading