0011872: add imported members to default group
authorsstamer <s.stamer@metaways.de>
Fri, 13 May 2016 10:40:14 +0000 (12:40 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 19 May 2016 10:32:47 +0000 (12:32 +0200)
https://forge.tine20.org/view.php?id=11872

Change-Id: I463b740103db13590456369025abe1f21d6d859e
Reviewed-on: http://gerrit.tine20.com/customers/3157
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Courses/JsonTest.php
tine20/Courses/Controller/Course.php

index dc8fb7e..a4c0ee6 100644 (file)
@@ -262,6 +262,11 @@ class Courses_JsonTest extends TestCase
         $this->assertEquals('lahmph', $user->accountLoginName);
         $this->assertEquals('lahmph@' . $maildomain, $user->accountEmailAddress);
         $this->assertEquals('//base/school/' . $result['name'] . '/' . $user->accountLoginName, $user->accountHomeDirectory);
+        $defaultGroupMembers = Tinebase_Group::getInstance()->getGroupMembers(
+            Tinebase_Group::getInstance()->getDefaultGroup()->getId()
+        );
+        $this->assertTrue(in_array($user->getId(), $defaultGroupMembers),
+            'user not added to default user group. memberships: ' . print_r($defaultGroupMembers, true));
     }
     
     /**
@@ -315,7 +320,7 @@ class Courses_JsonTest extends TestCase
         $this->assertTrue($userId !== NULL);
         
         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
-        $this->assertEquals(3, count($groupMemberships), 'new user should have 3 group memberships');
+        $this->assertEquals(4, count($groupMemberships), 'new user should have 4 group memberships');
         $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), $userId . ' not member of the internet group ' . print_r($groupMemberships, TRUE));
         
         $user = Tinebase_User::getInstance()->getFullUserById($userId);
index f11b406..b21d462 100644 (file)
@@ -443,7 +443,23 @@ class Courses_Controller_Course extends Tinebase_Controller_Record_Abstract
             }
         }
     }
-    
+
+    /**
+     * add user ids to default user group
+     *
+     * @param array $userIds
+     */
+    protected function _addToUserDefaultGroup($userIds)
+    {
+        $defaultGroup = Tinebase_Group::getInstance()->getDefaultGroup();
+        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+            . ' Adding ' . print_r($userIds, TRUE) . ' to default group (id ' . $defaultGroup->getId() . ')');
+
+        foreach ($userIds as $id) {
+            $this->_groupController->addGroupMember($defaultGroup->getId(), $id);
+        }
+    }
+
     /**
     * import course members
     *
@@ -474,6 +490,7 @@ class Courses_Controller_Course extends Tinebase_Controller_Record_Abstract
         $groupMembers = $this->_groupController->getGroupMembers($course->group_id);
         $this->_manageAccessGroups($groupMembers, $course);
         $this->_addToStudentGroup($groupMembers);
+        $this->_addToUserDefaultGroup($groupMembers);
         
         return $result;
     }