コード例 #1
0
ファイル: Group.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * the singleton pattern
  *
  * @return Admin_Controller_Group
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Admin_Controller_Group();
     }
     return self::$_instance;
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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);
     }
 }
コード例 #4
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * update fileserver/internet access
  *
  * @param  array   $ids
  * @param  string  $type
  * @param  boolean $access
  * @return array
  */
 public function updateAccess($ids, $type, $access)
 {
     $result = FALSE;
     $allowedTypes = array('internet', 'fileserver');
     if (in_array($type, $allowedTypes)) {
         foreach ($ids as $courseId) {
             $course = $this->_controller->get($courseId);
             $members = $this->_groupController->getGroupMembers($course->group_id);
             // update course and groups
             $this->_manageAccessGroups($members, $access, $type);
             $course->{$type} = $access;
             $course = $this->_controller->update($course);
         }
         $result = TRUE;
     }
     return array('status' => $result ? 'success' : 'failure');
 }
コード例 #5
0
 /**
  * add new member to course
  * 
  * @param Courses_Model_Course $course
  * @param Tinebase_Model_FullUser $user
  * @return Tinebase_Model_FullUser
  * 
  * @todo use importMembers() here to avoid duplication
  */
 public function createNewMember(Courses_Model_Course $course, Tinebase_Model_FullUser $user)
 {
     $this->checkRight(Courses_Acl_Rights::ADD_NEW_USER);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new member for ' . $course->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($course->toArray(), TRUE));
     }
     $password = $user->applyOptionsAndGeneratePassword($this->_getNewUserConfig($course));
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($user->toArray(), TRUE));
     }
     $newMember = $this->_userController->create($user, $password, $password);
     // add to default group and manage access group for user
     $this->_groupController->addGroupMember(Tinebase_Group::getInstance()->getDefaultGroup()->getId(), $newMember->getId());
     $this->_manageAccessGroups(array($newMember->getId()), $course);
     $this->_addToStudentGroup(array($newMember->getId()));
     return $newMember;
 }
コード例 #6
0
 /**
  * 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";
         }
     }
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 /**
  * 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);
         }
     }
 }
コード例 #9
0
 /**
  * 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));
 }
コード例 #10
0
 /**
  * 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());
 }
コード例 #11
0
 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');
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * 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']);
 }
コード例 #14
0
 /**
  * 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);
     }
 }
コード例 #15
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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;
 }
コード例 #16
0
 /**
  * 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']);
 }
コード例 #17
0
ファイル: Course.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }
コード例 #18
0
 /**
  * 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));
     }
 }