CC-5786: Quota Enforcement in the File Upload API

Tweaked this so it will work on self-hosted instances
This commit is contained in:
drigato 2014-04-14 12:09:15 -04:00
parent 4add0f0b7b
commit 63e2eda64b
3 changed files with 16 additions and 10 deletions

View File

@ -27,7 +27,7 @@ class PluploadController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']);
$this->view->quotaLimitReached = false; $this->view->quotaLimitReached = false;
if (Application_Model_Preference::getDiskUsage() > Application_Model_Preference::getDiskQuota()) { if (Application_Model_Systemstatus::isDiskOverQuota()) {
$this->view->quotaLimitReached = true; $this->view->quotaLimitReached = true;
} }
} }

View File

@ -235,4 +235,16 @@ class Application_Model_Systemstatus
return array_values($partitions); return array_values($partitions);
} }
public static function isDiskOverQuota()
{
$diskInfo = self::GetDiskInfo();
$diskInfo = $diskInfo[0];
$diskUsage = $diskInfo->totalSpace - $diskInfo->totalFreeSpace;
if ($diskUsage > $diskInfo->totalSpace) {
return true;
}
return false;
}
} }

View File

@ -120,7 +120,7 @@ class Rest_MediaController extends Zend_Rest_Controller
return; return;
} }
if (!$this->isEnoughDiskSpace()) { if (!$this->isDiskOverQuota()) {
$this->getResponse() $this->getResponse()
->setHttpResponseCode(400) ->setHttpResponseCode(400)
->appendBody("ERROR: Disk Quota limit reached."); ->appendBody("ERROR: Disk Quota limit reached.");
@ -430,15 +430,9 @@ class Rest_MediaController extends Zend_Rest_Controller
return $response; return $response;
} }
/** private function isDiskOverQuota()
*
* Checks if there is enough disk space to upload the file in question
* We allow one file to exceed to the disk quota so it is possible for the
* disk usage to be greater than the disk usage value
*/
private function isEnoughDiskSpace()
{ {
if (Application_Model_Preference::getDiskUsage() < Application_Model_Preference::GetDiskQuota()) { if (Application_Model_Systemstatus::isDiskOverQuota()) {
return true; return true;
} }
return false; return false;