Filemanager - add quota by folder
authorPaul Mehrer <p.mehrer@metaways.de>
Mon, 10 Jul 2017 15:12:48 +0000 (17:12 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Tue, 11 Jul 2017 07:41:43 +0000 (09:41 +0200)
admin grant required to set quota via json frontend

Change-Id: I9445dd60b7650583ccac7a8eaed1caf2b10d8de1
Reviewed-on: http://gerrit.tine20.com/customers/5083
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Filemanager/Frontend/JsonTests.php
tine20/Filemanager/Controller/Node.php
tine20/Tinebase/Model/Tree/Node.php
tine20/Tinebase/Setup/Update/Release10.php
tine20/Tinebase/Setup/setup.xml

index d470632..d902ee4 100644 (file)
@@ -759,6 +759,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $personalContainerNode['revisionProps']['keep'] = true;
         $personalContainerNode['revisionProps']['keepNum'] = 3;
         $personalContainerNode['revisionProps']['keepMonth'] = 4;
+        $personalContainerNode['quota'] = 10 * 1024 * 1024 * 1024; // 10 GB -> exceeds 32bit integer
         $updatedNode = $this->_getUit()->saveNode($personalContainerNode);
 
         static::assertTrue(isset($updatedNode['customfields']) && isset($updatedNode['customfields'][$cf->name]),
@@ -773,6 +774,17 @@ class Filemanager_Frontend_JsonTests extends TestCase
         static::assertEquals($personalContainerNode['revisionProps']['keep'], true);
         static::assertEquals($personalContainerNode['revisionProps']['keepNum'], 3);
         static::assertEquals($personalContainerNode['revisionProps']['keepMonth'], 4);
+        static::assertEquals($personalContainerNode['quota'], 10 * 1024 * 1024 * 1024);
+
+        return $updatedNode;
+    }
+
+    public function testUnsetQuota()
+    {
+        $node = $this->testUpdateNodeWithCustomfield();
+        $node['quota'] = null;
+        $updatedNode = $this->_getUit()->saveNode($node);
+        static::assertTrue(!isset($updatedNode['quota']), 'unset of quota did not work');
     }
     
     /**
index df6b23c..cc73b97 100644 (file)
@@ -164,20 +164,21 @@ class Filemanager_Controller_Node extends Tinebase_Controller_Record_Abstract
      * inspect update of one record (before update)
      *
      * @param   Filemanager_Model_Node $_record      the update record
-     * @param   Tinebase_Record_Interface $_oldRecord   the current persistent record
+     * @param   Filemanager_Model_Node $_oldRecord   the current persistent record
      * @return  void
      */
     protected function _inspectBeforeUpdate($_record, $_oldRecord)
     {
         // protect against file object spoofing
         foreach (array_keys($_record->toArray()) as $property) {
-            if (! in_array($property, array('name', 'description', 'relations', 'customfields', 'tags', 'notes', 'acl_node', 'grants', Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION, Tinebase_Model_Tree_Node::XPROPS_REVISION))) {
+            if (! in_array($property, array('name', 'description', 'relations', 'customfields', 'tags', 'notes', 'acl_node', 'grants', 'quota', Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION, Tinebase_Model_Tree_Node::XPROPS_REVISION))) {
                 $_record->{$property} = $_oldRecord->{$property};
             }
         }
 
         if (!Tinebase_Core::getUser()->hasGrant($_record, Tinebase_Model_Grants::GRANT_ADMIN, 'Tinebase_Model_Tree_Node')) {
             $_record->{Tinebase_Model_Tree_Node::XPROPS_REVISION} = $_oldRecord->{Tinebase_Model_Tree_Node::XPROPS_REVISION};
+            $_record->quota = $_oldRecord->quota;
         }
 
         // update node acl
index e2b460f..9cd9b6e 100644 (file)
@@ -32,6 +32,7 @@
  * @property    array              revisionProps
  * @property    array              notificationProps
  * @property    string             preview_count
+ * @property    integer            quota
  * @property    Tinebase_Record_RecordSet grants
  */
 class Tinebase_Model_Tree_Node extends Tinebase_Record_Abstract
@@ -118,6 +119,7 @@ class Tinebase_Model_Tree_Node extends Tinebase_Record_Abstract
             Zend_Filter_Input::DEFAULT_VALUE => '0',
             array('InArray', array(true, false))
         ),
+        'quota'             => array(Zend_Filter_Input::ALLOW_EMPTY => true),
 
         'relations' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'notes' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
index bf9f571..204166d 100644 (file)
@@ -1749,4 +1749,35 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
         }
         $this->setApplicationVersion('Tinebase', '10.35');
     }
+
+    /**
+     * update to 10.36
+     *
+     * add quota column to tree_nodes
+     */
+    public function update_35()
+    {
+        if (! $this->_backend->columnExists('quota', 'tree_nodes')) {
+            $this->_backend->addCol('tree_nodes', new Setup_Backend_Schema_Field_Xml('<field>
+                    <name>quota</name>
+                    <type>integer</type>
+                    <length>64</length>
+                    <notnull>false</notnull>
+                </field>'));
+            $this->setTableVersion('tree_nodes', 5);
+        }
+
+        if ($this->getTableVersion('tree_fileobjects') < 6) {
+            $this->_backend->alterCol('tree_fileobjects', new Setup_Backend_Schema_Field_Xml('<field>
+                    <name>revision_size</name>
+                    <type>integer</type>
+                    <length>64</length>
+                    <notnull>true</notnull>
+                    <default>0</default>
+                </field>'));
+            $this->setTableVersion('tree_fileobjects', 6);
+        }
+
+        $this->setApplicationVersion('Tinebase', '10.36');
+    }
 }
index 428d090..0e25e3b 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Tinebase</name>
-    <version>10.35</version>
+    <version>10.36</version>
     <tables>
         <table>
             <name>applications</name>
         
         <table>
             <name>tree_fileobjects</name>
-            <version>5</version>
+            <version>6</version>
             <declaration>
                 <field>
                     <name>id</name>
                 <field>
                     <name>revision_size</name>
                     <type>integer</type>
+                    <length>64</length>
                     <notnull>true</notnull>
                     <default>0</default>
                 </field>
                 <field>
                     <name>preview_count</name>
                     <type>integer</type>
-                    <length>64</length>
                     <notnull>true</notnull>
                     <default>0</default>
                 </field>
 
         <table>
             <name>tree_nodes</name>
-            <version>4</version>
+            <version>5</version>
             <declaration>
                 <field>
                     <name>id</name>
                     <default>false</default>
                     <notnull>true</notnull>
                 </field>
+                <field>
+                    <name>quota</name>
+                    <type>integer</type>
+                    <notnull>false</notnull>
+                    <length>64</length>
+                </field>
                 <index>
                     <name>id</name>
                     <primary>true</primary>