CC-5786: Quota Enforcement in the File Upload API

This commit is contained in:
drigato 2014-04-14 11:24:39 -04:00
parent 7fbd285dd0
commit 4add0f0b7b
4 changed files with 38 additions and 3 deletions

View File

@ -25,6 +25,11 @@ class PluploadController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'css/plupload.queue.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']);
$this->view->quotaLimitReached = false;
if (Application_Model_Preference::getDiskUsage() > Application_Model_Preference::getDiskQuota()) {
$this->view->quotaLimitReached = true;
}
}
public function recentUploadsAction()

View File

@ -110,7 +110,7 @@ class Rest_MediaController extends Zend_Rest_Controller
{
return;
}
//If we do get an ID on a POST, then that doesn't make any sense
//since POST is only for creating.
if ($id = $this->_getParam('id', false)) {
@ -120,6 +120,13 @@ class Rest_MediaController extends Zend_Rest_Controller
return;
}
if (!$this->isEnoughDiskSpace()) {
$this->getResponse()
->setHttpResponseCode(400)
->appendBody("ERROR: Disk Quota limit reached.");
return;
}
$file = new CcFiles();
$whiteList = $this->removeBlacklistedFieldsFromRequestData($this->getRequest()->getPost());
@ -423,5 +430,19 @@ class Rest_MediaController extends Zend_Rest_Controller
return $response;
}
/**
*
* 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()) {
return true;
}
return false;
}
}

View File

@ -2,8 +2,15 @@
#plupload_files input[type="file"] {
font-size: 200px !important;
}
</style>
<form id="plupload_form">
</style>
<?php if ($this->quotaLimitReached) { ?>
<div class="errors quota-reached">
Disk quota exceeded. You cannot upload files until you <a href="http://www.sourcefabric.org/en/airtime" target="_blank">upgrade your storage</a>.
</div>
<?php
}
?>
<form id="plupload_form" <?php if ($this->quotaLimitReached) { ?> class="hidden" <?php } ?>>
<div id="plupload_files"></div>
</form>
<div id="plupload_error">

View File

@ -3087,3 +3087,5 @@ dd .stream-status {
#popup-share-link {
width: 320px;
}
.quota-reached {
font-size: 14px !important;