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

Commit

Permalink
BUG: refs #0377. Client side quota validation should respect default …
Browse files Browse the repository at this point in the history
…settings
  • Loading branch information
zachmullen committed Jan 11, 2012
1 parent f00c4b2 commit 83be7a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
14 changes: 7 additions & 7 deletions modules/sizequota/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function init()
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getScript');
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getSimpleuploadExtraHtml');
//$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');

$this->enableWebAPI($this->moduleName);
}
Expand Down Expand Up @@ -80,24 +80,24 @@ public function getSimpleuploadExtraHtml($args)

$folder = $args['folder'];
$rootFolder = $folderModel->getRoot($folder);
$quota = $folderQuotaModel->getQuota($rootFolder);
if($quota === false)
$quota = $folderQuotaModel->getFolderQuota($rootFolder);
if($quota == '')
{
return '<div id="sizequotaFreeSpace" style="display:none;"></div>';
}
else
{
$freeSpace = number_format($quota->getQuota() - $folderModel->getSize($rootFolder), 0, '.', '');
$freeSpace = number_format($quota - $folderModel->getSize($rootFolder), 0, '.', '');
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>';
}
}

/** Return whether or not the upload is allowed. If uploading the file
* will cause the size to pass the quota, it will be rejected.
/**
* Return whether or not the upload is allowed. If uploading the file
* will cause the size to surpass the quota, it will be rejected.
*/
public function validateUpload($args)
{
//TODO
return true;
}
} //end class
Expand Down
6 changes: 3 additions & 3 deletions modules/sizequota/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ public function getfreespaceAction()
return;
}
$rootFolder = $this->Folder->getRoot($folder);
$quota = $this->Sizequota_FolderQuota->getQuota($rootFolder);
if($quota === false)
$quota = $this->Sizequota_FolderQuota->getFolderQuota($rootFolder);
if($quota == '')
{
$freeSpace = '';
}
else
{
$freeSpace = number_format($quota->getQuota() - $this->Folder->getSize($rootFolder), 0, '.', '');
$freeSpace = number_format($quota - $this->Folder->getSize($rootFolder), 0, '.', '');
}
echo JsonComponent::encode(array('status' => true, 'freeSpace' => $freeSpace));
}
Expand Down
21 changes: 21 additions & 0 deletions modules/sizequota/models/base/FolderQuotaModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public function __construct()
/** Get the quota dao for a particular folder, or return false if none is set */
public abstract function getQuota($folder);

/** Get the quota in bytes for a particular folder, or return the default if none is set */
public function getFolderQuota($folder)
{
$quotaDao = $this->getQuota($folder);
if(!$quotaDao)
{
$modelLoader = new MIDAS_ModelLoader();
$settingModel = $modelLoader->loadModel('Setting');
if($folder->getParentId() == -1) //user
{
$settingName = 'defaultuserquota';
}
else
{
$settingName = 'defaultcommunityquota';
}
return $settingModel->getValueByName($settingName, $this->moduleName);
}
return $quotaDao->getQuota();
}

/** Get the quota in bytes for a particular user, or return the default if none is set */
public function getUserQuota($user)
{
Expand Down

0 comments on commit 83be7a8

Please sign in to comment.