/** * the constructor * * don't use the constructor. use the singleton */ private function __construct() { $this->_backend = new Courses_Backend_Course(); $this->_config = Courses_Config::getInstance(); $this->_groupController = Admin_Controller_Group::getInstance(); $this->_userController = Admin_Controller_User::getInstance(); }
/** * create group lists */ protected function _initializeGroupLists() { foreach (Tinebase_Group::getInstance()->getGroups() as $group) { $group->members = Tinebase_Group::getInstance()->getGroupMembers($group); $group->container_id = $this->_getInternalAddressbook()->getId(); $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED; $list = Admin_Controller_Group::getInstance()->createOrUpdateList($group); $group->list_id = $list->getId(); Tinebase_Group::getInstance()->updateGroup($group); } }
/** * returns task prepared for json transport * * @param Tinebase_Record_Interface $_record * @return array record data */ protected function _recordToJson($_record) { $recordArray = parent::_recordToJson($_record); // group data $groupData = Admin_Controller_Group::getInstance()->get($_record->group_id)->toArray(); unset($groupData['id']); $groupData['members'] = $this->_getCourseMembers($_record->group_id); // course type $recordArray['type'] = array('value' => $recordArray['type'], 'records' => $this->searchCourseTypes(NULL, NULL)); return array_merge($groupData, $recordArray); }
/** * iterate adb lists * * @param Tinebase_Record_RecordSet $records */ public function iterateAddressbookLists(Tinebase_Record_RecordSet $records) { $addContactController = Addressbook_Controller_Contact::getInstance(); $admGroupController = Admin_Controller_Group::getInstance(); $admUserController = Admin_Controller_User::getInstance(); $userContactIds = array(); foreach ($records as $list) { if ($list->type == 'group') { echo "Skipping list " . $list->name . "\n"; } /** * @var Addressbook_Model_List $list */ if (!empty($list->group_id)) { continue; } $group = new Tinebase_Model_Group(array('container_id' => $list->container_id, 'list_id' => $list->getId(), 'name' => $list->name, 'description' => $list->description, 'email' => $list->email)); $allMembers = array(); $members = $addContactController->getMultiple($list->members); foreach ($members as $member) { if ($member->type == Addressbook_Model_Contact::CONTACTTYPE_CONTACT && !in_array($member->getId(), $userContactIds)) { $pwd = Tinebase_Record_Abstract::generateUID(); $user = new Tinebase_Model_FullUser(array('accountPrimaryGroup' => Tinebase_Group::getInstance()->getDefaultGroup()->getId(), 'contact_id' => $member->getId(), 'accountDisplayName' => $member->n_fileas ? $member->n_fileas : $member->n_fn, 'accountLastName' => $member->n_family ? $member->n_family : $member->n_fn, 'accountFullName' => $member->n_fn, 'accountFirstName' => $member->n_given ? $member->n_given : '', 'accountEmailAddress' => $member->email), true); $user->accountLoginName = Tinebase_User::getInstance()->generateUserName($user); echo 'Creating user ' . $user->accountLoginName . "...\n"; $user = $admUserController->create($user, $pwd, $pwd); $member->account_id = $user->getId(); $userContactIds[] = $member->getId(); } $allMembers[] = $member->account_id; } $group->members = $allMembers; echo 'Creating group ' . $group->name . "...\n"; try { $admGroupController->create($group); } catch (Exception $e) { echo $e->getMessage() . "\n"; } } }
/** * import single record (create password if in data) * * @param Tinebase_Record_Abstract $_record * @param string $_resolveStrategy * @param array $_recordData * @return Tinebase_Record_Interface * @throws Tinebase_Exception_Record_Validation */ protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array()) { $admCfg = Tinebase_Core::getConfig()->get('Admin'); $excludeGroups = array(); $be = new Tinebase_Group_Sql(); $members = explode(' ', $_record->members); $_record->members = null; unset($_record->members); $this->_setController(); try { $group = $be->getGroupByName($_record->name); } catch (Tinebase_Exception_Record_NotDefined $e) { $group = NULL; parent::_importRecord($_record, $_resolveStrategy, $_recordData); } if ($group) { $this->_handleGroupMemberShip($group, $members); } else { $group = Admin_Controller_Group::getInstance()->get($_record->getId()); $list = Addressbook_Controller_List::getInstance()->createByGroup($group); $group->list_id = $list->getId(); $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED; $be->updateGroupInSqlBackend($group); $memberUids = array(); if (!empty($members)) { $users = $this->_resolveUsers($members); foreach ($users as $userId) { try { $be->addGroupMember($_record->getId(), $userId); } catch (Exception $e) { } } } } return $group; }
/** * try to delete a group * */ public function testDeleteGroups() { $groups = Admin_Controller_Group::getInstance()->search($this->objects['initialGroup']->name); Admin_Controller_Group::getInstance()->delete($groups->getArrayOfIds()); $this->setExpectedException('Tinebase_Exception_Record_NotDefined'); $group = Admin_Controller_Group::getInstance()->get($groups[0]->getId()); }
public function testAttendeeGroupMembersChange() { $defaultAdminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup(); // create event and invite admin group $event = $this->_getEvent(); // only events in future will be changed! $event->dtstart = Tinebase_DateTime::now()->addHour(1); $event->dtend = Tinebase_DateTime::now()->addHour(2); $event->attendee = $this->_getAttendee(); $event->attendee[1] = new Calendar_Model_Attender(array('user_id' => $defaultAdminGroup->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_GROUP, 'role' => Calendar_Model_Attender::ROLE_REQUIRED)); $persistentEvent = $this->_controller->create($event); // assert test condition $pwulf = $persistentEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $this->_personasContacts['pwulf']->getId()); $this->assertEquals(0, count($pwulf), 'invalid test condition, pwulf should not be member or admin group'); Admin_Controller_Group::getInstance()->addGroupMember($defaultAdminGroup->getId(), $this->_personasContacts['pwulf']->account_id); $loadedEvent = $this->_controller->get($persistentEvent->getId()); // assert pwulf is in $pwulf = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $this->_personasContacts['pwulf']->getId()); $this->assertEquals(1, count($pwulf), 'pwulf is not attender of event, but should be'); Admin_Controller_Group::getInstance()->removeGroupMember($defaultAdminGroup->getId(), $this->_personasContacts['pwulf']->account_id); $loadedEvent = $this->_controller->get($persistentEvent->getId()); // assert pwulf is missing $pwulf = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $this->_personasContacts['pwulf']->getId()); $this->assertEquals(0, count($pwulf), 'pwulf is attender of event, but not should be'); // Test the same with update $group = Admin_Controller_Group::getInstance()->get($defaultAdminGroup->getId()); $group->members = array_merge(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(array_value('pwulf', Zend_Registry::get('personas'))->getId())); Admin_Controller_Group::getInstance()->update($group); // assert pwulf is in $loadedEvent = $this->_controller->get($persistentEvent->getId()); $pwulf = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $this->_personasContacts['pwulf']->getId()); $this->assertEquals(1, count($pwulf), 'pwulf is not attender of event, but should be (via update)'); $group->members = array_diff(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(array_value('pwulf', Zend_Registry::get('personas'))->getId())); Admin_Controller_Group::getInstance()->update($group); // assert pwulf is missing $loadedEvent = $this->_controller->get($persistentEvent->getId()); $pwulf = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $this->_personasContacts['pwulf']->getId()); $this->assertEquals(0, count($pwulf), 'pwulf is attender of event, but not should be'); }
/** * import file * * @param string $_filename * @param Tinebase_Model_ImportExportDefinition $_definition * @param boolean $_useJsonImportFn * @param boolean $removeGroupList * @return array course data */ protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE, $removeGroupList = FALSE) { $definition = $_definition !== NULL ? $_definition : $this->_getCourseImportDefinition(); $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); if ($removeGroupList) { $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']); Addressbook_Controller_List::getInstance()->delete($group->list_id); } if ($_useJsonImportFn) { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile($_filename); Courses_Config::getInstance()->set(Courses_Config::STUDENTS_IMPORT_DEFINITION, $definition->name); $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']); $this->assertGreaterThan(0, $result['results']); } else { $maildomain = TestServer::getPrimaryMailDomain(); $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array('group_id' => $courseData['group_id'], 'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/', 'accountEmailDomain' => $maildomain, 'password' => $courseData['name'], 'samba' => array('homePath' => '//basehome/', 'homeDrive' => 'H:', 'logonScript' => 'logon.bat', 'profilePath' => '\\\\profile\\'))); $tempFilename = TestServer::replaceEmailDomainInFile($_filename); $importer->importFile($tempFilename); } $courseData = $this->_json->getCourse($courseData['id']); return $courseData; }
/** * testUpdateUserRemovedPrimaryGroup * * @see 0006710: save user fails if primary group no longer exists */ public function testUpdateUserRemovedPrimaryGroup() { $this->testAddGroup(); $accountData = $this->objects['user']->toArray(); $accountData['accountPrimaryGroup'] = Tinebase_Group::getInstance()->getGroupByName('tine20phpunit')->getId(); Admin_Controller_Group::getInstance()->delete(array($accountData['accountPrimaryGroup'])); $savedAccount = $this->_createUser($accountData); $this->assertEquals(Tinebase_Group::getInstance()->getDefaultGroup()->getId(), $savedAccount['accountPrimaryGroup']['id']); }
/** * delete accounts * * @param mixed $_accountIds array of account ids * @return array with success flag * @throws Tinebase_Exception_Record_NotAllowed */ public function delete($_accountIds) { $this->checkRight('MANAGE_ACCOUNTS'); $groupsController = Admin_Controller_Group::getInstance(); foreach ((array) $_accountIds as $accountId) { if ($accountId === Tinebase_Core::getUser()->getId()) { $message = 'You are not allowed to delete yourself!'; Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $message); throw new Tinebase_Exception_AccessDenied($message); } Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " about to remove user with id: {$accountId}"); $oldUser = $this->get($accountId); $memberships = $groupsController->getGroupMemberships($accountId); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " removing user from groups: " . print_r($memberships, true)); } foreach ((array) $memberships as $groupId) { $groupsController->removeGroupMember($groupId, $accountId); } if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true && !empty($oldUser->contact_id)) { $this->_deleteContact($oldUser->contact_id); } $this->_userBackend->deleteUser($accountId); } }
/** * delete multiple groups * * @param array $groupIds list of contactId's to delete * @return array with success flag */ public function deleteGroups($groupIds) { $result = array('success' => TRUE); Admin_Controller_Group::getInstance()->delete($groupIds); return $result; }
/** * testHiddenMembers * * @see 0007122: hide hidden users from lists */ public function testHiddenMembers() { $group = new Tinebase_Model_Group(array('name' => 'testgroup', 'description' => 'test group', 'visibility' => Tinebase_Model_Group::VISIBILITY_DISPLAYED)); $group = Admin_Controller_Group::getInstance()->create($group); $this->_groupIdsToDelete[] = $group->getId(); $list = $this->_instance->get($group->list_id); $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever'); $list->members = array($sclever->contact_id); $list = $this->_instance->update($list); // hide sclever $sclever->visibility = Tinebase_Model_User::VISIBILITY_HIDDEN; Admin_Controller_User::getInstance()->update($sclever, NULL, NULL); // fetch list and check hidden members $listGet = $this->_instance->get($list->getId()); $listSearch = $this->_instance->search(new Addressbook_Model_ListFilter(array(array('field' => 'id', 'operator' => 'in', 'value' => array($list->getId())))))->getFirstRecord(); $listGetMultiple = $this->_instance->getMultiple(array($list->getId()))->getFirstRecord(); foreach (array('get' => $listGet, 'search' => $listSearch, 'getMultiple' => $listGetMultiple) as $fn => $listRecord) { $this->assertTrue($listRecord instanceof Addressbook_Model_List, $fn . ' did not return a list: ' . var_export($listRecord, TRUE)); $this->assertEquals(0, count($listRecord->members), 'Hidden sclever should not appear in list members returned by ' . $fn . '(): ' . print_r($listRecord->toArray(), TRUE)); } }
/** * Deletes a set of records. * * If one of the records could not be deleted, no record is deleted * * @param array array of record identifiers * @return void * @throws Tinebase_Exception_NotFound|Tinebase_Exception */ public function delete($_ids) { $courses = $this->getMultiple($_ids); $groupController = Admin_Controller_Group::getInstance(); $userController = Admin_Controller_User::getInstance(); $groupsToDelete = array(); $usersToDelete = array(); foreach ($courses as $course) { $groupsToDelete[] = $course->group_id; $usersToDelete = array_merge($usersToDelete, $groupController->getGroupMembers($course->group_id)); } Courses_Controller::getInstance()->suspendEvents(); $userController->delete(array_unique($usersToDelete)); $groupController->delete(array_unique($groupsToDelete)); Courses_Controller::getInstance()->resumeEvents(); parent::delete($_ids); }
/** * test filter with hidden group -> should return empty result * * @see 0006934: setting a group that is hidden from adb as attendee filter throws exception */ public function testHiddenGroupFilter() { $hiddenGroup = new Tinebase_Model_Group(array('name' => 'hiddengroup', 'description' => 'hidden group', 'visibility' => Tinebase_Model_Group::VISIBILITY_HIDDEN)); $hiddenGroup = Admin_Controller_Group::getInstance()->create($hiddenGroup); $this->_groupIdsToDelete[] = $hiddenGroup->getId(); $filter = array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_id' => $hiddenGroup->list_id, 'user_type' => 'group'))); $result = $this->_uit->searchEvents($filter, array()); $this->assertEquals(0, $result['totalcount']); }
/** * test search hidden list -> should not appear * * @see 0006934: setting a group that is hidden from adb as attendee filter throws exception */ public function testSearchHiddenList() { $hiddenGroup = new Tinebase_Model_Group(array('name' => 'hiddengroup', 'description' => 'hidden group', 'visibility' => Tinebase_Model_Group::VISIBILITY_HIDDEN)); try { $hiddenGroup = Admin_Controller_Group::getInstance()->create($hiddenGroup); } catch (Exception $e) { // group already exists $hiddenGroup = Tinebase_Group::getInstance()->getGroupByName($hiddenGroup->name); } $this->_groupIdsToDelete = array($hiddenGroup->getId()); $filter = array(array('field' => 'name', 'operator' => 'equals', 'value' => 'hiddengroup')); $result = $this->_uit->searchLists($filter, array()); $this->assertEquals(0, $result['totalcount'], 'should not find hidden list: ' . print_r($result, TRUE)); }
/** * inspect update of one record * * @param Tinebase_Record_Interface $_record the update record * @param Tinebase_Record_Interface $_oldRecord the current persistent record * @return void */ protected function _inspectBeforeUpdate($_record, $_oldRecord) { if (!empty($_record->group_id)) { // first check if something changed that requires special rights $changeGroup = false; foreach (Addressbook_Model_List::getManageAccountFields() as $field) { if ($_record->{$field} != $_oldRecord->{$field}) { $changeGroup = true; break; } } // then do the update, the group controller will check manage accounts right if ($changeGroup) { $groupController = Admin_Controller_Group::getInstance(); $group = $groupController->get($_record->group_id); foreach (Addressbook_Model_List::getManageAccountFields() as $field) { $group->{$field} = $_record->{$field}; } $groupController->update($group, false); } } }
/** * import course members * * @param string $tempFileId * @param string $groupId * @param string $courseName * * @todo write test!! */ public function importMembers($tempFileId, $groupId, $courseId) { $tempFile = Tinebase_TempFile::getInstance()->getTempFile($tempFileId); $course = $this->_controller->get($courseId); $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name); // get definition and start import with admin user import csv plugin $definitionName = $this->_config->get('import_definition', 'admin_user_import_csv'); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using import definition: ' . $definitionName); } $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($definitionName); $importer = Admin_Import_Csv::createFromDefinition($definition, array('group_id' => $groupId, 'accountEmailDomain' => isset($this->_config->domain) ? $this->_config->domain : '', 'accountHomeDirectoryPrefix' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $course->name . '/' : '', 'password' => strtolower($course->name), 'course' => $course, 'samba' => isset($this->_config->samba) ? array('homePath' => $this->_config->samba->basehomepath, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $course->name . $this->_config->samba->logonscript_postfix_member, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $course->name . '\\', 'pwdCanChange' => new Tinebase_DateTime('@1'), 'pwdMustChange' => new Tinebase_DateTime('@1')) : array())); $importer->importFile($tempFile->path); // return members to update members grid and add to student group $members = $this->_getCourseMembers($groupId); // add to student group if available if (isset($this->_config->students_group) && !empty($this->_config->students_group)) { $groupController = Admin_Controller_Group::getInstance(); foreach ($members as $member) { $groupController->addGroupMember($this->_config->students_group, $member['id']); } } return array('results' => $members, 'status' => 'success'); }