Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 83be7a8

Browse files
committed
BUG: refs #0377. Client side quota validation should respect default settings
1 parent f00c4b2 commit 83be7a8

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

modules/sizequota/Notification.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function init()
3333
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
3434
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getScript');
3535
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getSimpleuploadExtraHtml');
36-
//$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
36+
$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
3737

3838
$this->enableWebAPI($this->moduleName);
3939
}
@@ -80,24 +80,24 @@ public function getSimpleuploadExtraHtml($args)
8080

8181
$folder = $args['folder'];
8282
$rootFolder = $folderModel->getRoot($folder);
83-
$quota = $folderQuotaModel->getQuota($rootFolder);
84-
if($quota === false)
83+
$quota = $folderQuotaModel->getFolderQuota($rootFolder);
84+
if($quota == '')
8585
{
8686
return '<div id="sizequotaFreeSpace" style="display:none;"></div>';
8787
}
8888
else
8989
{
90-
$freeSpace = number_format($quota->getQuota() - $folderModel->getSize($rootFolder), 0, '.', '');
90+
$freeSpace = number_format($quota - $folderModel->getSize($rootFolder), 0, '.', '');
9191
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>';
9292
}
9393
}
9494

95-
/** Return whether or not the upload is allowed. If uploading the file
96-
* will cause the size to pass the quota, it will be rejected.
95+
/**
96+
* Return whether or not the upload is allowed. If uploading the file
97+
* will cause the size to surpass the quota, it will be rejected.
9798
*/
9899
public function validateUpload($args)
99100
{
100-
//TODO
101101
return true;
102102
}
103103
} //end class

modules/sizequota/controllers/ConfigController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ public function getfreespaceAction()
181181
return;
182182
}
183183
$rootFolder = $this->Folder->getRoot($folder);
184-
$quota = $this->Sizequota_FolderQuota->getQuota($rootFolder);
185-
if($quota === false)
184+
$quota = $this->Sizequota_FolderQuota->getFolderQuota($rootFolder);
185+
if($quota == '')
186186
{
187187
$freeSpace = '';
188188
}
189189
else
190190
{
191-
$freeSpace = number_format($quota->getQuota() - $this->Folder->getSize($rootFolder), 0, '.', '');
191+
$freeSpace = number_format($quota - $this->Folder->getSize($rootFolder), 0, '.', '');
192192
}
193193
echo JsonComponent::encode(array('status' => true, 'freeSpace' => $freeSpace));
194194
}

modules/sizequota/models/base/FolderQuotaModelBase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ public function __construct()
4141
/** Get the quota dao for a particular folder, or return false if none is set */
4242
public abstract function getQuota($folder);
4343

44+
/** Get the quota in bytes for a particular folder, or return the default if none is set */
45+
public function getFolderQuota($folder)
46+
{
47+
$quotaDao = $this->getQuota($folder);
48+
if(!$quotaDao)
49+
{
50+
$modelLoader = new MIDAS_ModelLoader();
51+
$settingModel = $modelLoader->loadModel('Setting');
52+
if($folder->getParentId() == -1) //user
53+
{
54+
$settingName = 'defaultuserquota';
55+
}
56+
else
57+
{
58+
$settingName = 'defaultcommunityquota';
59+
}
60+
return $settingModel->getValueByName($settingName, $this->moduleName);
61+
}
62+
return $quotaDao->getQuota();
63+
}
64+
4465
/** Get the quota in bytes for a particular user, or return the default if none is set */
4566
public function getUserQuota($user)
4667
{

0 commit comments

Comments
 (0)