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

Commit a4064a0

Browse files
committed
ENH: refs #0377. Basic view and form handler for folder-specific quota mgmt
1 parent 83f6672 commit a4064a0

File tree

7 files changed

+203
-9
lines changed

7 files changed

+203
-9
lines changed

core/models/pdo/FolderModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public function move($folder, $parent)
389389
$tmpParent = $tmpParent->getParent();
390390
}
391391

392-
if(!$folder instanceof FolderDao)
392+
if(!$folder instanceof FolderDao)
393393
{
394394
throw new Zend_Exception("Error parameter.");
395395
}

modules/sizequota/constant/module.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
See the License for the specific language governing permissions and
1818
limitations under the License.
1919
=========================================================================*/
20-
//define("MIDAS_EXAMPLE", 0);
20+
define("MIDAS_USE_DEFAULT_QUOTA", 0);
21+
define("MIDAS_USE_SPECIFIC_QUOTA", 1);
2122
?>

modules/sizequota/controllers/ConfigController.php

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** sizequota main config controller */
21+
/**
22+
* This controller is used to manage size quotas on folders.
23+
* It contains the actions for the main module configuration page as well as for
24+
* maintaining folder-specific quotas.
25+
*/
2226
class Sizequota_ConfigController extends Sizequota_AppController
2327
{
28+
public $_models = array('Folder', 'Setting');
29+
public $_moduleModels = array('FolderQuota');
2430
public $_moduleForms = array('Config');
2531

2632
/** index action*/
@@ -29,9 +35,8 @@ function indexAction()
2935
$this->requireAdminPrivileges();
3036

3137
$modelLoader = new MIDAS_ModelLoader();
32-
$settingModel = $modelLoader->loadModel('Setting');
33-
$defaultUserQuota = $settingModel->getValueByName('defaultuserquota', $this->moduleName);
34-
$defaultCommunityQuota = $settingModel->getValueByName('defaultcommunityquota', $this->moduleName);
38+
$defaultUserQuota = $this->Setting->getValueByName('defaultuserquota', $this->moduleName);
39+
$defaultCommunityQuota = $this->Setting->getValueByName('defaultcommunityquota', $this->moduleName);
3540

3641
$configForm = $this->ModuleForm->Config->createConfigForm();
3742
$formArray = $this->getFormAsArray($configForm);
@@ -59,14 +64,94 @@ function indexAction()
5964
echo JsonComponent::encode(array(false, 'Invalid quota value. Please enter a positive integer.'));
6065
return;
6166
}
62-
$settingModel->setConfig('defaultuserquota', $defaultUserQuota, $this->moduleName);
63-
$settingModel->setConfig('defaultcommunityquota', $defaultCommunityQuota, $this->moduleName);
67+
$this->Setting->setConfig('defaultuserquota', $defaultUserQuota, $this->moduleName);
68+
$this->Setting->setConfig('defaultcommunityquota', $defaultCommunityQuota, $this->moduleName);
6469
echo JsonComponent::encode(array(true, 'Changes saved'));
6570
}
6671
}
6772
}
6873

69-
/** Test whether the provided quota value is legal */
74+
/** Renders the view for folder-specific quotas */
75+
public function folderAction()
76+
{
77+
$this->disableLayout();
78+
if(!$this->_getParam('folderId'))
79+
{
80+
throw new Zend_Exception('Invalid parameters');
81+
}
82+
$folder = $this->Folder->load($this->_getParam('folderId'));
83+
84+
if(!$folder)
85+
{
86+
throw new Zend_Exception('Invalid folderId parameter');
87+
}
88+
if(!$this->Folder->policyCheck($folder, $this->userSession->Dao, MIDAS_POLICY_READ))
89+
{
90+
throw new Zend_Exception('Invalid policy');
91+
}
92+
93+
if($folder->getParentId() == -1) //user folder
94+
{
95+
$defaultQuota = $this->Setting->getValueByName('defaultuserquota', $this->moduleName);
96+
}
97+
else if($folder->getParentId() == -2) //community folder
98+
{
99+
$defaultQuota = $this->Setting->getValueByName('defaultcommunityquota', $this->moduleName);
100+
}
101+
else
102+
{
103+
throw new Zend_Exception('Must be a community or user root folder');
104+
}
105+
106+
$currentQuota = $this->Sizequota_FolderQuota->getQuota($folder);
107+
$configForm = $this->ModuleForm->Config->createFolderForm($defaultQuota);
108+
$formArray = $this->getFormAsArray($configForm);
109+
if($currentQuota === false)
110+
{
111+
$formArray['usedefault']->setValue(MIDAS_USE_DEFAULT_QUOTA);
112+
$this->view->quota = $defaultQuota;
113+
}
114+
else
115+
{
116+
$formArray['usedefault']->setValue(MIDAS_USE_SPECIFIC_QUOTA);
117+
$formArray['quota']->setValue($currentQuota->getQuota());
118+
$this->view->quota = $currentQuota->getQuota();
119+
}
120+
$this->view->configForm = $formArray;
121+
$this->view->folder = $folder;
122+
$this->view->usedSpace = $this->Folder->getSizeFiltered($folder, $this->userSession->Dao);
123+
}
124+
125+
/** Used to manage folder-specific quotas (form handler) */
126+
public function foldersubmitAction()
127+
{
128+
$this->requireAdminPrivileges();
129+
130+
$this->disableLayout();
131+
$this->_helper->viewRenderer->setNoRender();
132+
$quota = $this->_getParam('quota');
133+
$useDefault = $this->_getParam('usedefault');
134+
if($useDefault == MIDAS_USE_DEFAULT_QUOTA)
135+
{
136+
$quota = null;
137+
}
138+
$folder = $this->Folder->load($this->_getParam('folderId'));
139+
if(!$folder)
140+
{
141+
echo JsonComponent::encode(array(false, 'Invalid folderId parameter'));
142+
return;
143+
}
144+
if($quota !== null && !$this->_isValidQuota(array($quota)))
145+
{
146+
echo JsonComponent::encode(array(false, 'Invalid quota value. Please enter a positive integer.'));
147+
return;
148+
}
149+
150+
$this->Sizequota_FolderQuota->setQuota($folder, $quota);
151+
echo JsonComponent::encode(array(true, 'Changes saved'));
152+
}
153+
154+
/** Test whether the provided quota values are legal */
70155
private function _isValidQuota($quotas)
71156
{
72157
foreach($quotas as $quota)

modules/sizequota/controllers/forms/ConfigForm.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,32 @@ public function createConfigForm()
3737
$form->addElements(array($defaultUserQuota, $defaultCommunityQuota, $submit));
3838
return $form;
3939
}
40+
41+
/** form used to set a folder-specific quota */
42+
public function createFolderForm($defaultQuota)
43+
{
44+
if($defaultQuota === '')
45+
{
46+
$defaultQuota = $this->t('Unlimited');
47+
}
48+
$form = new Zend_Form;
49+
$form->setAction($this->webroot.'/sizequota/config/foldersubmit')
50+
->setMethod('post');
51+
52+
$submit = new Zend_Form_Element_Submit('submitQuota');
53+
$submit->setLabel($this->t('Save'));
54+
55+
$useDefault = new Zend_Form_Element_Radio('usedefault');
56+
$useDefault->addMultiOptions(array(MIDAS_USE_DEFAULT_QUOTA => $this->t('Use the default quota: ').$defaultQuota,
57+
MIDAS_USE_SPECIFIC_QUOTA => $this->t('Use a specific quota:')))
58+
->setRequired(true);
59+
60+
$quota = new Zend_Form_Element_Text('quota');
61+
$quota->setAttrib('quota', 30);
62+
63+
$form->addElements(array($useDefault, $quota, $submit));
64+
return $form;
65+
}
66+
4067
} // end class
4168
?>

modules/sizequota/public/css/config/config.folder.css

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$(document).ready(function() {
2+
3+
4+
$('#configForm').ajaxForm( {beforeSubmit: validateConfig, success: successConfig} );
5+
});
6+
7+
8+
function validateConfig(formData, jqForm, options) {
9+
10+
}
11+
12+
function successConfig(responseText, statusText, xhr, form)
13+
{
14+
try {
15+
jsonResponse = jQuery.parseJSON(responseText);
16+
} catch (e) {
17+
alert("An error occured. Please check the logs.");
18+
return false;
19+
}
20+
if(jsonResponse==null)
21+
{
22+
createNotive('Error',4000);
23+
return;
24+
}
25+
if(jsonResponse[0])
26+
{
27+
createNotive(jsonResponse[1],4000);
28+
}
29+
else
30+
{
31+
createNotive(jsonResponse[1],4000);
32+
}
33+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.form.js');
22+
$this->headScript()->appendFile($this->moduleWebroot.'/public/js/config/config.folder.js');
23+
?>
24+
<link type="text/css" rel="stylesheet" href="<?php echo $this->moduleWebroot?>/public/css/config/config.folder.css" />
25+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.genericPage.css" />
26+
27+
</div>
28+
<form class='genericForm' id='configForm' method='<?php echo $this->configForm['method'] ?>' action='<?php echo $this->configForm['action'] ?>'>
29+
<h3>Size Quota Module Configuration:</h3>
30+
Leave a field blank to indicate an unlimited quota.
31+
<br /><br />
32+
<div>
33+
<?php
34+
echo $this->configForm['usedefault'];
35+
echo $this->configForm['quota'];
36+
?>
37+
<div>
38+
<?php echo $this->configForm['submitQuota']; ?>
39+
</div>
40+
<input type="hidden" name="folderId" value="<?php echo $this->folder->getKey(); ?>" />
41+
</form>
42+
</div>
43+
44+
45+
46+
47+
48+

0 commit comments

Comments
 (0)