Skip to content

Commit

Permalink
feat(quota): provide storage info to PageController
Browse files Browse the repository at this point in the history
Signed-off-by: Franziska Bath <[email protected]>
  • Loading branch information
fracado committed Sep 10, 2024
1 parent 49ec2fd commit 21aaf3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 22 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OC\Authentication\Token\INamedToken;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC_Helper;
use OCA\SimpleSettings\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
Expand All @@ -34,7 +35,9 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\Exceptions\InvalidTokenException;
use OCP\Files\FileInfo;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -49,30 +52,36 @@ class PageController extends Controller {
private IConfig $config;
private IUserManager $userManager;
private IFactory $l10nFactory;
private $l;
private IProvider $tokenProvider;
private IInitialState $initialState;
private IUserSession $userSession;
private ISession $session;
private string|null $uid;
private OC_Helper $helper;

public function __construct(
IConfig $config,
IUserManager $userManager,
IFactory $l10nFactory,
IL10N $l,
IProvider $tokenProvider,
ISession $session,
IInitialState $initialState,
IUserSession $userSession,
?string $UserId
?string $UserId,
OC_Helper $helper
) {
$this->config = $config;
$this->userManager = $userManager;
$this->l10nFactory = $l10nFactory;
$this->l = $l;
$this->tokenProvider = $tokenProvider;
$this->session = $session;
$this->initialState = $initialState;
$this->userSession = $userSession;
$this->uid = $UserId;
$this->helper = $helper;
}

#[NoCSRFRequired]
Expand All @@ -92,10 +101,22 @@ public function index(): TemplateResponse {

$user = $this->userManager->get($this->uid);

$storageInfo = $this->helper::getStorageInfo('/');
if ($storageInfo['quota'] !== FileInfo::SPACE_UNLIMITED) {
$totalSpace = $this->l->t('Unlimited');
} else {
$totalSpace = $this->helper::humanFileSize($storageInfo['total']);
}

$this->initialState->provideInitialState(
'personalInfoParameters',
[
'languageMap' => $this->getLanguageMap($user),
'quota' => $storageInfo['quota'],
'totalSpace' => $totalSpace,
'freeSpace' => $this->helper::humanFileSize($storageInfo['free']),
'usage' => $this->helper::humanFileSize($storageInfo['used']),
'usageRelative' => round($storageInfo['relative']),
]
);

Expand Down
8 changes: 7 additions & 1 deletion tests/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
use OC\Authentication\Token\INamedToken;
use OC\Authentication\Token\IProvider as IAuthTokenProvider;
use OC\Authentication\Token\IToken;
use OC_Helper;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -45,21 +47,25 @@ protected function setUp(): void {
$this->config = $this->createMock(IConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->l = $this->createMock(IL10N::class);
$this->tokenProvider = $this->createMock(IAuthTokenProvider::class);
$this->session = $this->createMock(ISession::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->uid = "mock-user-id-123";
$this->helper = $this->createMock(OC_Helper::class);

$this->controller = new PageController(
$this->config,
$this->userManager,
$this->l10nFactory,
$this->l,
$this->tokenProvider,
$this->session,
$this->initialState,
$this->userSession,
$this->uid
$this->uid,
$this->helper
);

$mockCurrentSessionId = "mock-session-id-123";
Expand Down

0 comments on commit 21aaf3f

Please sign in to comment.