Admin - Account - add quota configuration
authorPaul Mehrer <p.mehrer@metaways.de>
Mon, 10 Jul 2017 14:01:07 +0000 (16:01 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Tue, 11 Jul 2017 07:41:08 +0000 (09:41 +0200)
Change-Id: Ia7ed24412c912812d55cc5f2364e19e80bf7322a
Reviewed-on: http://gerrit.tine20.com/customers/5078
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Admin/JsonTest.php
tine20/Tinebase/Convert/FullUser/Json.php [new file with mode: 0644]
tine20/Tinebase/Model/FullUser.php
tine20/Tinebase/Setup/Update/Release10.php
tine20/Tinebase/Setup/setup.xml

index 8b4c56c..b6073a9 100644 (file)
@@ -107,6 +107,7 @@ class Admin_JsonTest extends TestCase
         $accountData = $this->_getUserArrayWithPw();
         $accountData['accountPrimaryGroup'] = Tinebase_Group::getInstance()->getGroupByName('tine20phpunitgroup')->getId();
         $accountData['accountFirstName'] = 'PHPUnitup';
+        $accountData['configuration'][Tinebase_Model_FullUser::CONFIGURATION_PERSONAL_QUOTA] = 100;
         
         $account = $this->_createUser($accountData);
         
@@ -117,6 +118,9 @@ class Admin_JsonTest extends TestCase
         // check password
         $authResult = Tinebase_Auth::getInstance()->authenticate($account['accountLoginName'], $accountData['accountPassword']);
         $this->assertTrue($authResult->isValid());
+        $this->assertTrue(isset($accountData['configuration']) && isset($accountData['configuration'][Tinebase_Model_FullUser::CONFIGURATION_PERSONAL_QUOTA])
+            && $accountData['configuration'][Tinebase_Model_FullUser::CONFIGURATION_PERSONAL_QUOTA] === 100,
+            'failed to set/get account configuration');
         
         $account['accountPrimaryGroup'] = $accountData['accountPrimaryGroup'];
         return $account;
diff --git a/tine20/Tinebase/Convert/FullUser/Json.php b/tine20/Tinebase/Convert/FullUser/Json.php
new file mode 100644 (file)
index 0000000..3f76def
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * convert functions for records from/to json (array) format
+ *
+ * @package     Tinebase
+ * @subpackage  Convert
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Paul Mehrer <p.mehrer@metaways.de>
+ * @copyright   Copyright (c) 2017-2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * convert functions for records from/to json (array) format
+ *
+ * @package     Tinebase
+ * @subpackage  Convert
+ */
+class Tinebase_Convert_FullUser_Json extends Tinebase_Convert_Json
+{
+    /**
+     * resolves child records before converting the record set to an array
+     *
+     * @param Tinebase_Record_RecordSet $records
+     * @param Tinebase_ModelConfiguration $modelConfiguration
+     * @param boolean $multiple
+     */
+    protected function _resolveBeforeToArray($records, $modelConfiguration, $multiple = false)
+    {
+        /** @noinspection PhpUndefinedMethodInspection */
+        $records->xprops('configuration');
+
+        parent::_resolveBeforeToArray($records, $modelConfiguration, $multiple);
+    }
+}
\ No newline at end of file
index 20b103b..d87e706 100644 (file)
@@ -28,6 +28,7 @@
  * @property    string                      accountLoginShell   account login shell
  * @property    string                      accountPrimaryGroup primary group id
  * @property    string                      container_id
+ * @property    string                      configuration
  * @property    array                       groups              list of group memberships
  * @property    Tinebase_DateTime           lastLoginFailure    time of last login failure
  * @property    int                         loginFailures       number of login failures
@@ -40,6 +41,8 @@
  */
 class Tinebase_Model_FullUser extends Tinebase_Model_User
 {
+    const CONFIGURATION_PERSONAL_QUOTA = 'personalQuota';
+
     /**
      * list of zend inputfilter
      * 
@@ -125,6 +128,7 @@ class Tinebase_Model_FullUser extends Tinebase_Model_User
                 Tinebase_Model_User::VISIBILITY_HIDDEN, 
                 Tinebase_Model_User::VISIBILITY_DISPLAYED)
             ), Zend_Filter_Input::DEFAULT_VALUE => Tinebase_Model_User::VISIBILITY_DISPLAYED),
+            'configuration'         => array('allowEmpty' => true),
             'created_by'            => array('allowEmpty' => true),
             'creation_time'         => array('allowEmpty' => true),
             'last_modified_by'      => array('allowEmpty' => true),
@@ -373,4 +377,17 @@ class Tinebase_Model_FullUser extends Tinebase_Model_User
         
         return $username;
     }
+
+    public function runConvertToData()
+    {
+        if (isset($this->_properties['configuration']) && is_array($this->_properties['configuration'])) {
+            if (count($this->_properties['configuration']) > 0) {
+                $this->_properties['configuration'] = json_encode($this->_properties['configuration']);
+            } else {
+                $this->_properties['configuration'] = null;
+            }
+        }
+
+        parent::runConvertToData();
+    }
 }
index c771330..bf9f571 100644 (file)
@@ -1731,4 +1731,22 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
 
         $this->setApplicationVersion('Tinebase', '10.34');
     }
+
+    /**
+     * update to 10.35
+     *
+     * add configuration column to accounts
+     */
+    public function update_34()
+    {
+        if (! $this->_backend->columnExists('configuration', 'accounts')) {
+            $this->_backend->addCol('accounts', new Setup_Backend_Schema_Field_Xml('<field>
+                    <name>configuration</name>
+                    <type>text</type>
+                    <length>65535</length>
+                </field>'));
+            $this->setTableVersion('accounts', 13);
+        }
+        $this->setApplicationVersion('Tinebase', '10.35');
+    }
 }
index db5d7a3..428d090 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Tinebase</name>
-    <version>10.34</version>
+    <version>10.35</version>
     <tables>
         <table>
             <name>applications</name>
 
         <table>
             <name>accounts</name>
-            <version>12</version>
+            <version>13</version>
             <declaration>
                 <field>
                     <name>id</name>
                     <length>40</length>
                 </field>
                 <field>
+                    <name>configuration</name>
+                    <type>text</type>
+                    <length>65535</length>
+                </field>
+                <field>
                     <name>created_by</name>
                     <type>text</type>
                     <length>40</length>