Example #1
0
 /**
  * saves and returns container
  * 
  * @param string $_type
  * @return array
  */
 protected function _saveContainer($_type = Tinebase_Model_Container::TYPE_SHARED)
 {
     $data = array('name' => 'testcontainer', 'type' => $_type, 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId());
     $container = $this->_json->saveContainer($data);
     $this->objects['container'] = $container['id'];
     $this->assertEquals($data['name'], $container['name']);
     return $container;
 }
 /**
  * @see 0011504: deactivated user is removed from group when group is saved
  */
 public function testBlockedUserGroupSave()
 {
     // deactivate user
     $userArray = $this->testSaveAccount();
     $userArray['lastLoginFailure'] = Tinebase_DateTime::now()->toString();
     $userArray['loginFailures'] = 10;
     // save group
     // TODO generalize
     $group = Tinebase_Group::getInstance()->getGroupByName('tine20phpunit');
     $groupArray = $this->_json->getGroup($group->getId());
     $this->assertEquals(1, $groupArray['groupMembers']['totalcount']);
     $groupArray['container_id'] = $groupArray['container_id']['id'];
     $savedGroup = $this->_json->saveGroup($groupArray, array($userArray['accountId']));
     // check group memberships
     $this->assertEquals(1, $savedGroup['groupMembers']['totalcount']);
 }
 /**
  * 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' => 'unittestx8@tine20.org'));
     $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());
 }
 /**
  * Check for smtp domains in registry
  *
  * @see 0010305: Undefined value in user edit dialog
  */
 public function testRegistryForSMTP()
 {
     $smtpConfig = Tinebase_EmailUser::getConfig(Tinebase_Config::SMTP);
     $primaryDomainConfig = Tinebase_EmailUser::manages(Tinebase_Config::SMTP) && isset($smtpConfig['primarydomain']) ? $smtpConfig['primarydomain'] : '';
     $secondaryDomainConfig = Tinebase_EmailUser::manages(Tinebase_Config::SMTP) && isset($smtpConfig['secondarydomains']) ? $smtpConfig['secondarydomains'] : '';
     $afj = new Admin_Frontend_Json();
     $registryData = $afj->getRegistryData();
     $this->assertEquals($registryData['primarydomain'], $primaryDomainConfig);
     $this->assertEquals($registryData['secondarydomains'], $secondaryDomainConfig);
 }
 /**
  * create roles
  */
 protected function _createRoles()
 {
     $fe = new Admin_Frontend_Json();
     foreach ($this->_roles as $roleArray) {
         // resolve members
         $members = array();
         foreach ($roleArray['roleMembers'] as &$member) {
             $member['id'] = $this->_groups[$member['name']]['id'];
             unset($member['name']);
         }
         // resolve rights
         $roleRights = array();
         foreach ($roleArray['roleRights'] as $application => $rights) {
             try {
                 $appId = Tinebase_Application::getInstance()->getApplicationByName($application)->getId();
                 foreach ($rights as $rightName) {
                     $roleRights[] = array('application_id' => $appId, 'right' => $rightName);
                 }
             } catch (Exception $e) {
                 echo 'Application "' . $application . '" not installed. Skipping...' . PHP_EOL;
             }
         }
         try {
             $result = $fe->saveRole($roleArray['roleData'], $roleArray['roleMembers'], $roleRights);
         } catch (Exception $e) {
             echo 'Role "' . $roleArray['roleData']['name'] . '" already exists. Skipping...' . PHP_EOL;
         }
     }
 }
 /**
  * reset password for given account
  * - call Admin_Frontend_Json::resetPassword()
  *
  * @param  array   $account data of Tinebase_Model_FullUser or account id
  * @param  string  $password the new password
  * @param  bool    $mustChange
  * @return array
  */
 public function resetPassword($account, $password, $mustChange)
 {
     $password = $this->_controller->getStudentPassword($password);
     $adminJson = new Admin_Frontend_Json();
     return $adminJson->resetPassword($account, $password, (bool) $mustChange);
 }
 /**
  * test if a user, who has no manage_invoices - right, is able tosave a timeaccount having an invoice linked
  */
 public function testUpdateInvoiceLinkedTimeaccount()
 {
     $this->markTestSkipped('0010492: fix failing invoices and timetracker tests');
     $ta = $this->_getTimeaccount(array('title' => 'to find'), true);
     $cc = Sales_Controller_CostCenter::getInstance()->create(new Sales_Model_CostCenter(array('number' => 1, 'title' => 'test')));
     $customer = Sales_Controller_Customer::getInstance()->create(new Sales_Model_Customer(array('number' => 100, 'name' => 'test', 'description' => 'unittest', 'credit_term' => 1)));
     $address = Sales_Controller_Address::getInstance()->create(new Sales_Model_Address(array('street' => 'teststreet', 'locality' => 'testcity', 'customer_id' => $customer->id, 'postalcode' => 12345)));
     $invoice = Sales_Controller_Invoice::getInstance()->create(new Sales_Model_Invoice(array('description' => 'test', 'address_id' => $address->id, 'date' => Tinebase_DateTime::now(), 'credit_term' => 1, 'type' => 'INVOICE', 'start_date' => Tinebase_DateTime::now(), 'end_date' => Tinebase_DateTime::now()->addMonth(1), 'costcenter_id' => $cc->id)));
     Tinebase_Relations::getInstance()->setRelations('Sales_Model_Invoice', 'Sql', $invoice->id, array(array('related_id' => $ta->id, 'related_model' => 'Timetracker_Model_Timeaccount', 'related_record' => $ta, 'own_degree' => 'sibling', 'type' => 'INVOICE')));
     // 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' => 'unittestx8@tine20.org'));
     $user = Admin_Controller_User::getInstance()->create($user, 'pw', 'pw');
     // add tt-ta admin right to user role to allow user to update (manage) timeaccounts
     // user has no right to see sales contracts
     $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('Timetracker');
     $roleRights['results'][] = array('application_id' => $app->getId(), 'right' => Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS);
     $roleRights['results'][] = array('application_id' => $app->getId(), 'right' => Tinebase_Acl_Rights::ADMIN);
     $fe->saveRole($userRole, $roleMembers['results'], $roleRights['results']);
     // switch to other user
     $this->_testUser = Tinebase_Core::getUser();
     Tinebase_Core::set(Tinebase_Core::USER, $user);
     $ta = $this->_json->getTimeaccount($ta->id);
     $this->assertTrue(empty($ta['relations']), 'relations are not empty: ' . print_r($ta['relations'], true));
     // this must be possible
     $ta = $this->_json->saveTimeaccount($ta);
     Tinebase_Core::set(Tinebase_Core::USER, $this->_testUser);
     $ta = $this->_json->getTimeaccount($ta['id']);
     $this->assertTrue(count($ta['relations']) == 1);
 }
Example #8
0
 /**
  * reset password for given account
  * - call Admin_Frontend_Json::resetPassword()
  *
  * @param  array   $account data of Tinebase_Model_FullUser or account id
  * @param  string  $password the new password
  * @param  bool    $mustChange
  * @return array
  */
 public function resetPassword($account, $password, $mustChange)
 {
     $adminJson = new Admin_Frontend_Json();
     return $adminJson->resetPassword($account, $password, (bool) $mustChange);
 }