Skip to content
Merged
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
3 changes: 1 addition & 2 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use OC\Share20\ShareDisableChecker;
use OC_App;
use OC_Hook;
use OC_Util;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\Files_Sharing\External\Mount;
use OCA\Files_Sharing\ISharedMountPoint;
Expand Down Expand Up @@ -157,7 +156,7 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
if ($mount instanceof HomeMountPoint) {
$user = $mount->getUser();
return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
return OC_Util::getUserQuota($user);
return $user->getQuotaBytes();
}, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/private/User/LazyUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public function getQuota() {
return $this->getUser()->getQuota();
}

public function getQuotaBytes(): int|float {
return $this->getUser()->getQuotaBytes();
}

public function setQuota($quota) {
$this->getUser()->setQuota($quota);
}
Expand Down
13 changes: 13 additions & 0 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,19 @@ public function getQuota() {
return $quota;
}

public function getQuotaBytes(): int|float {
$quota = $this->getQuota();
if ($quota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
}

$bytes = \OCP\Util::computerFileSize($quota);
if ($bytes === false) {
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
}
return $bytes;
}

/**
* set the users' quota
*
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
} else {
$user = \OC::$server->getUserSession()->getUser();
}
$quota = OC_Util::getUserQuota($user);
$quota = $user?->getQuotaBytes() ?? \OCP\Files\FileInfo::SPACE_UNKNOWN;
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
// always get free space / total space from root + mount points
return self::getGlobalStorageInfo($quota, $user, $mount);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function isDefaultExpireDateEnforced() {
*
* @param IUser|null $user
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false|float Quota bytes
* @deprecated 9.0.0 - Use \OCP\IUser::getQuota
* @deprecated 9.0.0 - Use \OCP\IUser::getQuota or \OCP\IUser::getQuotaBytes
*/
public static function getUserQuota(?IUser $user) {
if (is_null($user)) {
Expand Down
9 changes: 9 additions & 0 deletions lib/public/IUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ public function setPrimaryEMailAddress(string $mailAddress): void;
*/
public function getQuota();

/**
* Get the users' quota in machine readable form. If a specific quota is set
* for the user, then the quota is returned in bytes. Otherwise the default value is returned.
* If a default setting was not set, it is return as `\OCP\Files\FileInfo::SPACE_UNLIMITED`, i.e. quota is not limited.
*
* @since 32.0.0
*/
public function getQuotaBytes(): int|float;

/**
* set the users' quota
*
Expand Down
9 changes: 5 additions & 4 deletions tests/lib/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OC\User\User;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -834,8 +835,8 @@ public function testGetDefaultUnlimitedQuota(): void {
$config->method('getAppValue')
->will($this->returnValueMap($appValueMap));

$quota = $user->getQuota();
$this->assertEquals('none', $quota);
$this->assertEquals('none', $user->getQuota());
$this->assertEquals(FileInfo::SPACE_UNLIMITED, $user->getQuotaBytes());
}

public function testGetDefaultUnlimitedQuotaForbidden(): void {
Expand Down Expand Up @@ -868,8 +869,8 @@ public function testGetDefaultUnlimitedQuotaForbidden(): void {
$config->method('getAppValue')
->will($this->returnValueMap($appValueMap));

$quota = $user->getQuota();
$this->assertEquals('1 GB', $quota);
$this->assertEquals('1 GB', $user->getQuota());
$this->assertEquals(1024 * 1024 * 1024, $user->getQuotaBytes());
Comment on lines +872 to +873
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that’s 1 GiB, not 1 GB 🙀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike that we have this 🙈

}

public function testSetQuotaAddressNoChange(): void {
Expand Down
Loading