Merge branch 'pu/2013.10-ldap' into 2013.10
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 17 Jul 2014 16:09:23 +0000 (18:09 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 17 Jul 2014 16:09:23 +0000 (18:09 +0200)
12 files changed:
tests/tine20/Addressbook/ControllerTest.php
tests/tine20/Admin/CliTest.php
tests/tine20/Admin/files/test_teacher.csv
tests/tine20/Felamimail/Controller/MessageTest.php
tine20/Admin/Import/Csv.php
tine20/Admin/Import/definitions/admin_user_import_csv_advanced.xml [new file with mode: 0644]
tine20/Admin/Setup/Update/Release8.php
tine20/Admin/Setup/setup.xml
tine20/Felamimail/Controller/Message.php
tine20/Felamimail/Model/Message.php
tine20/Tinebase/Controller/Record/Abstract.php
tine20/Tinebase/Model/FullUser.php

index 61138fd..dfa0c06 100644 (file)
@@ -171,6 +171,7 @@ class Addressbook_ControllerTest extends PHPUnit_Framework_TestCase
     {
         Addressbook_Controller_Contact::getInstance()->setGeoDataForContacts($this->_geodata);
         
+        $this->_instance->useNotes(true);
         if ((isset($this->objects['contact']) || array_key_exists('contact', $this->objects))) {
             $this->_instance->delete($this->objects['contact']);
         }
@@ -425,4 +426,40 @@ class Addressbook_ControllerTest extends PHPUnit_Framework_TestCase
         $count2 = $this->_instance->searchCount($filter);
         $this->assertEquals($count1, $count2);
     }
+    
+    /**
+     * test useNotes
+     */
+    public function testUseNotes()
+    {
+        $contact = $this->objects['initialContact'];
+        $contact1 = clone $contact;
+    
+        $contact1->notes = array(new Tinebase_Record_RecordSet('Tinebase_Model_Note', array($this->objects['note'])));
+        $contact->notes = array(new Tinebase_Record_RecordSet('Tinebase_Model_Note', array($this->objects['note'])));
+    
+        $newcontact1 = $this->_instance->create($contact1);
+        $this->_instance->delete($newcontact1);
+    
+        $this->_instance->useNotes(false);
+        $this->objects['contact'] = $this->_instance->create($contact);
+    
+        $compStr = 'Array
+(
+    [0] => Array
+        (
+            [note_type_id] => 1
+            [note] => phpunit test note
+            [record_backend] => Sql
+            [id] => 
+        )
+
+)';
+        
+        $this->assertTrue($newcontact1->has('notes'));
+        $this->assertEquals($compStr, $newcontact1->notes[0]->note);
+        
+        $this->setExpectedException('Tinebase_Exception_NotFound');
+        $this->objects['contact']->notes[0]->note = 'note';
+    }
 }
index 3258625..4e10540 100644 (file)
@@ -58,9 +58,15 @@ class Admin_CliTest extends TestCase
         $this->_usernamesToDelete = array('hmaster', 'hmeister', 'hmoster', 'irmeli', 'testuser', 'm.muster');
         
         $this->_groupsToDelete = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
+        $this->_testGroup['domainuser'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
+            'name'   => 'domainuser'
+        )));
         $this->_testGroup['teacher'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
             'name'   => 'teacher'
         )));
+        $this->_testGroup['student'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
+            'name'   => 'student'
+        )));
         $this->_groupsToDelete->addRecord($this->_testGroup['teacher']);
         
         $this->objects['config'] = '<?xml version="1.0" encoding="UTF-8"?>
@@ -191,14 +197,14 @@ class Admin_CliTest extends TestCase
                 </field>
             </mapping>
         </config>';
-          $this->objects['configGroup'] = '<?xml version="1.0" encoding="UTF-8"?>
+          $this->objects['configAdvanced'] = '<?xml version="1.0" encoding="UTF-8"?>
         <config>
            <model>Tinebase_Model_FullUser</model>
            <plugin>Admin_Import_Csv</plugin>
            <type>import</type>
            <headline>1</headline>
            <dryrun>0</dryrun>
-           <delimiter>;</delimiter>
+           <delimiter>,</delimiter>
            <mapping>
                <field>
                    <source>firstname</source>
@@ -217,17 +223,41 @@ class Admin_CliTest extends TestCase
                    <destination>password</destination>
                </field>
                <field>
-                   <source>group_id</source>
+                   <source>primary_group_id</source>
                    <destination>accountPrimaryGroup</destination>
                </field>
                <field>
+                   <source>additional_groups</source>
+                   <destination>groups</destination>
+               </field>
+              <field>
                    <source>accountHomeDirectory</source>
                    <destination>accountHomeDirectory</destination>
                </field>
                <field>
+                   <source>accountHomeDirectoryPrefix</source>
+                   <destination>accountHomeDirectoryPrefix</destination>
+               </field>
+               <field>
                    <source>accountLoginShell</source>
                    <destination>accountLoginShell</destination>
                </field>
+               <field>
+                   <source>homePath</source>
+                   <destination>homePath</destination>
+               </field>
+               <field>
+                   <source>homeDrive</source>
+                   <destination>homeDrive</destination>
+               </field>
+               <field>
+                   <source>logonScript</source>
+                   <destination>logonScript</destination>
+               </field>
+               <field>
+                   <source>profilePath</source>
+                   <destination>profilePath</destination>
+               </field>
            </mapping>
         </config>';
     }
@@ -372,10 +402,12 @@ class Admin_CliTest extends TestCase
     }
     
     /**
-     * testImportUsersWithGroup
+     * testImportUsersAdvanced
      */
-    public function testImportUsersWithGroup()
+    public function testImportUsersAdvanced()
     {
+        $userBackend = Tinebase_User::getInstance();
+        
         $readFile = fopen(dirname(__FILE__) . '/files/test_teacher.csv', 'r');
         $writeFile = fopen('test2.csv', 'w');
         $delimiter = ',';
@@ -383,7 +415,9 @@ class Admin_CliTest extends TestCase
         
         while (($row = fgetcsv($readFile)) !== false) {
             foreach ($row as $colIndex => &$field) {
-                $field = str_replace('GROUP', $this->_testGroup['teacher']->getId(), $field);
+                $field = str_replace('PRIMARYGROUP', $this->_testGroup['domainuser']->getId(), $field);
+                $field = str_replace('GROUP1', $this->_testGroup['teacher']->getId(), $field);
+                $field = str_replace('GROUP2', $this->_testGroup['student']->getId(), $field);
             }
             fputcsv($writeFile, $row, $delimiter, $enclosure);
         }
@@ -391,13 +425,23 @@ class Admin_CliTest extends TestCase
         fclose($readFile);
         fclose($writeFile);
         
-        $this->_importUsers($this->objects['configGroup'], 'test2.csv', 'admin_user_import_csv_test_teacher');
+        $this->_importUsers($this->objects['configAdvanced'], 'test2.csv', 'admin_user_import_csv_test_advanced');
         $newUser = Tinebase_User::getInstance()->getFullUserByLoginName('m.muster');
+        
         $newUserMemberships = Tinebase_Group::getInstance()->getGroupMemberships($newUser);
+        $this->assertTrue(in_array($this->_testGroup['domainuser']->getId(), $newUserMemberships),
+        ' not member of the domainuser group (' . $this->_testGroup['domainuser']->getId() . ') ' . print_r($newUserMemberships, TRUE));
+        $this->assertTrue(in_array($this->_testGroup['student']->getId(), $newUserMemberships),
+        ' not member of the student group (' . $this->_testGroup['student']->getId() . ') ' . print_r($newUserMemberships, TRUE));
         $this->assertTrue(in_array($this->_testGroup['teacher']->getId(), $newUserMemberships),
-        ' not member of the test group (' . $this->_testGroup['teacher']->getId() . ') ' . print_r($newUserMemberships, TRUE));
+        ' not member of the teacher group (' . $this->_testGroup['teacher']->getId() . ') ' . print_r($newUserMemberships, TRUE));
+        
         $this->assertEquals('/bin/false', $newUser->accountLoginShell);
+        $this->assertEquals('/storage/lehrer/m.muster', $newUser->accountHomeDirectory);
         
+        if (array_key_exists('Tinebase_User_Plugin_Samba', $userBackend->getPlugins())) {
+            $this->assertEquals('\\fileserver\profiles\m.muster', $newUser->sambaSAM->profilePath);
+        }
         unlink("test2.csv");
     }
 }
index b8db165..8634de8 100644 (file)
@@ -1,2 +1,2 @@
-objectname;firstname;lastname;password;accountLoginShell;accountHomeDirectory;group_id
-m.muster;Max;Muster;foo;/bin/false;/storage/lehrer/m.muster;GROUP
+"objectname","firstname","lastname","password","accountLoginShell","accountHomeDirectory","accountHomeDirectoryPrefix","primary_group_id","additional_groups","homePath","homeDrive","logonScript","profilePath"
+"m.muster","Max","Muster","foo","/bin/false","/storage/lehrer/m.muster","/storage/lehrer/","PRIMARYGROUP","GROUP1, GROUP2","\\\\fileserver\\","U:","lehrer.cmd","\\\\fileserver\\profiles\\"
index 5c66107..bd1ff28 100644 (file)
@@ -611,8 +611,11 @@ class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
                     echo "\nchecking message: " . $fileName . "\n";
                     $cachedMessage = $this->messageTestHelper($fileName, $filename);
                     $message = $this->_controller->getCompleteMessage($cachedMessage);
-                    echo $message->body;
                     $this->assertTrue(! empty($message->body));
+                    
+                    echo "body: " . $message->body . "\n";
+                    echo "attachements: ";
+                    print_r($message->attachments);
                 }
             }
         }
index d5d7d21..b85dca6 100644 (file)
@@ -80,14 +80,19 @@ class Admin_Import_Csv extends Tinebase_Import_Csv_Abstract
             
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
                 . ' record Data' . print_r($_recordData, true));
-            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
-                . ' ' . print_r($record->toArray(), true));
             if (isset($_recordData['smtpUser'])) {
                 $record->smtpUser = new Tinebase_Model_EmailUser($_recordData['smtpUser']);
             }
             if (isset($_recordData['imapUser'])) {
                 $record->imapUser = new Tinebase_Model_EmailUser($_recordData['imapUser']);
             }
+            if (isset($_recordData['samba'])) {
+                $this->_options['samba'] = $_recordData['samba'];
+            }
+            if (isset($_recordData['accountHomeDirectoryPrefix'])) {
+                $this->_options['accountHomeDirectoryPrefix'] = $_recordData['accountHomeDirectoryPrefix'];
+            }
+            
             $password = $record->applyOptionsAndGeneratePassword($this->_options, (isset($_recordData['password'])) ? $_recordData['password'] : NULL);
             Tinebase_Event::fireEvent(new Admin_Event_BeforeImportUser($record, $this->_options));
             
@@ -106,7 +111,6 @@ class Admin_Import_Csv extends Tinebase_Import_Csv_Abstract
         } else {
             $record = parent::_importRecord($_record, $_resolveStrategy, $_recordData);
         }
-        
         return $record;
     }
     
@@ -118,6 +122,16 @@ class Admin_Import_Csv extends Tinebase_Import_Csv_Abstract
                 'emailForwards'    => isset($result['emailForwards']) && !empty($result['emailForwards']) ? explode(' ', trim($result['emailForwards'])) : array(),
                 'emailAliases'     => isset($result['emailAliases']) ? explode(' ', trim($result['emailAliases'])) : array()
                             );
+            $result['groups'] = !empty($result['groups']) ? array_map('trim',explode(",",$result['groups'])) : array();
+            
+            $result['samba'] = array(
+                'homePath'      => (isset($result['homePath'])) ? stripslashes($result['homePath']) : '',
+                'homeDrive'     => (isset($result['homeDrive'])) ? stripslashes($result['homeDrive']) : '',
+                'logonScript'   => (isset($result['logonScript'])) ? $result['logonScript'] : '',
+                'profilePath'   => (isset($result['profilePath'])) ? stripslashes($result['profilePath']) : '',
+                'pwdCanChange'  => isset($result['pwdCanChange'])  ? new Tinebase_DateTime($result['pwdCanChange']) : '',
+                'pwdMustChange' => isset($result['pwdMustChange']) ? new Tinebase_DateTime($result['pwdMustChange']) : ''
+                            );
         return $result;
     }
 }
diff --git a/tine20/Admin/Import/definitions/admin_user_import_csv_advanced.xml b/tine20/Admin/Import/definitions/admin_user_import_csv_advanced.xml
new file mode 100644 (file)
index 0000000..83a0ee3
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <config>
+       <model>Tinebase_Model_FullUser</model>
+       <plugin>Admin_Import_Csv</plugin>
+       <type>import</type>
+       <headline>1</headline>
+       <dryrun>0</dryrun>
+       <delimiter>,</delimiter>
+       <mapping>
+           <field>
+               <source>firstname</source>
+               <destination>accountFirstName</destination>
+           </field>
+           <field>
+               <source>lastname</source>
+               <destination>accountLastName</destination>
+           </field>
+           <field>
+               <source>objectname</source>
+               <destination>accountLoginName</destination>
+           </field>
+           <field>
+               <source>password</source>
+               <destination>password</destination>
+           </field>
+           <field>
+               <source>primary_group_id</source>
+               <destination>accountPrimaryGroup</destination>
+           </field>
+           <field>
+               <source>additional_groups</source>
+               <destination>groups</destination>
+           </field>
+           <field>
+               <source>accountHomeDirectory</source>
+               <destination>accountHomeDirectory</destination>
+           </field>
+           <field>
+               <source>accountHomeDirectoryPrefix</source>
+               <destination>accountHomeDirectoryPrefix</destination>
+           </field>
+           <field>
+               <source>accountLoginShell</source>
+               <destination>accountLoginShell</destination>
+           </field>
+           <field>
+               <source>homePath</source>
+               <destination>homePath</destination>
+           </field>
+           <field>
+               <source>homeDrive</source>
+               <destination>homeDrive</destination>
+           </field>
+           <field>
+               <source>logonScript</source>
+               <destination>logonScript</destination>
+           </field>
+           <field>
+               <source>profilePath</source>
+               <destination>profilePath</destination>
+           </field>
+       </mapping>
+    </config>
index c26de23..f1b6a4e 100644 (file)
@@ -20,4 +20,15 @@ class Admin_Setup_Update_Release8 extends Setup_Update_Abstract
         Setup_Controller::getInstance()->createImportExportDefinitions(Tinebase_Application::getInstance()->getApplicationByName('Admin'));
         $this->setApplicationVersion('Admin', '8.1');
     }
+    
+    /**
+     * update to 8.2
+     * 
+     * @return void
+     */
+    public function update_1()
+    {
+        Setup_Controller::getInstance()->createImportExportDefinitions(Tinebase_Application::getInstance()->getApplicationByName('Admin'));
+        $this->setApplicationVersion('Admin', '8.2');
+    }
 }
index 63fe47c..c32d6d0 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Admin</name>
-    <version>8.1</version>
+    <version>8.2</version>
     <order>1</order>
     <depends>
         <application>Tinebase</application>
index 4ad71ae..3c52108 100644 (file)
@@ -219,21 +219,21 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
         } else {
             // create new object for rfc822 message
             $structure = $_message->getPartStructure($_partId, FALSE);
-        
+            
             $message = new Felamimail_Model_Message(array(
                 'messageuid'  => $_message->messageuid,
                 'folder_id'   => $_message->folder_id,
                 'received'    => $_message->received,
-                'size'        => ((isset($structure['size']) || array_key_exists('size', $structure))) ? $structure['size'] : 0,
+                'size'        => isset($structure['size']) ? $structure['size'] : 0,
                 'partid'      => $_partId,
                 'body'        => $body,
                 'headers'     => $headers,
                 'attachments' => $attachments
             ));
-        
+            
             $message->parseHeaders($headers);
-        
-            $structure = (isset($structure['messageStructure']) || array_key_exists('messageStructure', $structure)) ? $structure['messageStructure'] : $structure;
+            
+            $structure = isset($structure['messageStructure']) ? $structure['messageStructure'] : $structure;
             $message->parseStructure($structure);
         }
         
@@ -833,10 +833,10 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
         }
         
         $structure = $message->getPartStructure($_partId);
-
+        
         $attachments = array();
         
-        if (!(isset($structure['parts']) || array_key_exists('parts', $structure))) {
+        if (! isset($structure['parts'])) {
             return $attachments;
         }
         
@@ -894,6 +894,9 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
             $filename = $part['parameters']['name'];
         } else {
             $filename = 'Part ' . $part['partId'];
+            if (isset($part['contentType'])) {
+                $filename .= ' (' . $part['contentType'] . ')';
+            }
         }
         
         return $filename;
index fed5375..7b285d4 100644 (file)
@@ -228,6 +228,12 @@ class Felamimail_Model_Message extends Tinebase_Record_Abstract
      */
     protected function _setStructure($structure)
     {
+        if (! empty($structure['partId'])) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
+                . ' Don\'t cache structure of subparts');
+            return;
+        }
+        
         $cacheId = $this->_getStructureCacheId();
         
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Caching message structure: ' . $cacheId);
index 3cb2608..42c747a 100644 (file)
@@ -54,6 +54,13 @@ abstract class Tinebase_Controller_Record_Abstract
     protected $_doRightChecks = TRUE;
 
     /**
+     * use notes - can be enabled/disabled by useNotes
+     *
+     * @var boolean
+     */
+    protected $_setNotes = TRUE;
+
+    /**
      * delete or just set is_delete=1 if record is going to be deleted
      * - legacy code -> remove that when all backends/applications are using the history logging
      *
@@ -955,7 +962,7 @@ abstract class Tinebase_Controller_Record_Abstract
      */
     protected function _setNotes($_updatedRecord, $_record, $_systemNoteType = Tinebase_Model_Note::SYSTEM_NOTE_NAME_CREATED, $_currentMods = NULL)
     {
-        if (! $_record->has('notes')) {
+        if (! $_record->has('notes') || $this->_setNotes === false) {
             return;
         }
 
@@ -1141,6 +1148,18 @@ abstract class Tinebase_Controller_Record_Abstract
     }
     
     /**
+     * enable / disable notes
+     *
+     * @param boolean $_value
+     * @return void
+     */
+    public function useNotes()
+    {
+        $value = (func_num_args() === 1) ? (bool) func_get_arg(0) : NULL;
+        return $this->_setBooleanMemberVar('_setNotes', $value);
+    }
+    
+    /**
      * iterate relations
      * 
      * @param Tinebase_Record_Abstract $currentRecord
index febcff6..d6c9d4f 100644 (file)
@@ -94,7 +94,7 @@ class Tinebase_Model_FullUser extends Tinebase_Model_User
             $this->accountLoginName = Tinebase_User::getInstance()->generateUserName($this, (isset($options['userNameSchema'])) ? $options['userNameSchema'] : 1);
         }
         
-        if (! isset($this->accountPrimaryGroup)) {
+        if (empty($this->accountPrimaryGroup)) {
             if (! empty($options['group_id'])) {
                 $groupId = $options['group_id'];
             } else {