/** * returns record prepared for json transport * * @param Tinebase_Record_Interface $_record * @return array record data */ protected function _recordToJson($_record) { switch (get_class($_record)) { case 'Timetracker_Model_Timesheet': $_record['timeaccount_id'] = $_record['timeaccount_id'] ? $this->_timeaccountController->get($_record['timeaccount_id']) : $_record['timeaccount_id']; $_record['timeaccount_id']['account_grants'] = Timetracker_Model_TimeaccountGrants::getGrantsOfAccount(Tinebase_Core::get('currentAccount'), $_record['timeaccount_id']); $_record['timeaccount_id']['account_grants'] = $this->_resolveTimesheetGrantsByTimeaccountGrants($_record['timeaccount_id']['account_grants'], $_record['account_id']); Tinebase_User::getInstance()->resolveUsers($_record, 'account_id'); $recordArray = parent::_recordToJson($_record); break; case 'Timetracker_Model_Timeaccount': $recordArray = parent::_recordToJson($_record); // When editing a single TA we send _ALL_ grants to the client $recordArray['grants'] = Timetracker_Model_TimeaccountGrants::getTimeaccountGrants($_record)->toArray(); foreach ($recordArray['grants'] as &$value) { switch ($value['account_type']) { case Tinebase_Acl_Rights::ACCOUNT_TYPE_USER: $value['account_name'] = Tinebase_User::getInstance()->getUserById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP: $value['account_name'] = Tinebase_Group::getInstance()->getGroupById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE: $value['account_name'] = array('accountDisplayName' => 'Anyone'); break; default: throw new Tinebase_Exception_InvalidArgument('Unsupported accountType.'); break; } } break; } return $recordArray; }
/** * returns array with the filter settings of this filter * * @param bool $_valueToJson resolve value for json api? * @return array */ public function toArray($_valueToJson = false) { $result = parent::toArray($_valueToJson); if ($this->_userOperator && $this->_userOperator == 'inGroup') { $result['operator'] = $this->_userOperator; $result['value'] = $this->_userValue; } else { if ($this->_userValue === Tinebase_Model_User::CURRENTACCOUNT) { // switch back to CURRENTACCOUNT to make sure filter is saved and shown in client correctly $result['value'] = $this->_userValue; } } if ($_valueToJson == true) { if ($this->_userOperator && $this->_userOperator == 'inGroup' && $this->_userValue) { $result['value'] = Tinebase_Group::getInstance()->getGroupById($this->_userValue)->toArray(); } else { switch ($this->_operator) { case 'equals': $result['value'] = $result['value'] ? Tinebase_User::getInstance()->getUserById($this->_value)->toArray() : $result['value']; break; case 'in': $result['value'] = array(); foreach ($this->_value as $userId) { $result['value'][] = Tinebase_User::getInstance()->getUserById($userId)->toArray(); } break; default: break; } } } return $result; }
/** * @return void */ public function testEmailsToAttendeeWithGroups() { if (Tinebase_User::getConfiguredBackend() === Tinebase_User::LDAP || Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) { $this->markTestSkipped('FIXME: Does not work with LDAP/AD backend'); } $event = $this->_getEvent(); $persistentEvent = Calendar_Controller_Event::getInstance()->create($event); $primaryGroup = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup); $newAttendees = array(array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'firstName' => $this->_originalTestUser->accountFirstName, 'lastName' => $this->_originalTestUser->accountLastName, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $this->_originalTestUser->accountEmailAddress), array('userType' => Calendar_Model_Attender::USERTYPE_GROUP, 'displayName' => $primaryGroup->name, 'partStat' => Calendar_Model_Attender::STATUS_NEEDSACTION, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => '*****@*****.**')); Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE); $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent); $attendees = clone $persistentEvent->attendee; Calendar_Model_Attender::resolveAttendee($attendees); $newAttendees = array(); foreach ($attendees as $attendee) { $newAttendees[] = array('userType' => $attendee->user_type == 'group' ? Calendar_Model_Attender::USERTYPE_GROUP : Calendar_Model_Attender::USERTYPE_USER, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $attendee->user_type == 'group' ? $attendee->user_id->getId() : $attendee->user_id->email, 'displayName' => $attendee->user_type == 'group' ? $attendee->user_id->name : $attendee->user_id->n_fileas); } Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE); $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent); // print_r($persistentEvent->attendee->toArray()); // there must be more than 2 attendees the user, the group + the groupmembers $this->assertGreaterThan(2, count($persistentEvent->attendee)); // current account must not be a groupmember $this->assertFalse(!!Calendar_Model_Attender::getAttendee($persistentEvent->attendee, new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $this->_originalTestUser->contact_id))), 'found user as groupmember'); $this->assertEquals(Calendar_Model_Attender::STATUS_TENTATIVE, Calendar_Model_Attender::getOwnAttender($persistentEvent->attendee)->status); }
/** * returns multiple records prepared for json transport * * @param Tinebase_Record_RecordSet $_records * @param Tinebase_Model_Filter_FilterGroup $_filter * @param Tinebase_Model_Pagination $_pagination * * @return array data */ protected function _multipleRecordsToJson(Tinebase_Record_RecordSet $_records, $_filter = NULL, $_pagination = NULL) { $result = parent::_multipleRecordsToJson($_records, $_filter, $_pagination); // get groups + types (departments) and merge data $groupIds = $_records->group_id; $groups = Tinebase_Group::getInstance()->getMultiple(array_unique(array_values($groupIds))); $knownTypes = Tinebase_Department::getInstance()->search(new Tinebase_Model_DepartmentFilter()); foreach ($result as &$course) { $groupIdx = $groups->getIndexById($course['group_id']); if ($groupIdx !== FALSE) { $group = $groups[$groupIdx]->toArray(); unset($group['id']); $course = array_merge($group, $course); } else { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Group with ID ' . $course['group_id'] . ' does not exist.'); } } $typeIdx = $knownTypes->getIndexById($course['type']); if ($typeIdx !== FALSE) { //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($knownTypes[$typeIdx]->toArray(), true)); $course['type'] = $knownTypes[$typeIdx]->toArray(); } else { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Department with ID ' . $course['type'] . ' does not exist.'); } $course['type'] = array('id' => $course['type'], 'name' => $course['type']); } } return $result; }
/** * set all courses to internet = FILTERED * * @return integer */ public function resetCoursesInternetAccess() { if (!$this->_checkAdminRight()) { return 2; } $config = Courses_Config::getInstance(); if (!isset($config->{Courses_Config::INTERNET_ACCESS_GROUP_ON}) || !isset($config->{Courses_Config::INTERNET_ACCESS_GROUP_FILTERED})) { echo "No internet groups defined in config. Exiting\n"; return 2; } $filter = new Courses_Model_CourseFilter(array(array('field' => 'internet', 'operator' => 'not', 'value' => 'FILTERED'))); $count = 0; foreach (Courses_Controller_Course::getInstance()->search($filter) as $course) { $course->internet = 'FILTERED'; $group = Tinebase_Group::getInstance()->getGroupById($course->group_id); $group->members = Tinebase_Group::getInstance()->getGroupMembers($group); try { Courses_Controller_Course::getInstance()->saveCourseAndGroup($course, $group); $count++; } catch (Exception $e) { echo 'Failed to update course: ' . $course->name . PHP_EOL; echo $e . PHP_EOL; } } echo "Updated " . $count . " Course(s)\n"; return 0; }
/** * returns array with the filter settings of this filter * * @param bool $_valueToJson resolve value for json api? * @return array */ public function toArray($_valueToJson = false) { $result = parent::toArray($_valueToJson); if ($this->_userOperator && $this->_userOperator == 'inGroup') { $result['operator'] = $this->_userOperator; $result['value'] = $this->_userValue; } if ($_valueToJson == true) { if ($this->_userOperator && $this->_userOperator == 'inGroup' && $this->_userValue) { $result['value'] = Tinebase_Group::getInstance()->getGroupById($this->_userValue)->toArray(); } else { switch ($this->_operator) { case 'equals': $result['value'] = $result['value'] ? Tinebase_User::getInstance()->getUserById($this->_value)->toArray() : $result['value']; break; case 'in': $result['value'] = array(); foreach ($this->_value as $userId) { $result['value'][] = Tinebase_User::getInstance()->getUserById($userId)->toArray(); } break; default: break; } } } return $result; }
public function testExpandProperty() { $list = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup); $body = '<?xml version="1.0" encoding="UTF-8"?> <A:expand-property xmlns:A="DAV:"> <A:property name="expanded-group-member-set" namespace="http://calendarserver.org/ns/"> <A:property name="last-name" namespace="http://calendarserver.org/ns/"/> <A:property name="principal-URL" namespace="DAV:"/> <A:property name="calendar-user-type" namespace="urn:ietf:params:xml:ns:caldav"/> <A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/> <A:property name="first-name" namespace="http://calendarserver.org/ns/"/> <A:property name="record-type" namespace="http://calendarserver.org/ns/"/> <A:property name="displayname" namespace="DAV:"/> </A:property> </A:expand-property>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals/groups/' . $list->list_id . '/')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav'); $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/groups/' . $list->list_id . '/"]'); $this->assertEquals(1, $nodes->length, 'group itself (not shown by client) is missing'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/intelligroups/' . $list->list_id . '/"]'); $this->assertEquals(1, $nodes->length, 'intelligroup (to keep group itself) is missing'); $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/users/' . Tinebase_Core::getUser()->contact_id . '/"]'); $this->assertEquals(1, $nodes->length, 'user is missing'); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_groupLDAP = Tinebase_Group::factory(Tinebase_Group::LDAP); $this->_userLDAP = Tinebase_User::factory(Tinebase_User::LDAP); $this->_groupSQL = Tinebase_Group::factory(Tinebase_Group::SQL); $this->objects['initialGroup'] = new Tinebase_Model_Group(array('name' => 'tine20phpunit', 'description' => 'initial group')); $this->objects['updatedGroup'] = new Tinebase_Model_Group(array('name' => 'tine20phpunit updated', 'description' => 'updated group')); $this->objects['initialAccount'] = new Tinebase_Model_FullUser(array('accountLoginName' => 'tine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => 'must be set to valid groupid', 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')); }
protected function setUp() { $this->_setGeoData = Addressbook_Controller_Contact::getInstance()->setGeoDataForContacts(FALSE); $appName = 'Addressbook'; ############# TEST USER ########## $user = new Tinebase_Model_FullUser(array('accountLoginName' => 'tine20phpunit', 'accountDisplayName' => 'tine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getGroupByName('Users')->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')); try { $user = Tinebase_User::getInstance()->getUserByLoginName($user->accountLoginName); } catch (Tinebase_Exception_NotFound $e) { $user = Tinebase_User::getInstance()->addUser($user); } $this->objects['user'] = $user; ############# TEST CONTACT ########## try { $containerWithSyncGrant = Tinebase_Container::getInstance()->getContainerByName($appName, 'ContainerWithSyncGrant', Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser()); } catch (Tinebase_Exception_NotFound $e) { $containerWithSyncGrant = new Tinebase_Model_Container(array('name' => 'ContainerWithSyncGrant', 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName($appName)->getId())); $containerWithSyncGrant = Tinebase_Container::getInstance()->addContainer($containerWithSyncGrant); } $this->objects['containerWithSyncGrant'] = $containerWithSyncGrant; try { $containerWithoutSyncGrant = Tinebase_Container::getInstance()->getContainerByName($appName, 'ContainerWithoutSyncGrant', Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser()); } catch (Tinebase_Exception_NotFound $e) { $creatorGrants = array('account_id' => Tinebase_Core::getUser()->getId(), 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_ADD => true, Tinebase_Model_Grants::GRANT_EDIT => true, Tinebase_Model_Grants::GRANT_DELETE => true, Tinebase_Model_Grants::GRANT_ADMIN => true); $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array($creatorGrants)); $containerWithoutSyncGrant = new Tinebase_Model_Container(array('name' => 'ContainerWithoutSyncGrant', 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName($appName)->getId())); $containerWithSyncGrant = Tinebase_Container::getInstance()->addContainer($containerWithoutSyncGrant, $grants); } $this->objects['containerWithoutSyncGrant'] = $containerWithoutSyncGrant; $contact = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'bday' => '1975-01-02 03:00:00', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'container_id' => $this->objects['containerWithSyncGrant']->id, 'role' => 'Role', 'n_given' => 'Lars', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars')); $contact = Addressbook_Controller_Contact::getInstance()->create($contact, FALSE); $this->objects['contact'] = $contact; $unSyncableContact = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'bday' => '1975-01-02 03:00:00', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'container_id' => $this->objects['containerWithoutSyncGrant']->id, 'role' => 'Role', 'n_given' => 'Lars', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars')); $unSyncableContact = Addressbook_Controller_Contact::getInstance()->create($unSyncableContact, FALSE); $this->objects['unSyncableContact'] = $unSyncableContact; ########### define test filter $filterBackend = new Tinebase_PersistentFilter_Backend_Sql(); try { $filter = $filterBackend->getByProperty('Contacts Sync Test', 'name'); } catch (Tinebase_Exception_NotFound $e) { $filter = new Tinebase_Model_PersistentFilter(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'account_id' => Tinebase_Core::getUser()->getId(), 'model' => 'Addressbook_Model_ContactFilter', 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->objects['containerWithSyncGrant']->getId())), 'name' => 'Contacts Sync Test', 'description' => 'Created by unit test')); $filter = $filterBackend->create($filter); } $this->objects['filter'] = $filter; ########### define test devices $palm = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_WEBOS); $palm->contactsfilter_id = $this->objects['filter']->getId(); $this->objects['deviceWebOS'] = ActiveSync_Controller_Device::getInstance()->create($palm); $iphone = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_IPHONE); $iphone->contactsfilter_id = $this->objects['filter']->getId(); $this->objects['deviceIPhone'] = ActiveSync_Controller_Device::getInstance()->create($iphone); $htcAndroid = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_ANDROID); $htcAndroid->contactsfilter_id = $this->objects['filter']->getId(); $this->objects['deviceAndroid'] = ActiveSync_Controller_Device::getInstance()->create($htcAndroid); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->objects['application'] = Tinebase_Application::getInstance()->getApplicationByName('Crm'); $this->objects['user'] = new Tinebase_Model_FullUser(array('accountLoginName' => 'crmtine20phpunit', 'accountDisplayName' => 'crmtine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getDefaultGroup()->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'crmPHPUnit', 'accountEmailAddress' => '*****@*****.**')); $this->objects['role'] = new Tinebase_Model_Role(array('id' => 10, 'name' => 'phpunitrole', 'description' => 'test role for phpunit')); $this->objects['role_2'] = new Tinebase_Model_Role(array('id' => 11, 'name' => 'phpunitrole 2', 'description' => 'test role 2 for phpunit')); // add account for group / role member tests $this->objects['user'] = Tinebase_User::getInstance()->addUser($this->objects['user']); Tinebase_Group::getInstance()->addGroupMember($this->objects['user']->accountPrimaryGroup, $this->objects['user']); return; }
/** * Applies the requierd params for tags acl to the given select object * * @param Zend_Db_Select $_select * @param string $_right required right * @param string $_idProperty property of tag id in select statement * @return void */ public static function applyAclSql($_select, $_right = self::VIEW_RIGHT, $_idProperty = 'id') { $db = Tinebase_Core::getDb(); // TODO: how quota default value if ($_idProperty == 'id') { $_idProperty = $db->quoteIdentifier('id'); } $currentAccountId = Tinebase_Core::getUser()->getId(); $currentGroupIds = Tinebase_Group::getInstance()->getGroupMemberships($currentAccountId); $groupCondition = !empty($currentGroupIds) ? ' OR (' . $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP) . ' AND ' . $db->quoteInto($db->quoteIdentifier('acl.account_id') . ' IN (?)', $currentGroupIds) . ' )' : ''; $where = $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE) . ' OR (' . $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) . ' AND ' . $db->quoteInto($db->quoteIdentifier('acl.account_id') . ' = ?', $currentAccountId) . ' ) ' . $groupCondition; $_select->join(array('acl' => SQL_TABLE_PREFIX . 'tags_acl'), $_idProperty . ' = ' . $db->quoteIdentifier('acl.tag_id'), array())->where($where)->where($db->quoteIdentifier('acl.account_right') . ' = ?', $_right); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->objects['initialGroup'] = new Tinebase_Model_Group(array('id' => 'test-controller-group', 'name' => 'tine20phpunit', 'description' => 'initial test group')); $this->objects['updatedGroup'] = new Tinebase_Model_Group(array('id' => 'test-controller-group', 'name' => 'tine20phpunit updated', 'description' => 'updated test group')); $this->objects['initialAccount'] = new Tinebase_Model_FullUser(array('accountId' => 'dflkjgldfgdfgd', 'accountLoginName' => 'tine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')); $this->objects['updatedAccount'] = new Tinebase_Model_FullUser(array('accountLoginName' => 'tine20phpunit-updated', 'accountStatus' => 'disabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0 Updated', 'accountFirstName' => 'PHPUnit Updated', 'accountEmailAddress' => '*****@*****.**')); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED); $this->objects['initialGroup']->container_id = $internalAddressbook->getId(); $this->objects['updatedGroup']->container_id = $internalAddressbook->getId(); $this->objects['initialAccount']->container_id = $internalAddressbook->getId(); $this->objects['updatedAccount']->container_id = $internalAddressbook->getId(); } return; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->objects['application'] = Tinebase_Application::getInstance()->getApplicationByName('Crm'); $this->objects['user'] = new Tinebase_Model_FullUser(array('accountId' => 10, 'accountLoginName' => 'tine20phpunit', 'accountDisplayName' => 'tine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getGroupByName('Users')->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')); $this->objects['role'] = new Tinebase_Model_Role(array('id' => 10, 'name' => 'phpunitrole', 'description' => 'test role for phpunit')); $this->objects['role_2'] = new Tinebase_Model_Role(array('id' => 11, 'name' => 'phpunitrole 2', 'description' => 'test role 2 for phpunit')); $translate = Tinebase_Translation::getTranslation('Tinebase'); // add account for group / role member tests try { $user = Tinebase_User::getInstance()->getUserById($this->objects['user']->accountId); } catch (Tinebase_Exception_NotFound $e) { $user = Tinebase_User::getInstance()->addUser($this->objects['user']); Tinebase_Group::getInstance()->addGroupMember($user->accountPrimaryGroup, $user); } return; }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if ($this->_accountId === '0') { // get anyones preferences $field = $_backend->getAdapter()->quoteIdentifier($_backend->getTableName() . '.account_type'); $_select->where(Tinebase_Core::getDb()->quoteInto($field . '= ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE)); } else { $conditions = array(array('condition' => Tinebase_Model_Filter_FilterGroup::CONDITION_AND, 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_accountId), array('field' => 'account_type', 'operator' => 'equals', 'value' => $this->_accountType))), array('field' => 'account_type', 'operator' => 'equals', 'value' => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE)); // add groups if accountType is user if ($this->_accountType === Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { $groups = Tinebase_Group::getInstance()->getGroupMemberships($this->_accountId); $conditions[] = array('condition' => Tinebase_Model_Filter_FilterGroup::CONDITION_AND, 'filters' => array(array('field' => 'account_id', 'operator' => 'in', 'value' => $groups), array('field' => 'account_type', 'operator' => 'equals', 'value' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP))); } $filter = new Tinebase_Model_PreferenceFilter($conditions, Tinebase_Model_Filter_FilterGroup::CONDITION_OR); Tinebase_Backend_Sql_Filter_FilterGroup::appendFilters($_select, $filter, $_backend); } }
/** * @return void */ public function testEmailsToAttendeeWithGroups() { $event = $this->_getEvent(); $persistentEvent = Calendar_Controller_Event::getInstance()->create($event); $primaryGroup = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup); $newAttendees = array(array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'firstName' => $this->_testUser->accountFirstName, 'lastName' => $this->_testUser->accountLastName, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $this->_testUser->accountEmailAddress), array('userType' => Calendar_Model_Attender::USERTYPE_GROUP, 'displayName' => $primaryGroup->name, 'partStat' => Calendar_Model_Attender::STATUS_NEEDSACTION, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => '*****@*****.**')); Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE); $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent); $attendees = clone $persistentEvent->attendee; Calendar_Model_Attender::resolveAttendee($attendees); $newAttendees = array(); foreach ($attendees as $attendee) { $newAttendees[] = array('userType' => $attendee->user_type == 'group' ? Calendar_Model_Attender::USERTYPE_GROUP : Calendar_Model_Attender::USERTYPE_USER, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $attendee->user_type == 'group' ? $attendee->user_id->getId() : $attendee->user_id->email, 'displayName' => $attendee->user_type == 'group' ? $attendee->user_id->name : $attendee->user_id->n_fileas); } Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE); $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent); //var_dump($persistentEvent->attendee->toArray()); // there must be more than 2 attendees the user, the group + the groupmembers $this->assertGreaterThan(2, count($persistentEvent->attendee)); }
/** * returns record prepared for json transport * * @param Tinebase_Record_Interface $_record * @return array record data */ protected function _recordToJson($_record) { switch (get_class($_record)) { case 'Timetracker_Model_Timesheet': $_record['timeaccount_id'] = $_record['timeaccount_id'] ? $this->_timeaccountController->get($_record['timeaccount_id']) : $_record['timeaccount_id']; $_record['timeaccount_id']['account_grants'] = Timetracker_Model_TimeaccountGrants::getGrantsOfAccount(Tinebase_Core::get('currentAccount'), $_record['timeaccount_id']); $_record['timeaccount_id']['account_grants'] = $this->_resolveTimesheetGrantsByTimeaccountGrants($_record['timeaccount_id']['account_grants'], $_record['account_id']); Tinebase_User::getInstance()->resolveUsers($_record, 'account_id'); if (Tinebase_Core::getUser()->hasRight('Sales', 'manage_invoices') && !empty($_record['invoice_id'])) { try { $_record['invoice_id'] = Sales_Controller_Invoice::getInstance()->get($_record['invoice_id']); } catch (Tinebase_Exception_NotFound $nfe) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not resolve invoice with id ' . $_record['invoice_id']); } } $recordArray = parent::_recordToJson($_record); break; case 'Timetracker_Model_Timeaccount': $recordArray = parent::_recordToJson($_record); // When editing a single TA we send _ALL_ grants to the client $recordArray['grants'] = Timetracker_Model_TimeaccountGrants::getTimeaccountGrants($_record)->toArray(); foreach ($recordArray['grants'] as &$value) { switch ($value['account_type']) { case Tinebase_Acl_Rights::ACCOUNT_TYPE_USER: $value['account_name'] = Tinebase_User::getInstance()->getUserById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP: $value['account_name'] = Tinebase_Group::getInstance()->getGroupById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE: $value['account_name'] = array('accountDisplayName' => 'Anyone'); break; default: throw new Tinebase_Exception_InvalidArgument('Unsupported accountType.'); break; } } break; } return $recordArray; }
/** * Applies the requierd params for tags acl to the given select object * * @param Zend_Db_Select $_select * @param string $_right required right * @param string $_idProperty property of tag id in select statement * @return void */ public static function applyAclSql($_select, $_right = self::VIEW_RIGHT, $_idProperty = 'id') { if (empty($_right)) { throw new Tinebase_Exception_InvalidArgument('right is empty'); } $db = Tinebase_Core::getDb(); if ($_idProperty == 'id') { $_idProperty = $db->quoteIdentifier('id'); } if (!is_object(Tinebase_Core::getUser())) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Cannot apply ACL, no user object found. This might happen during setup/update.'); } return; } $currentAccountId = Tinebase_Core::getUser()->getId(); $currentGroupIds = Tinebase_Group::getInstance()->getGroupMemberships($currentAccountId); $groupCondition = !empty($currentGroupIds) ? ' OR (' . $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP) . ' AND ' . $db->quoteInto($db->quoteIdentifier('acl.account_id') . ' IN (?)', $currentGroupIds) . ' )' : ''; $where = $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE) . ' OR (' . $db->quoteInto($db->quoteIdentifier('acl.account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) . ' AND ' . $db->quoteInto($db->quoteIdentifier('acl.account_id') . ' = ?', $currentAccountId) . ' ) ' . $groupCondition; $_select->join(array('acl' => SQL_TABLE_PREFIX . 'tags_acl'), $_idProperty . ' = ' . $db->quoteIdentifier('acl.tag_id'), array())->where($where)->where($db->quoteIdentifier('acl.account_right') . ' = ?', $_right); }
/** * 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"; } } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if ($this->_value === 'all') { $_select->where('1=1'); return; } $gs = new Tinebase_Backend_Sql_Filter_GroupSelect($_select); $adapter = $_backend->getAdapter(); //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') value: ' . print_r($this->_value, true)); foreach ($this->_value as $attenderValue) { if (in_array($attenderValue['user_type'], array(Calendar_Model_Attender::USERTYPE_USER, Calendar_Model_Attender::USERTYPE_GROUPMEMBER))) { // @todo user_id might contain filter in the future -> get userids from adressbook controller with contact filter // transform CURRENTCONTACT $attenderValue['user_id'] = $attenderValue['user_id'] == Addressbook_Model_Contact::CURRENTCONTACT ? Tinebase_Core::getUser()->contact_id : $attenderValue['user_id']; $attendee = array(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $attenderValue['user_id']), array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $attenderValue['user_id'])); } else { if ($attenderValue['user_type'] == self::USERTYPE_MEMBEROF) { // resolve group members $group = Tinebase_Group::getInstance()->getGroupById($attenderValue['user_id']); $attendee = array(); // fetch list only if list_id is not NULL, otherwise we get back an empty list object if (!empty($group->list_id)) { $contactList = Addressbook_Controller_List::getInstance()->get($group->list_id); foreach ($contactList->members as $member) { $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $member); $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $member); } } } else { $attendee = array($attenderValue); } } foreach ($attendee as $attender) { $gs->orWhere($adapter->quoteInto($adapter->quoteIdentifier('attendee.user_type') . ' = ?', $attender['user_type']) . ' AND ' . $adapter->quoteInto($adapter->quoteIdentifier('attendee.user_id') . ' = ?', $attender['user_id'])); } } $gs->appendWhere(Zend_Db_Select::SQL_OR); }
/** * delete groups and their members * * - also deletes groups and users in sync backends */ protected function _deleteGroups() { foreach ($this->_groupIdsToDelete as $groupId) { if ($this->_removeGroupMembers) { foreach (Tinebase_Group::getInstance()->getGroupMembers($groupId) as $userId) { try { Tinebase_User::getInstance()->deleteUser($userId); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' error while deleting user: '******'::' . __LINE__ . ' error while deleting group: ' . $e->getMessage()); } } } }
/** * Create initial Roles * * @todo make hard coded role names ('user role' and 'admin role') configurable * * @return void */ public function createInitialRoles() { $groupsBackend = Tinebase_Group::getInstance(); $adminGroup = $groupsBackend->getDefaultAdminGroup(); $userGroup = $groupsBackend->getDefaultGroup(); // add roles and add the groups to the roles $adminRole = new Tinebase_Model_Role(array('name' => 'admin role', 'description' => 'admin role for tine. this role has all rights per default.')); $adminRole = $this->createRole($adminRole); $this->setRoleMembers($adminRole->getId(), array(array('id' => $adminGroup->getId(), 'type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP))); $userRole = new Tinebase_Model_Role(array('name' => 'user role', 'description' => 'userrole for tine. this role has only the run rights for all applications per default.')); $userRole = $this->createRole($userRole); $this->setRoleMembers($userRole->getId(), array(array('id' => $userGroup->getId(), 'type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP))); $this->resetClassCache(); }
/** * import the addressbook from egw14 * * @param string $_oldTableName [OPTIONAL] * @param int $_useOldId [OPTIONAL] * * @todo use old group name for the (shared) container ? * @todo add more config params ( */ public function importAddressbook($_oldTableName = NULL, $_useOldId = TRUE) { // did nothing //@set_time_limit (120); $sharedContactsGroupId = -15; $sharedContactsContainerName = "Metaways Kontakte"; $setFileasFromName = TRUE; $tableName = $_oldTableName != NULL ? $_oldTableName : $this->oldTablePrefix . 'addressbook'; $contactsTable = new Tinebase_Db_Table(array('name' => $tableName)); // get contacts $contacts = $contactsTable->fetchAll(); // get categories $categories = $this->getCategories(); echo "Import Contacts from table " . $tableName . " ... <br/>"; foreach ($contacts as $contact) { echo "importing " . $contact->n_given . " " . $contact->n_family . " ..."; /******************** add container ************************/ if ($contact->contact_owner > 0) { // personal container for owner try { $container = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Personal Contacts', Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser()); } catch (Tinebase_Exception_NotFound $e) { $container = new Tinebase_Model_Container(array('name' => 'Personal Contacts', 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId())); $container = Tinebase_Container::getInstance()->addContainer($container, NULL, TRUE); } } else { if ($contact->contact_owner == $sharedContactsGroupId) { // default users group -> shared container $userGroup = Tinebase_Group::getInstance()->getGroupByName('Users'); try { $container = Tinebase_Container::getInstance()->getContainerByName('Addressbook', $sharedContactsContainerName, Tinebase_Model_Container::TYPE_SHARED); } catch (Tinebase_Exception_NotFound $e) { $container = new Tinebase_Model_Container(array('name' => $sharedContactsContainerName, 'type' => Tinebase_Model_Container::TYPE_SHARED, 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId())); $container = Tinebase_Container::getInstance()->addContainer($container, NULL, TRUE); Tinebase_Container::getInstance()->addGrants($container, Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP, $userGroup, array(Tinebase_Model_Grants::GRANT_READ, Tinebase_Model_Grants::GRANT_ADD, Tinebase_Model_Grants::GRANT_EDIT, Tinebase_Model_Grants::GRANT_DELETE), TRUE); } } else { echo "skipped.<br/>"; continue; } } $containerId = $container->getId(); /******************** set fileas ************************/ if ($setFileasFromName) { $fileas = ""; if (!empty($contact->n_family)) { if (!empty($contact->n_given)) { $fileas = $contact->n_family . ", " . $contact->n_given; } else { $fileas = $contact->n_family; } } else { $fileas = $contact->n_given; } if (empty($fileas)) { $fileas = $contact->org_name; } elseif (!empty($contact->n_middle)) { $fileas .= " " . $contact->n_middle; } } else { $fileas = empty($contact->n_fileas) ? $contact->org_name : $contact->n_fileas; } /******************** set urls (add 'http://' if missing) ************************/ if (!preg_match("/https*:\\/\\//i", $contact->contact_url) && !empty($contact->contact_url)) { $url = "http://" . $contact->contact_url; } else { $url = $contact->contact_url; } if (!preg_match("/https*:\\/\\//i", $contact->contact_url_home) && !empty($contact->contact_url_home)) { $urlHome = "http://" . $contact->contact_url_home; } else { $urlHome = $contact->contact_url_home; } /******************** create contact record ************************/ $tineContact = new Addressbook_Model_Contact(array('id' => $_useOldId ? $contact->contact_id : 0, 'account_id' => $contact->account_id, 'owner' => $containerId, 'n_family' => empty($contact->n_family) ? 'imported' : $contact->n_family, 'n_fileas' => $fileas, 'n_fn' => empty($contact->n_fn) ? 'imported' : $contact->n_fn, 'adr_one_countryname' => isset($this->countryMapping[$contact->adr_one_countryname]) ? $this->countryMapping[$contact->adr_one_countryname] : "", 'adr_one_locality' => $contact->adr_one_locality, 'adr_one_postalcode' => $contact->adr_one_postalcode, 'adr_one_region' => $contact->adr_one_region, 'adr_one_street' => $contact->adr_one_street, 'adr_one_street2' => $contact->adr_one_street2, 'adr_two_countryname' => isset($this->countryMapping[$contact->adr_two_countryname]) ? $this->countryMapping[$contact->adr_two_countryname] : "", 'adr_two_locality' => $contact->adr_two_locality, 'adr_two_postalcode' => $contact->adr_two_postalcode, 'adr_two_region' => $contact->adr_two_region, 'adr_two_street' => $contact->adr_two_street, 'adr_two_street2' => $contact->adr_two_street2, 'last_modified_time' => new Tinebase_DateTime($contact->contact_modified), 'assistent' => $contact->contact_assistent, 'bday' => $contact->contact_bday, 'email' => $contact->contact_email, 'email_home' => $contact->contact_email_home, 'note' => $contact->contact_note, 'role' => $contact->contact_role, 'title' => $contact->contact_title, 'url' => $url, 'url_home' => $urlHome, 'n_given' => $contact->n_given, 'n_middle' => $contact->n_middle, 'n_prefix' => $contact->n_prefix, 'n_suffix' => $contact->n_suffix, 'org_name' => $contact->org_name, 'org_unit' => $contact->org_unit, 'tel_assistent' => $contact->tel_assistent, 'tel_car' => $contact->tel_car, 'tel_cell' => $contact->tel_cell, 'tel_cell_private' => $contact->tel_cell_private, 'tel_fax' => $contact->tel_fax, 'tel_fax_home' => $contact->tel_fax_home, 'tel_home' => $contact->tel_home, 'tel_pager' => $contact->tel_pager, 'tel_work' => $contact->tel_work, 'tags' => array())); $tineContact = Addressbook_Controller_Contact::getInstance()->create($tineContact); echo " ok.<br/>"; // get categories -> tags if (!empty($contact->cat_id)) { $catIds = explode(',', $contact->cat_id); $filter = new Tinebase_Model_TagFilter(array('name' => '%', 'application' => 'Addressbook')); $paging = new Tinebase_Model_Pagination(); $contactTags = new Tinebase_Record_RecordSet('Tinebase_Model_Tag'); foreach ($catIds as $catId) { if (isset($categories[$catId])) { $filter->name = $categories[$catId]->cat_name; $tags = Tinebase_Tags::getInstance()->searchTags($filter, $paging)->toArray(); if (empty($tags)) { $tag = new Tinebase_Model_Tag(array('type' => Tinebase_Model_Tag::TYPE_SHARED, 'name' => $categories[$catId]->cat_name)); $tag = Tinebase_Tags::getInstance()->createTag($tag); $contactTags->addRecord($tag); } else { $contactTags->addRecord(new Tinebase_Model_Tag($tags[0])); } } } $tineContact->tags = $contactTags; Tinebase_Tags::getInstance()->setTagsOfRecord($tineContact); } } echo "done! got " . sizeof($contacts) . " contacts.<br>"; }
/** * create new cronuser * * @return Tinebase_Model_FullUser */ protected function _createCronuser() { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new cronuser.'); } $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup(); $cronuser = new Tinebase_Model_FullUser(array('accountLoginName' => 'cronuser', 'accountStatus' => Tinebase_Model_User::ACCOUNT_STATUS_DISABLED, 'visibility' => Tinebase_Model_FullUser::VISIBILITY_HIDDEN, 'accountPrimaryGroup' => $adminGroup->getId(), 'accountLastName' => 'cronuser', 'accountDisplayName' => 'cronuser', 'accountExpires' => NULL)); $cronuser = Tinebase_User::getInstance()->addUser($cronuser); Tinebase_Group::getInstance()->addGroupMember($cronuser->accountPrimaryGroup, $cronuser->getId()); return $cronuser; }
/** * tests if the rights work: Sales_Acl_Rights::SET_INVOICE_NUMBER, Sales_Acl_Rights::MANAGE_INVOICES */ public function testSetManualNumberRight() { $this->_createCustomers(); $this->_createCostCenters(); $customer = $this->_customerRecords->filter('name', 'Customer1')->getFirstRecord(); $invoice = $this->_invoiceController->create(new Sales_Model_Invoice(array('number' => 'R-3000', 'customer_id' => $customer->getId(), 'description' => 'Manual', 'address_id' => $this->_addressRecords->filter('customer_id', $customer->getId())->getFirstRecord()->getId(), 'costcenter_id' => $this->_costcenterRecords->getFirstRecord()->getId()))); // fetch user group $group = Tinebase_Group::getInstance()->getGroupByName('Users'); $groupId = $group->getId(); // create new user $user = new Tinebase_Model_FullUser(array('accountLoginName' => 'testuser', 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => 'Test User', 'accountLastName' => 'User', 'accountFirstName' => 'Test', 'accountFullName' => 'Test User', 'accountEmailAddress' => '*****@*****.**')); $user = Admin_Controller_User::getInstance()->create($user, 'pw', 'pw'); $this->_testUser = Tinebase_Core::getUser(); Tinebase_Core::set(Tinebase_Core::USER, $user); $e = new Exception('No Message'); try { $invoice = $this->_invoiceController->create(new Sales_Model_Invoice(array('number' => 'R-3001', 'customer_id' => $customer->getId(), 'description' => 'Manual Forbidden', 'address_id' => $this->_addressRecords->filter('customer_id', $customer->getId())->getFirstRecord()->getId(), 'costcenter_id' => $this->_costcenterRecords->getFirstRecord()->getId()))); } catch (Exception $e) { } $this->assertTrue(get_class($e) == 'Tinebase_Exception_AccessDenied'); $this->assertTrue($e->getMessage() == 'You don\'t have the right to manage invoices!'); Tinebase_Core::set(Tinebase_Core::USER, $this->_testUser); $fe = new Admin_Frontend_Json(); $userRoles = $fe->getRoles('user', array(), array(), 0, 1); $userRole = $fe->getRole($userRoles['results'][0]['id']); $roleRights = $fe->getRoleRights($userRole['id']); $roleMembers = $fe->getRoleMembers($userRole['id']); $roleMembers['results'][] = array('name' => 'testuser', 'type' => 'user', 'id' => $user->accountId); $app = Tinebase_Application::getInstance()->getApplicationByName('Sales'); $roleRights['results'][] = array('application_id' => $app->getId(), 'right' => Sales_Acl_Rights::MANAGE_INVOICES); $fe->saveRole($userRole, $roleMembers['results'], $roleRights['results']); Tinebase_Core::set(Tinebase_Core::USER, $user); $e = new Exception('No Message'); try { $invoice = $this->_invoiceController->create(new Sales_Model_Invoice(array('number' => 'R-3001', 'customer_id' => $customer->getId(), 'description' => 'Manual Forbidden', 'address_id' => $this->_addressRecords->filter('customer_id', $customer->getId())->getFirstRecord()->getId(), 'costcenter_id' => $this->_costcenterRecords->getFirstRecord()->getId()))); } catch (Exception $e) { } $this->assertEquals('Tinebase_Exception_AccessDenied', get_class($e)); $this->assertEquals('You have no right to set the invoice number!', $e->getMessage()); }
/** * 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; }
/** * create initial admin account * * Method is called during Setup Initialization * * $_options may contain the following keys: * <code> * $options = array( * 'adminLoginName' => 'admin', * 'adminPassword' => 'lars', * 'adminFirstName' => 'Tine 2.0', * 'adminLastName' => 'Admin Account', * 'adminEmailAddress' => '*****@*****.**', * 'expires' => Tinebase_DateTime object * ); * </code> * * @param array $_options [hash that may contain override values for admin user name and password] * @return void * @throws Tinebase_Exception_InvalidArgument */ public static function createInitialAccounts($_options) { if (!isset($_options['adminPassword']) || !isset($_options['adminLoginName'])) { throw new Tinebase_Exception_InvalidArgument('Admin password and login name have to be set when creating initial account.', 503); } $adminLoginName = $_options['adminLoginName']; $adminPassword = $_options['adminPassword']; $adminFirstName = isset($_options['adminFirstName']) ? $_options['adminFirstName'] : 'Tine 2.0'; $adminLastName = isset($_options['adminLastName']) ? $_options['adminLastName'] : 'Admin Account'; $adminEmailAddress = isset($_options['adminEmailAddress']) || array_key_exists('adminEmailAddress', $_options) ? $_options['adminEmailAddress'] : NULL; // get admin & user groups $userBackend = Tinebase_User::getInstance(); $groupsBackend = Tinebase_Group::getInstance(); $adminGroup = $groupsBackend->getDefaultAdminGroup(); $userGroup = $groupsBackend->getDefaultGroup(); Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating initial admin user (login: '******' / email: ' . $adminEmailAddress . ')'); $user = new Tinebase_Model_FullUser(array('accountLoginName' => $adminLoginName, 'accountStatus' => 'enabled', 'accountPrimaryGroup' => $userGroup->getId(), 'accountLastName' => $adminLastName, 'accountDisplayName' => $adminLastName . ', ' . $adminFirstName, 'accountFirstName' => $adminFirstName, 'accountExpires' => isset($_options['expires']) ? $_options['expires'] : NULL, 'accountEmailAddress' => $adminEmailAddress)); if ($adminEmailAddress !== NULL) { $user->imapUser = new Tinebase_Model_EmailUser(array('emailPassword' => $adminPassword)); $user->smtpUser = new Tinebase_Model_EmailUser(array('emailPassword' => $adminPassword)); } // update or create user in local sql backend try { $userBackend->getUserByProperty('accountLoginName', $adminLoginName); Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'update'); $user = $userBackend->updateUserInSqlBackend($user); } catch (Tinebase_Exception_NotFound $ten) { // call addUser here to make sure, sql user plugins (email, ...) are triggered Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create'); $user = $userBackend->addUser($user); } // set the password for the account // empty password triggers password change dialogue during first login if (!empty($adminPassword)) { Tinebase_User::getInstance()->setPassword($user, $adminPassword); } // add the admin account to all groups Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user); Tinebase_Group::getInstance()->addGroupMember($userGroup, $user); }
/** * testAddressbookCustomFieldAcl * * @see 0007630: Customfield read access to all users */ public function testAddressbookCustomFieldAcl() { $createdCustomField = $this->_instance->addCustomField(self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact'))); $anotherCustomField = $this->_instance->addCustomField(self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact'))); $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'testcontact', 'container_id' => Tinebase_Container::getInstance()->getSharedContainer(Tinebase_Core::getUser(), 'Addressbook', Tinebase_Model_Grants::GRANT_READ)->getFirstRecord()->getId()))); $cfValue = array($createdCustomField->name => 'test value', $anotherCustomField->name => 'test value 2'); $contact->customfields = $cfValue; $contact = Addressbook_Controller_Contact::getInstance()->update($contact); $this->assertEquals($cfValue, $contact->customfields, 'cf not saved: ' . print_r($contact->toArray(), TRUE)); // create group and only give acl to this group $group = Tinebase_Group::getInstance()->getDefaultAdminGroup(); $this->_instance->setGrants($createdCustomField, array(Tinebase_Model_CustomField_Grant::GRANT_READ, Tinebase_Model_CustomField_Grant::GRANT_WRITE), Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP, $group->getId()); $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId()); $this->assertEquals(2, count($contact->customfields)); // change user and check cfs $this->_user = Tinebase_Core::getUser(); $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever'); Tinebase_Core::set(Tinebase_Core::USER, $sclever); $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId()); $this->assertEquals(array($anotherCustomField->name => 'test value 2'), $contact->customfields, 'cf should be hidden: ' . print_r($contact->customfields, TRUE)); }
/** * update to 1.12 * - import accounts from ldap to sql again if needed */ public function update_11() { $groupBackend = Tinebase_Group::getInstance(); // check if ldap backend is enabled if ($groupBackend instanceof Tinebase_Group_Ldap) { // empty suer and group tables #$this->_db->delete(SQL_TABLE_PREFIX . 'group_members'); #$this->_db->delete(SQL_TABLE_PREFIX . 'accounts'); #$this->_db->delete(SQL_TABLE_PREFIX . 'groups'); // import groups from ldap #Tinebase_Group::getInstance()->importGroups(); // import users from ldap Tinebase_User::getInstance()->importUsers(); // import group memberships from ldap #Tinebase_Group::getInstance()->importGroupMembers(); } $this->setApplicationVersion('Tinebase', '1.12'); }
/** * 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)); }
/** * @see 0009852: improve cache cleaning after LDAP sync */ public function testSyncGroups() { $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup(); $group = $this->testAddGroup(); $user = $this->_addUserToGroup($group); // add user to group (only in LDAP) $this->_groupLDAP->addGroupMemberInSyncBackend($defaultUserGroup->getId(), $user); // trigger caching $memberships = $this->_groupLDAP->getGroupMembers($defaultUserGroup); $this->assertFalse(in_array($user->getId(), $memberships)); // sync users Tinebase_User::syncUsers(array('syncContactData' => TRUE)); // check group memberships $memberships = $this->_groupLDAP->getGroupMembers($defaultUserGroup); $this->assertTrue(in_array($user->getId(), $memberships), 'group memberships not updated: ' . print_r($memberships, true)); }