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

Commit 4f172c7

Browse files
committed
ENH: refs #0377. Models and module config view for size quota module
1 parent 2ede090 commit 4f172c7

29 files changed

+886
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
/** Size quota Application Controller */
22+
class Sizequota_AppController extends MIDAS_GlobalModule
23+
{
24+
public $moduleName = 'sizequota';
25+
26+
/** folder quota model */
27+
var $Sizequota_Folderquota;
28+
} //end class
29+
?>

modules/sizequota/Notification.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
/** notification manager for sizequota module */
22+
class Sizequota_Notification extends MIDAS_Notification
23+
{
24+
public $moduleName = 'sizequota';
25+
public $_moduleComponents = array();
26+
public $_models = array();
27+
28+
/** init notification process */
29+
public function init()
30+
{
31+
//$this->addCallBack('CALLBACK_CORE_GET_MANAGE_COMMUNITY_TABS', 'getCommunityTab');
32+
//$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
33+
//$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
34+
}
35+
36+
/** Add a tab to the manage community page for size quota */
37+
public function getCommunityTab($args)
38+
{
39+
//TODO
40+
}
41+
42+
/** Add a tab to the user's main page for size quota */
43+
public function getUserTab($args)
44+
{
45+
//TODO
46+
}
47+
48+
/** Return whether or not the upload is allowed. If uploading the file
49+
* will cause the size to pass the quota, it will be rejected.
50+
*/
51+
public function validateUpload($args)
52+
{
53+
//TODO
54+
return true;
55+
}
56+
} //end class
57+
?>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.local.ini
2+
*.local.ini.old
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[global]
2+
; version of the module
3+
version = 1.0.0
4+
; full name
5+
fullname = Size Quotas
6+
; description
7+
description = "Allows maximum size quotas to be set on communities and users"
8+
;Category
9+
category = Core
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
//define("MIDAS_EXAMPLE", 0);
21+
?>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
/** sizequota main config controller */
22+
class Sizequota_ConfigController extends Sizequota_AppController
23+
{
24+
public $_moduleForms = array('Config');
25+
26+
/** index action*/
27+
function indexAction()
28+
{
29+
$this->requireAdminPrivileges();
30+
31+
$modelLoader = new MIDAS_ModelLoader();
32+
$settingModel = $modelLoader->loadModel('Setting');
33+
$defaultUserQuota = $settingModel->getValueByName('defaultuserquota', $this->moduleName);
34+
$defaultCommunityQuota = $settingModel->getValueByName('defaultcommunityquota', $this->moduleName);
35+
36+
$configForm = $this->ModuleForm->Config->createConfigForm();
37+
$formArray = $this->getFormAsArray($configForm);
38+
if($defaultUserQuota !== null)
39+
{
40+
$formArray['defaultuserquota']->setValue($defaultUserQuota);
41+
}
42+
if($defaultCommunityQuota !== null)
43+
{
44+
$formArray['defaultcommunityquota']->setValue($defaultCommunityQuota);
45+
}
46+
$this->view->configForm = $formArray;
47+
48+
if($this->_request->isPost())
49+
{
50+
$this->disableLayout();
51+
$this->_helper->viewRenderer->setNoRender();
52+
$submitConfig = $this->_getParam('submitConfig');
53+
if(isset($submitConfig))
54+
{
55+
$defaultUserQuota = $this->_getParam('defaultuserquota');
56+
$defaultCommunityQuota = $this->_getParam('defaultcommunityquota');
57+
if(!$this->_isValidQuota(array($defaultUserQuota, $defaultCommunityQuota)))
58+
{
59+
echo JsonComponent::encode(array(false, 'Invalid quota value. Please enter a positive integer.'));
60+
return;
61+
}
62+
$settingModel->setConfig('defaultuserquota', $defaultUserQuota, $this->moduleName);
63+
$settingModel->setConfig('defaultcommunityquota', $defaultCommunityQuota, $this->moduleName);
64+
echo JsonComponent::encode(array(true, 'Changes saved'));
65+
}
66+
}
67+
}
68+
69+
/** Test whether the provided quota value is legal */
70+
private function _isValidQuota($quotas)
71+
{
72+
foreach($quotas as $quota)
73+
{
74+
if(!preg_match('/^[0-9]*$/', $quota))
75+
{
76+
return false;
77+
}
78+
}
79+
return true;
80+
}
81+
82+
}//end class
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/** sizequota config form */
22+
class Sizequota_ConfigForm extends AppForm
23+
{
24+
/** create the admin->modules page config form */
25+
public function createConfigForm()
26+
{
27+
$form = new Zend_Form;
28+
$form->setAction($this->webroot.'/sizequota/config/index')
29+
->setMethod('post');
30+
31+
$defaultUserQuota = new Zend_Form_Element_Text('defaultuserquota');
32+
$defaultCommunityQuota = new Zend_Form_Element_Text('defaultcommunityquota');
33+
34+
$submit = new Zend_Form_Element_Submit('submitConfig');
35+
$submit->setLabel('Save configuration');
36+
37+
$form->addElements(array($defaultUserQuota, $defaultCommunityQuota, $submit));
38+
return $form;
39+
}
40+
} // end class
41+
?>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
CREATE TABLE IF NOT EXISTS `sizequota_folderquota` (
3+
`folderquota_id` bigint(20) NOT NULL AUTO_INCREMENT,
4+
`folder_id` bigint(20) NOT NULL,
5+
`quota` bigint(20) NOT NULL,
6+
PRIMARY KEY (`folderquota_id`),
7+
KEY `folder_id` (`folder_id`)
8+
) DEFAULT CHARSET=utf8;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP TABLE IF EXISTS sizequota_folderquota;
2+
3+
CREATE TABLE sizequota_folderquota (
4+
folderquota_id bigint serial PRIMARY KEY,
5+
folder_id bigint NOT NULL,
6+
quota bigint NOT NULL
7+
);
8+
CREATE INDEX sizequota_folderquota_folder_id ON sizequota_folderquota (folder_id);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
/** sizequota App Dao */
22+
class Sizequota_AppDao extends MIDAS_GlobalDao
23+
{
24+
25+
} //end class
26+
27+
?>

0 commit comments

Comments
 (0)