Tinebase Replication - fix role members / rights
authorPaul Mehrer <p.mehrer@metaways.de>
Mon, 29 May 2017 15:03:32 +0000 (17:03 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 30 May 2017 09:51:25 +0000 (11:51 +0200)
Change-Id: Ife3ac4ceac7992c8ca4006dbe65fc9b80d5ff704
Reviewed-on: http://gerrit.tine20.com/customers/4773
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/Timemachine/ModificationLogTest.php
tine20/Tinebase/Acl/Roles.php
tine20/Tinebase/Role.php
tine20/Tinebase/Setup/Update/Release10.php
tine20/Tinebase/Setup/setup.xml

index 1faff53..1b74075 100644 (file)
@@ -355,7 +355,7 @@ class Tinebase_Timemachine_ModificationLogTest extends PHPUnit_Framework_TestCas
 
         /** @var Tinebase_Acl_Roles $roleController */
         $roleController = Tinebase_Core::getApplicationInstance('Tinebase_Model_Role');
-        $this->assertEquals('Tinebase_Acl_Roles', get_class($roleController));
+        $this->assertEquals('Tinebase_Role', get_class($roleController));
 
         $role = new Tinebase_Model_Role(array('name' => 'unittest test role'));
         $role = $roleController->create($role);
@@ -401,7 +401,7 @@ class Tinebase_Timemachine_ModificationLogTest extends PHPUnit_Framework_TestCas
 
         $newRole = $roleController->get($role->getId());
 
-        $diff = $role->diff($newRole, array('creation_time', 'created_by', 'last_modified_by', 'last_modified_time'));
+        $diff = $role->diff($newRole, array('seq', 'creation_time', 'created_by', 'last_modified_by', 'last_modified_time'));
 
         $this->assertTrue($diff->isEmpty(), 'diff should be empty: ' . print_r($diff, true));
 
index b1e811b..60402ab 100644 (file)
@@ -55,7 +55,7 @@ class Tinebase_Acl_Roles extends Tinebase_Controller_Record_Abstract
      *
      * disabled. use the singleton
      */
-    private function __construct() 
+    protected function __construct()
     {
         $this->_applicationName = 'Tinebase';
         $this->_modelName = 'Tinebase_Model_Role';
@@ -438,9 +438,10 @@ class Tinebase_Acl_Roles extends Tinebase_Controller_Record_Abstract
      *
      * @param   int $_roleId
      * @param   array $_roleMembers with role members ("account_type" => account type, "account_id" => account id)
+     * @param   bool $_allowSetId
      * @throws  Tinebase_Exception_InvalidArgument
      */
-    public function setRoleMembers($_roleId, array $_roleMembers)
+    public function setRoleMembers($_roleId, array $_roleMembers, $_allowSetId = false)
     {
         $roleId = (int)$_roleId;
         if ($roleId != $_roleId && $roleId > 0) {
@@ -469,6 +470,11 @@ class Tinebase_Acl_Roles extends Tinebase_Controller_Record_Abstract
                 'account_type'  => $member['type'],
                 'account_id'    => $member['id'],
             );
+            if (true === $_allowSetId && isset($member['dataId'])) {
+                $data['id'] = $member['dataId'];
+            } else {
+                $data['id'] = Tinebase_Record_Abstract::generateUID();
+            }
             $this->_getDb()->insert(SQL_TABLE_PREFIX . 'role_accounts', $data);
         }
 
@@ -550,6 +556,7 @@ class Tinebase_Acl_Roles extends Tinebase_Controller_Record_Abstract
             'role_id'       => $roleId,
             'account_type'  => $_account['type'],
             'account_id'    => $_account['id'],
+            'id'            => Tinebase_Record_Abstract::generateUID(),
         );
         
         try {
index b09ce98..a08c1a4 100644 (file)
  */
 class Tinebase_Role extends Tinebase_Acl_Roles
 {
+    /**
+     * holds the _instance of the singleton
+     *
+     * @var Tinebase_Role
+     */
+    private static $_instance = NULL;
+
+    /**
+     * the singleton pattern
+     *
+     * @return Tinebase_Acl_Roles
+     */
+    public static function getInstance()
+    {
+        if (self::$_instance === NULL) {
+            self::$_instance = new Tinebase_Role;
+        }
+
+        return self::$_instance;
+    }
+
+    /**
+     * update one record
+     *
+     * @param   Tinebase_Record_Interface $_record
+     * @param   boolean $_duplicateCheck
+     * @return  Tinebase_Record_Interface
+     * @throws  Tinebase_Exception_AccessDenied
+     *
+     * @todo    fix duplicate check on update / merge needs to remove the changed record / ux discussion
+     */
+    public function update(Tinebase_Record_Interface $_record, $_duplicateCheck = TRUE)
+    {
+        /** @var Tinebase_Record_RecordSet $members */
+        $members = $_record->members;
+        $_record->members = null;
+        /** @var Tinebase_Record_RecordSet $rights */
+        $rights = $_record->rights;
+        $_record->rights = null;
+
+        $return = parent::update($_record, $_duplicateCheck);
+
+        if (null !== $members) {
+            $tmpMembers = $members->toArray();
+            foreach($tmpMembers as &$m) {
+                $m['dataId'] = $m['id'];
+                $m['type'] = $m['account_type'];
+                $m['id'] = $m['account_id'];
+            }
+            $this->setRoleMembers($_record->getId(), $tmpMembers, true);
+        }
+        if (null !== $rights) {
+            $this->setRoleRights($_record->getId(), $rights->toArray());
+        }
+        $this->resetClassCache();
+
+        $return->members = $members;
+        $return->rights = $rights;
+
+        return $return;
+    }
 }
\ No newline at end of file
index 007692c..339d13a 100644 (file)
@@ -1111,4 +1111,22 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
 
         $this->setApplicationVersion('Tinebase', '10.26');
     }
+
+    /**
+     * update to 10.27
+     *
+     * change role_accounts id to uuid
+     */
+    public function update_26()
+    {
+        $declaration = new Setup_Backend_Schema_Field_Xml('<field>
+                    <name>id</name>
+                    <type>text</type>
+                    <length>40</length>
+                </field>');
+        $this->_backend->alterCol('role_accounts', $declaration);
+
+        $this->setTableVersion('role_accounts', 4);
+        $this->setApplicationVersion('Tinebase', '10.27');
+    }
 }
index be6e854..a2f94c0 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Tinebase</name>
-    <version>10.26</version>
+    <version>10.27</version>
     <tables>
         <table>
             <name>applications</name>
 
         <table>
             <name>role_accounts</name>
-            <version>3</version>
+            <version>4</version>
             <declaration>
                 <field>
                     <name>id</name>
-                    <type>integer</type>
-                    <autoincrement>true</autoincrement>
+                    <type>text</type>
+                    <length>40</length>
                 </field>
                 <field>
                     <name>role_id</name>