/** * init the test frameworks * */ public function initFramework() { Setup_Core::initFramework(); //$this->getConfig(); Tinebase_Core::startCoreSession(); Tinebase_Core::set('frameworkInitialized', true); }
/** * Tears down the fixture * This method is called after a test is executed. * * @access protected */ protected function tearDown() { $currentUser = Tinebase_Core::getUser(); if ($currentUser->accountLoginName !== $this->_testUser->accountLoginName) { Tinebase_Core::set(Tinebase_Core::USER, $this->_testUser); } }
/** * Sets up the fixture. * * This method is called before a test is executed. */ protected function setUp() { Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); // we need that because the voip db tables can have a different prefix Tinebase_Core::set('voipdbTablePrefix', SQL_TABLE_PREFIX); $phoneId = Tinebase_Record_Abstract::generateUID(); $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'registrar' => 'registrar')); $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => Tinebase_Record_Abstract::generateUID())); $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => Tinebase_Record_Abstract::generateUID(), 'description' => Tinebase_Record_Abstract::generateUID(), 'language_w' => true)); $this->_objects['phonesettings'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $phoneId, 'language' => 'Deutsch')); $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId())); $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => $phoneId, 'macaddress' => "1234567890cd", 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phoneOwner'] = array('account_id' => Zend_Registry::get('currentAccount')->getId(), 'account_type' => 'user'); $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $this->_objects['phone']->rights = $rights; // create phone, location, template $snomLocationBackend = new Voipmanager_Backend_Snom_Location(); $snomTemplateBackend = new Voipmanager_Backend_Snom_Template(); $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software(); $snomPhoneBackend = new Voipmanager_Backend_Snom_Phone(); $snomSettingBackend = new Voipmanager_Backend_Snom_Setting(); $snomPhoneSettingsBackend = new Voipmanager_Backend_Snom_PhoneSettings(); $snomSoftwareBackend->create($this->_objects['software']); $snomLocationBackend->create($this->_objects['location']); $snomTemplateBackend->create($this->_objects['template']); $snomSettingBackend->create($this->_objects['setting']); $snomPhoneBackend->create($this->_objects['phone']); $snomPhoneSettingsBackend->create($this->_objects['phonesettings']); }
/** * update to 9.1 * * @return void */ public function update_0() { // we need at least addressbook version 9,7 if (version_compare($this->getApplicationVersion('Addressbook'), '9.8') < 0) { return; } $setupUser = $this->_getSetupFromConfigOrCreateOnTheFly(); if ($setupUser) { Tinebase_Core::set(Tinebase_Core::USER, $setupUser); $filter = new Phone_Model_CallFilter(array(array('field' => 'start', 'operator' => 'after', 'value' => date('Y-m-d H:i:s', time() - 3600 * 24 * 30 * 3))), 'AND', array('ignoreAcl' => true)); $addressbookController = Addressbook_Controller_Contact::getInstance(); $phoneController = Phone_Controller_Call::getInstance(); $calls = $phoneController->search($filter); foreach ($calls as $_record) { // resolve telephone number to contacts if possible $telNumber = Addressbook_Model_Contact::normalizeTelephoneNoCountry($phoneController->resolveInternalNumber($_record->destination)); if (null === $telNumber) { continue; } $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'telephone_normalized', 'operator' => 'equals', 'value' => $telNumber))); $contacts = $addressbookController->search($filter); $relations = array(); foreach ($contacts as $contact) { $relations[] = array('related_model' => 'Addressbook_Model_Contact', 'related_id' => $contact->getId(), 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND, 'type' => 'CALLER'); } if (count($relations) > 0) { $_record->relations = $relations; $phoneController->update($_record); } } } $this->setApplicationVersion('Phone', '9.1'); }
/** * Tears down the fixture * This method is called after a test is executed. * * @access protected */ protected function tearDown() { if ($this->_transactionId) { Tinebase_TransactionManager::getInstance()->rollBack(); } if ($this->_user) { Tinebase_Core::set(Tinebase_Core::USER, $this->_user); } }
/** * Tears down the fixture * This method is called after a test is executed. * * @access protected */ protected function tearDown() { // need to be reset after triggerAsyncEvents run (singleton ...) Tinebase_User::getInstance()->unregisterAllPlugins(); Tinebase_User::getInstance()->registerPlugins($this->_userPlugins); $currentUser = Tinebase_Core::getUser(); if ($currentUser->accountLoginName !== $this->_testUser->accountLoginName) { Tinebase_Core::set(Tinebase_Core::USER, $this->_testUser); } parent::tearDown(); }
/** * initializes the config * - overwrite session_save_path */ public function _setupCliConfig() { $configData = @(include 'config.inc.php'); if ($configData === false) { echo 'UNKNOWN STATUS / CONFIG FILE NOT FOUND (include path: ' . get_include_path() . ")\n"; exit(3); } $configData['sessiondir'] = Tinebase_Core::getTempDir(); $config = new Zend_Config($configData); Tinebase_Core::set(Tinebase_Core::CONFIG, $config); }
/** * testTimezoneConversion */ public function testTimezoneConversion() { $exampleFilterData = self::getPersistentFilterData(); $savedFilterData = $this->testSaveFilter($exampleFilterData); $testUserTimezone = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $testUserTimezone !== 'US/Pacific' ? 'US/Pacific' : 'UTC'); $originalDueDateFilter = $this->_getFilter('due', $exampleFilterData); $convertedDueDataFilter = $this->_getFilter('due', $this->_uit->getPersistentFilter($savedFilterData['id'])); Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $testUserTimezone); $this->assertNotEquals($originalDueDateFilter['value'], $convertedDueDataFilter['value']); }
/** * testDownloadLinkAcl */ public function testDownloadLinkAcl() { // try to access download link to personal container of another user $downloadLink = $this->testCreateDownloadLink(); Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['sclever']); try { $resultNode = $this->_getUit()->getNode($downloadLink, array()); $this->fail('user should not be able to access download link node'); } catch (Tinebase_Exception_AccessDenied $tead) { $this->assertEquals('No permission to get node', $tead->getMessage()); } }
/** * Sets up the fixture. * * This method is called before a test is executed. */ protected function setUp() { // we need that because the voip db tables can have a different prefix Tinebase_Core::set('voipdbTablePrefix', SQL_TABLE_PREFIX); $this->_backend = new Voipmanager_Backend_Snom_Phone(); $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => 20001, 'name' => 'phpunit test location', 'registrar' => 'registrar')); $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => 20003)); $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => 20004)); $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => 20002, 'name' => 'phpunit test location', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId())); $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => 1001, 'macaddress' => "1234567890cd", 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none')); $this->_objects['phoneOwner'] = array('account_id' => Zend_Registry::get('currentAccount')->getId(), 'account_type' => 'user'); $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner'])); $this->_objects['phone']->rights = $rights; }
/** * Override method: Setup needs additional initialisation * * @see tine20/Setup/Setup_Initialize#_initialize($_application) */ protected function _initialize(Tinebase_Model_Application $_application, $_options = null) { parent::_initialize($_application, $_options); $initialAdminUserOptions = $this->_parseInitialAdminUserOptions($_options); if (Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) { Tinebase_User::syncUsers(true); } else { Tinebase_User::createInitialAccounts($initialAdminUserOptions); } // set current user $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']); Tinebase_Core::set(Tinebase_Core::USER, $initialUser); parent::_initialize($_application, $_options); }
/** * exports calendars as ICS * * @param Zend_Console_Getopt $_opts */ public function exportICS($_opts) { Tinebase_Core::set('HOSTNAME', 'localhost'); $opts = $_opts->getRemainingArgs(); $container_id = $opts[0]; $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $container_id))); $result = Calendar_Controller_MSEventFacade::getInstance()->search($filter, null, false, false, 'get'); if ($result->count() == 0) { throw new Tinebase_Exception('this calendar does not contain any records.'); } $converter = Calendar_Convert_Event_VCalendar_Factory::factory("generic"); $result = $converter->fromTine20RecordSet($result); print $result->serialize(); }
public function testGetDispatchServerJSON() { $request = \Zend\Http\PhpEnvironment\Request::fromString("OPTIONS /index.php HTTP/1.1\r\n" . "Host: localhost\r\n" . "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre\r\n" . "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" . "Accept-Language: en-us,en;q=0.5\r\n" . "Accept-Encoding: gzip,deflate\r\n" . "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" . "Connection: keep-alive\r\n" . "Origin: http://foo.example\r\n" . "Access-Control-Request-Method: POST\r\n" . "Access-Control-Request-Headers: X-PINGOTHER"); Tinebase_Core::set(Tinebase_Core::REQUEST, $request); $server = Tinebase_Core::getDispatchServer($request); $this->assertInstanceOf('Tinebase_Server_Json', $server); $request = \Zend\Http\PhpEnvironment\Request::fromString("POST /index.php HTTP/1.1\r\n" . "X-Tine20-Request-Type: JSON\r\n" . "\r\n" . '{"jsonrpc":"2.0","method":"Admin.searchUsers","params":{"filter":[{"field":"query","operator":"contains","value":"","id":"ext-record-2"}],"paging":{"sort":"accountLoginName","dir":"ASC","start":0,"limit":50}},"id":37}'); Tinebase_Core::set(Tinebase_Core::REQUEST, $request); $server = Tinebase_Core::getDispatchServer($request); $this->assertInstanceOf('Tinebase_Server_Json', $server); $request = \Zend\Http\PhpEnvironment\Request::fromString("POST /index.php HTTP/1.1\r\n" . "Content-Type: application/json\r\n" . "\r\n" . '{"jsonrpc":"2.0","method":"Admin.searchUsers","params":{"filter":[{"field":"query","operator":"contains","value":"","id":"ext-record-2"}],"paging":{"sort":"accountLoginName","dir":"ASC","start":0,"limit":50}},"id":37}'); Tinebase_Core::set(Tinebase_Core::REQUEST, $request); $server = Tinebase_Core::getDispatchServer($request); $this->assertInstanceOf('Tinebase_Server_Json', $server); }
public function testUpdateEvent() { $persistentEvent = $this->testCreateEvent(); $currentTz = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, 'farfaraway'); $persistentEvent->summary = 'Lunchtime'; $updatedEvent = $this->_controller->update($persistentEvent); $this->assertEquals($persistentEvent->summary, $updatedEvent->summary); $this->assertEquals($currentTz, $updatedEvent->originator_tz, 'originator_tz must not be touchet if dtsart is not updatet!'); $updatedEvent->dtstart->addHour(1); $updatedEvent->dtend->addHour(1); $secondUpdatedEvent = $this->_controller->update($updatedEvent); $this->assertEquals(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), $secondUpdatedEvent->originator_tz, 'originator_tz must be adopted if dtsart is updatet!'); Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $currentTz); }
/** * Override method: Setup needs additional initialisation * * @see tine20/Setup/Setup_Initialize#_initialize($_application) */ protected function _initialize(Tinebase_Model_Application $_application, $_options = null) { $initialAdminUserOptions = $this->_parseInitialAdminUserOptions($_options); if (Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) { Tinebase_User::syncUsers(array('syncContactData' => TRUE)); } try { $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']); } catch (Tinebase_Exception_NotFound $tenf) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Could not find initial admin account in user backend. Creating new one ...'); } Tinebase_User::createInitialAccounts($initialAdminUserOptions); $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']); } Tinebase_Core::set(Tinebase_Core::USER, $initialUser); parent::_initialize($_application, $_options); }
/** * init the test framework */ public function initFramework() { $this->setWhiteAndBlacklists(); $config = $this->getConfig(); // set some server vars. sabredav complains if REQUEST_URI is not set $_SERVER['DOCUMENT_ROOT'] = $config->docroot; $_SERVER['REQUEST_URI'] = ''; Tinebase_Core::startCoreSession(); Tinebase_Core::initFramework(); // set default test mailer Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array()); // set max execution time Tinebase_Core::setExecutionLifeTime(1200); if ($config->locale) { Tinebase_Core::setupUserLocale($config->locale); } // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others) Zend_Session::$_unitTestEnabled = TRUE; Tinebase_Core::set('frameworkInitialized', true); }
/** * import the data */ public function import($_resource = NULL, $_clientRecordData = array()) { $_resource['options'] = Zend_Json::decode($_resource['options']); $credentials = new Tinebase_Model_CredentialCache(array('id' => $_resource['options']['cid'], 'key' => $_resource['options']['ckey'])); Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($credentials); $uri = $this->_splitUri($_resource['remoteUrl']); $caldavClientOptions = array('baseUri' => $uri['host'], 'calenderUri' => $uri['path'], 'userName' => $credentials->username, 'password' => $credentials->password, 'allowDuplicateEvents' => isset($_resource['options']['allowDuplicateEvents']) ? $_resource['options']['allowDuplicateEvents'] : false); Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Trying to get calendar container Name:' . $_resource['options']['container_id']); $container = Tinebase_Container::getInstance()->getContainerById($this->_getImportCalendarByName($_resource['options']['container_id'])); if ($container === false) { throw new Tinebase_Exception('Could not import, aborting ..'); return false; } $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($credentials->username, $credentials->password); Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . ' ' . __LINE__ . ' Trigger CalDAV client with URI ' . $_resource['remoteUrl']); } $this->_calDAVClient = new Calendar_Import_CalDav_Client($caldavClientOptions, 'Generic', $container->name); $this->_calDAVClient->setVerifyPeer(false); $this->_calDAVClient->getDecorator()->initCalendarImport(); $this->_calDAVClient->updateAllCalendarData(); }
/** * set current user * * @param $user * @throws Tinebase_Exception_InvalidArgument */ protected function _setUser($user) { Tinebase_Core::set(Tinebase_Core::USER, $user); }
/** * process given queue job * --message json encoded task * * @TODO rework user management, jobs should be executed as the right user in future * * @param Zend_Console_Getopt $_opts * @return boolean success */ public function executeQueueJob($_opts) { try { $cronuser = Tinebase_User::getInstance()->getFullUserByLoginName($_opts->username); } catch (Tinebase_Exception_NotFound $tenf) { $cronuser = $this->_getCronuserFromConfigOrCreateOnTheFly(); } Tinebase_Core::set(Tinebase_Core::USER, $cronuser); $args = $_opts->getRemainingArgs(); $message = preg_replace('/^message=/', '', $args[0]); if (!$message) { throw new Tinebase_Exception_InvalidArgument('mandatory parameter "message" is missing'); } Tinebase_ActionQueue::getInstance()->executeAction($message); return TRUE; }
/** * init the environment * */ protected function _init() { // init environment Tinebase_Core::setupConfig(); Tinebase_Core::setupLogger(); Tinebase_Core::set('locale', new Zend_Locale('de_DE')); Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, 'UTC'); Tinebase_Core::setupDatabaseConnection(); Tinebase_Core::setupCache(); }
/** * init tine framework */ public static function initFramework() { // avoid autostart of sessions Zend_Session::setOptions(array('strict' => true)); Tinebase_Core::setupTempDir(); Tinebase_Core::setupStreamWrapper(); //Cache must be setup before User Locale because otherwise Zend_Locale tries to setup //its own cache handler which might result in a open_basedir restriction depending on the php.ini settings Tinebase_Core::setupCache(); Tinebase_Core::setupBuildConstants(); // setup a temporary user locale. This will be overwritten later but we // need to handle exceptions during initialisation process such as session timeout // @todo add fallback locale to config file Tinebase_Core::set('locale', new Zend_Locale('en_US')); Tinebase_Core::setupUserLocale(); Tinebase_Core::enableProfiling(); if (PHP_SAPI !== 'cli') { header('X-API: http://www.tine20.org/apidocs/tine20/'); if (isset($_SERVER['HTTP_X_TRANSACTIONID'])) { header('X-TransactionID: ' . substr($_SERVER['HTTP_X_TRANSACTIONID'], 1, -1) . ';' . $_SERVER['SERVER_NAME'] . ';16.4.5009.816;' . date('Y-m-d H:i:s') . ' UTC;265.1558 ms'); } } }
/** * test record translation */ public function testTranslate() { $oldLocale = Tinebase_Core::get(Tinebase_Core::LOCALE); Tinebase_Core::set(Tinebase_Core::LOCALE, new Zend_Locale('de')); $record = new Tinebase_Record_DummyRecord(array('string' => 'test', 'leadstate' => 'waiting for feedback'), true); $record->translate(); $this->assertEquals('Wartet auf Feedback', $record->leadstate); Tinebase_Core::set(Tinebase_Core::LOCALE, $oldLocale); }
/** * #8380: write a test for saveMyPhone as unprivileged user * https://forge.tine20.org/mantisbt/view.php?id=8380 */ public function testSaveMyPhoneAsUnprivilegedUser() { // first save the phone as privileged user $userPhone = $this->_json->getMyPhone($this->_objects['phone']->getId()); $userPhone['lines'][0]['asteriskline_id']['cfi_mode'] = "number"; $userPhone['lines'][0]['asteriskline_id']['cfi_number'] = "+494949302111"; // try to set a property which should be overwritten again $userPhone['description'] = 'no phone'; $phone = $this->_json->saveMyPhone($userPhone); $this->assertEquals('number', $phone['lines'][0]['asteriskline_id']['cfi_mode']); $this->assertEquals('+494949302111', $phone['lines'][0]['asteriskline_id']['cfi_number']); $this->assertEquals('user phone', $phone['description']); $additionalLine = array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => $this->_objects['sippeer']->getId(), 'linenumber' => 2, 'lineactive' => 2); // use another user which doesn't have access to the phone Tinebase_Core::set(Tinebase_Core::USER, Tinebase_User::getInstance()->getFullUserByLoginName('pwulf')); $e = new Exception('No Exception has been thrown!'); try { $this->_json->saveMyPhone($userPhone); } catch (Exception $e) { } $this->assertEquals('Tinebase_Exception_AccessDenied', get_class($e)); // try to save with a line removed Tinebase_Core::set(Tinebase_Core::USER, $this->_adminUser); $snomLineBackend = new Voipmanager_Backend_Snom_Line(); $snomLineBackend->create(new Voipmanager_Model_Snom_Line($additionalLine)); $userPhone = $this->_json->getMyPhone($this->_objects['phone']->getId()); unset($userPhone['lines'][1]); $this->setExpectedException('Tinebase_Exception_AccessDenied'); $this->_json->saveMyPhone($userPhone); }
/** * 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()); }
/** * prompts for a username to set as active user on performing updates. this must be an admin user. * the user account will be returned. this method can be called by cli only, so a exception will * be thrown if not running on cli * * @throws Tinebase_Exception * @return Tinebase_Model_FullUser */ public function promptForUsername() { if (php_sapi_name() == 'cli') { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Prompting for username on CLI'); } $userFound = NULL; do { try { if ($userFound === FALSE) { echo PHP_EOL; echo 'The user could not be found!' . PHP_EOL . PHP_EOL; } $user = Tinebase_Server_Cli::promptInput('Please enter an admin username to perform updates '); $userAccount = Tinebase_User::getInstance()->getFullUserByLoginName($user); if (!$userAccount->hasRight('Tinebase', Tinebase_Acl_Rights::ADMIN)) { $userFound = NULL; echo PHP_EOL; echo 'The user "' . $user . '" could be found, but this is not an admin user!' . PHP_EOL . PHP_EOL; } else { Tinebase_Core::set(Tinebase_Core::USER, $userAccount); $userFound = TRUE; } } catch (Tinebase_Exception_NotFound $e) { $userFound = FALSE; } } while (!$userFound); } else { throw new Setup_Exception_PromptUser('no CLI call'); } return $userAccount; }
/** * sets download link owner (creator) as current user to ensure ACL handling * * @param Filemanager_Model_DownloadLink $download */ protected function _setDownloadLinkOwnerAsUser(Filemanager_Model_DownloadLink $download) { $user = Tinebase_User::getInstance()->getFullUserById($download->created_by); Tinebase_Core::set(Tinebase_Core::USER, $user); }
/** * update credential cache * * @param string $loginName * @param string $password */ protected function _updateCredentialCache($loginName, $password) { $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($loginName, $password); Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache); }
/** * 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 user credential cache * * - fires Tinebase_Event_User_ChangeCredentialCache * * @param string $password * @return array */ public function updateCredentialCache($password) { $oldCredentialCache = Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE); $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials(Tinebase_Core::getUser()->accountLoginName, $password); Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache); $success = $this->_setCredentialCacheCookie(); if ($success) { // close session to allow other requests Zend_Session::writeClose(true); $event = new Tinebase_Event_User_ChangeCredentialCache($oldCredentialCache); Tinebase_Event::fireEvent($event); } return array('success' => $success); }
/** * execute the action * * @param string $job * @todo make self::EXECUTION_METHOD_EXEC_CLI working */ protected function _executeAction($job) { // execute in subprocess if ($this->_getConfig()->tine20->executionMethod === self::EXECUTION_METHOD_EXEC_CLI) { $output = system('php $paths ./../../tine20.php --method Tinebase.executeQueueJob message=' . escapeshellarg($job), $exitCode); if (exitCode != 0) { throw new Exception('Problem during execution with shell: ' . $output); } // execute in same process } else { Tinebase_Core::initFramework(); Tinebase_Core::set(Tinebase_Core::USER, Tinebase_User::getInstance()->getFullUserById($job['account_id'])); Tinebase_ActionQueue::getInstance()->executeAction($job); } }