/**
  * the singleton pattern
  *
  * @return Admin_Controller_User
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Admin_Controller_User();
     }
     return self::$_instance;
 }
 /**
  * init/create user contacts
  */
 protected function _initializeUserContacts()
 {
     foreach (Tinebase_User::getInstance()->getFullUsers() as $fullUser) {
         $fullUser->container_id = $this->_getInternalAddressbook()->getId();
         $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($fullUser);
         $fullUser->contact_id = $contact->getId();
         Tinebase_User::getInstance()->updateUser($fullUser);
     }
 }
 /**
  * set controller
  */
 protected function _setController()
 {
     switch ($this->_options['model']) {
         case 'Tinebase_Model_FullUser':
             $this->_controller = Admin_Controller_User::getInstance();
             break;
         default:
             throw new Tinebase_Exception_InvalidArgument(get_class($this) . ' needs correct model in config.');
     }
 }
 /**
  * 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;
 }
 /**
  * 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";
         }
     }
 }
 /**
  * get user contact id
  * - NOTE: creates a new user contact on the fly if it did not exist before
  * 
  * @return string
  */
 public static function getCurrentUserContactId()
 {
     if (empty(Tinebase_Core::getUser()->contact_id)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating user contact for ' . Tinebase_Core::getUser()->accountDisplayName . ' on the fly ...');
         $contact = Admin_Controller_User::getInstance()->createOrUpdateContact(Tinebase_Core::getUser());
         Tinebase_Core::getUser()->contact_id = $contact->getId();
         Tinebase_User::getInstance()->updateUserInSqlBackend(Tinebase_Core::getUser());
     }
     return Tinebase_Core::getUser()->contact_id;
 }
예제 #7
0
 public function testAttendeeGroupMembersAddUser()
 {
     try {
         // clenup if exists
         $cleanupUser = Tinebase_User::getInstance()->getFullUserByLoginName('testAttendeeGroupMembersAddUser');
         Tinebase_User::getInstance()->deleteUser($cleanupUser);
     } catch (Exception $e) {
         // do nothing
     }
     $defaultGroup = Tinebase_Group::getInstance()->getDefaultGroup();
     // create event and invite admin group
     $event = $this->_getEvent();
     // only events in future will be changed!
     $event->dtstart = Tinebase_DateTime::now()->addHour(1);
     $event->dtend = Tinebase_DateTime::now()->addHour(2);
     $event->attendee = $this->_getAttendee();
     $event->attendee[1] = new Calendar_Model_Attender(array('user_id' => $defaultGroup->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_GROUP, 'role' => Calendar_Model_Attender::ROLE_REQUIRED));
     $persistentEvent = $this->_controller->create($event);
     // create a new user
     $newUser = Admin_Controller_User::getInstance()->create(new Tinebase_Model_FullUser(array('accountLoginName' => 'testAttendeeGroupMembersAddUser', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => $defaultGroup->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')), Zend_Registry::get('testConfig')->password, Zend_Registry::get('testConfig')->password);
     // check if this user was added to event
     $loadedEvent = $this->_controller->get($persistentEvent->getId());
     $user = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $newUser->contact_id);
     $this->assertEquals(1, count($user), 'added user is not attender of event, but should be');
     // cleanup user
     Admin_Controller_User::getInstance()->delete($newUser->getId());
     // check if user was removed from event
     $loadedEvent = $this->_controller->get($persistentEvent->getId());
     $user = $loadedEvent->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $newUser->contact_id);
     $this->assertEquals(0, count($user), 'added user is attender of event, but should be');
 }
 /**
  * @see 0011192: LDAP sync should delete contacts
  */
 public function testSyncDeleted()
 {
     $user = $this->testAddUser();
     // add user contact
     $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user);
     $user->contact_id = $contact->getId();
     Tinebase_User::getInstance()->updateUser($user);
     // delete user in ldap
     Tinebase_User::getInstance()->deleteUserInSyncBackend($user->getId());
     // check if still in tine20 db
     $sqlUser = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $user->getId());
     $this->assertEquals($user->getId(), $sqlUser->getId());
     // set sync config/option + start user sync
     $syncOptions = array('deleteUsers' => true);
     Tinebase_User::syncUsers($syncOptions);
     $now = Tinebase_DateTime::now();
     $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $user->getId(), 'Tinebase_Model_FullUser');
     $this->assertTrue($now->isLaterOrEquals($user->accountExpires), 'user should be expired');
     sleep(1);
     Tinebase_User::syncUsers($syncOptions);
     $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $user->getId(), 'Tinebase_Model_FullUser');
     $this->assertTrue($now->toString() == $user->accountExpires->toString() || $now->subSecond(1)->toString() == $user->accountExpires->toString(), 'expiry date should still be the same');
     // set expired to -1 year -> user should be deleted
     $user->accountExpires = $now->subYear(1);
     Tinebase_User::getInstance()->updateUserInSqlBackend($user);
     // sync again
     sleep(1);
     Tinebase_User::syncUsers($syncOptions);
     // check if user is deleted in tine, too
     try {
         Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $user->getId());
         $this->fail('user should be deleted from tine20 db');
     } catch (Tinebase_Exception_NotFound $tenf) {
         $this->assertContains('User with accountId = ' . $sqlUser->getId(), $tenf->getMessage());
     }
     // check if user contact is deleted, too
     try {
         Addressbook_Controller_Contact::getInstance()->get($sqlUser->contact_id);
         $this->fail('user contact should be deleted from tine20 db');
     } catch (Tinebase_Exception_NotFound $tenf) {
         $this->assertContains('Addressbook_Model_Contact record with id = ' . $sqlUser->contact_id, $tenf->getMessage());
     }
 }
 /**
  * test set expired status
  */
 public function testSetUserExpiredStatus()
 {
     $userArray = $this->testSaveAccount();
     $result = Admin_Controller_User::getInstance()->setAccountStatus($userArray['accountId'], Tinebase_Model_User::ACCOUNT_STATUS_EXPIRED);
     $this->assertEquals(1, $result);
 }
 protected function _createNewUser()
 {
     $pw = Tinebase_Record_Abstract::generateUID(10) . '*A53x';
     $newUser = Admin_Controller_User::getInstance()->create(new Tinebase_Model_FullUser(array('accountLoginName' => 'testAttendeeGroupMembersAddUser', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getDefaultGroup()->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')), $pw, $pw);
     return $newUser;
 }
 /**
  * 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' => '*****@*****.**'));
     $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);
 }
 /**
  * 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());
 }
 /**
  * sync user data to contact
  * 
  * @param Tinebase_Model_FullUser $user
  * @param Addressbook_Model_Contact $contact
  * @return Addressbook_Model_Contact
  */
 protected static function _user2Contact($user, $contact = null)
 {
     if ($contact === null) {
         $contact = new Addressbook_Model_Contact(array(), true);
     }
     $contact->type = Addressbook_Model_Contact::CONTACTTYPE_USER;
     foreach (self::$_contact2UserMapping as $contactKey => $userKey) {
         if (!empty($contact->{$contactKey}) && $contact->{$contactKey} == $user->{$userKey}) {
             continue;
         }
         switch ($contactKey) {
             case 'container_id':
                 $contact->container_id = !empty($user->container_id) ? $user->container_id : Admin_Controller_User::getInstance()->getDefaultInternalAddressbook();
                 break;
             default:
                 $contact->{$contactKey} = $user->{$userKey};
         }
     }
     return $contact;
 }
 /**
  * try to delete self
  */
 public function testDeleteSelf()
 {
     $this->markTestSkipped('TODO make this test independent');
     $this->setExpectedException('Tinebase_Exception_AccessDenied');
     Admin_Controller_User::getInstance()->delete(Tinebase_Core::getUser()->getId());
 }
 /**
  * reinstall applications
  * and reset Demodata
  * php setup.php --reset_demodata USERNAME
  * 
  * @param Zend_Console_Getopt $_opts
  */
 protected function _resetDemodata(Zend_Console_Getopt $_opts)
 {
     $controller = Setup_Controller::getInstance();
     $userController = Admin_Controller_User::getInstance();
     $containerController = Tinebase_Container::getInstance();
     $cli = new Tinebase_Frontend_Cli();
     //Don't reset this applications
     $fixedApplications = array('Tinebase', 'Admin', 'Addressbook');
     //Log in
     $opts = $_opts->getRemainingArgs();
     $username = $opts[0];
     if (empty($username)) {
         echo "Username is missing!\n";
         exit;
     }
     $user = Tinebase_User::getInstance()->getUserByLoginName($username);
     Tinebase_Core::set(Tinebase_Core::USER, $user);
     //get all applications and remove some
     $applications = Tinebase_Application::getInstance()->getApplications(NULL, 'id');
     foreach ($applications as $key => &$application) {
         if (in_array($application, $fixedApplications)) {
             unset($applications[$key]);
         }
     }
     //get set rights
     $users = Tinebase_Acl_Roles::getInstance()->getRoleByName('user role');
     $rights = Tinebase_Acl_Roles::getInstance()->getRoleRights($users->getId());
     //Uninstall Applications
     try {
         $controller->uninstallApplications($applications->name);
         echo "Successfully uninstalled " . count($applications) . " applications.\n";
     } catch (Tinebase_Exception_NotFound $e) {
     }
     //Install Applications
     try {
         $controller->installApplications($applications->name);
         echo "Successfully installed " . count($applications) . " applications.\n";
     } catch (Tinebase_Exception_NotFound $e) {
     }
     //set rights
     foreach ($applications as &$application) {
         $newApplicationId = Tinebase_Application::getInstance()->getApplicationByName($application->name)->getId();
         foreach ($rights as &$right) {
             if ($right['application_id'] == $application->id) {
                 $right['application_id'] = $newApplicationId;
             }
         }
     }
     Tinebase_Acl_Roles::getInstance()->setRoleRights($users->getId(), $rights);
     echo "Successfully restored user rights.\n";
     //Clean up addressbooks
     $internalContacts = $userController->getDefaultInternalAddressbook();
     $containers = $containerController->getAll();
     foreach ($containers as $key => &$container) {
         if ($container->id == $internalContacts) {
             // Do nothing
         } else {
             try {
                 $containerController->deleteContainer($container, true);
             } catch (Tinebase_Exception_NotFound $e) {
             }
         }
     }
     echo "Successfully cleand up containers.\n";
     //remove state
     $db = Tinebase_Core::getDb();
     $statement = "TRUNCATE TABLE " . $db->quoteIdentifier(SQL_TABLE_PREFIX . 'state');
     $db->query($statement);
     echo "Successfully truncated state table.\n";
     //Get Demodata
     $cli->createAllDemoData();
     //clear Cache
     Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL);
     echo "Successfully cleared Cache.\n";
     echo "Every thing done!\n";
 }
예제 #16
0
 /**
  * inits (adds) some test users
  *
  */
 public function initTestUsers()
 {
     $personas = array('jsmith' => 'John Smith', 'sclever' => 'Susan Clever', 'pwulf' => 'Paul Wulf', 'jmcblack' => 'James McBlack', 'rwright' => 'Roberta Wright');
     foreach ($personas as $login => $fullName) {
         try {
             $user = Tinebase_User::getInstance()->getFullUserByLoginName($login);
         } catch (Tinebase_Exception_NotFound $e) {
             list($given, $last) = explode(' ', $fullName);
             $group = Tinebase_Group::getInstance()->getGroupByName('Users');
             $groupId = $group->getId();
             $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@tine20.org'));
             if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
                 $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED);
                 $user->container_id = $internalAddressbook->getId();
                 $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user);
                 $user->contact_id = $contact->getId();
             }
             $user = Tinebase_User::getInstance()->addUser($user);
             Tinebase_Group::getInstance()->addGroupMember($groupId, $user);
             if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
                 $listBackend = new Addressbook_Backend_List();
                 $listBackend->addListMember($group->list_id, $user->contact_id);
             }
             // give additional testusers the same password as the primary test account
             Tinebase_User::getInstance()->setPassword($user, Zend_Registry::get('testConfig')->password);
         }
         $personas[$login] = $user;
     }
     Zend_Registry::set('personas', $personas);
 }
 /**
  * testAttendeeGroupMembersRecurringAddUser
  * 
  * FIXME 0007352: fix Calendar_Controller_EventTests::testAttendeeGroupMembersRecurringAddUser
  */
 public function testAttendeeGroupMembersRecurringAddUser()
 {
     $this->markTestIncomplete('test fails sometimes / needs fixing');
     try {
         // cleanup if exists
         $cleanupUser = Tinebase_User::getInstance()->getFullUserByLoginName('testAttendeeGroupMembersAddUser');
         Tinebase_User::getInstance()->deleteUser($cleanupUser);
     } catch (Exception $e) {
         // do nothing
     }
     $defaultGroup = Tinebase_Group::getInstance()->getDefaultGroup();
     // create event and invite admin group
     $event = $this->_getEvent();
     $event->rrule = 'FREQ=DAILY;INTERVAL=1';
     $event->attendee = $this->_getAttendee();
     $event->attendee[1] = new Calendar_Model_Attender(array('user_id' => $defaultGroup->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_GROUP, 'role' => Calendar_Model_Attender::ROLE_REQUIRED));
     $persistentEvent = $this->_controller->create($event);
     // create a new user
     $newUser = Admin_Controller_User::getInstance()->create(new Tinebase_Model_FullUser(array('accountLoginName' => 'testAttendeeGroupMembersAddUser', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => $defaultGroup->getId(), 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**')), Zend_Registry::get('testConfig')->password, Zend_Registry::get('testConfig')->password);
     if (isset(Tinebase_Core::getConfig()->actionqueue)) {
         Tinebase_ActionQueue::getInstance()->processQueue(10000);
     }
     $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_getTestCalendars()->getId()))), new Tinebase_Model_Pagination(array()));
     $oldSeries = $events->filter('rrule_until', '/.+/', TRUE)->getFirstRecord();
     $newSeries = $events->filter('rrule_until', '/^$/', TRUE)->getFirstRecord();
     $this->assertEquals(2, $events->count(), 'recur event must be splitted ' . print_r($events->toArray(), TRUE));
     // check if this user was added to event
     $this->_controller->get($persistentEvent->getId());
     $user = $oldSeries->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $newUser->contact_id);
     $this->assertEquals(0, count($user), 'added user is attender of old event, but should not be');
     $user = $newSeries->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $newUser->contact_id);
     $this->assertEquals(1, count($user), 'added user is not attender of new event, but should be');
     // cleanup user
     Admin_Controller_User::getInstance()->delete($newUser->getId());
     if (isset(Tinebase_Core::getConfig()->actionqueue)) {
         Tinebase_ActionQueue::getInstance()->processQueue(10000);
     }
     $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_getTestCalendars()->getId()))), new Tinebase_Model_Pagination(array()));
     $newSeries = $events->filter('rrule_until', '/^$/', TRUE)->getFirstRecord();
     // check if this user was deleted from event
     $user = $newSeries->attendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)->filter('user_id', $newUser->contact_id);
     $this->assertEquals(0, count($user), 'deleted user is attender of new event, but should not be');
 }
 /**
  * testHiddenMembers
  * 
  * @see 0007122: hide hidden users from lists
  */
 public function testHiddenMembers()
 {
     $group = new Tinebase_Model_Group(array('name' => 'testgroup', 'description' => 'test group', 'visibility' => Tinebase_Model_Group::VISIBILITY_DISPLAYED));
     $group = Admin_Controller_Group::getInstance()->create($group);
     $this->_groupIdsToDelete[] = $group->getId();
     $list = $this->_instance->get($group->list_id);
     $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
     $list->members = array($sclever->contact_id);
     $list = $this->_instance->update($list);
     // hide sclever
     $sclever->visibility = Tinebase_Model_User::VISIBILITY_HIDDEN;
     Admin_Controller_User::getInstance()->update($sclever, NULL, NULL);
     // fetch list and check hidden members
     $listGet = $this->_instance->get($list->getId());
     $listSearch = $this->_instance->search(new Addressbook_Model_ListFilter(array(array('field' => 'id', 'operator' => 'in', 'value' => array($list->getId())))))->getFirstRecord();
     $listGetMultiple = $this->_instance->getMultiple(array($list->getId()))->getFirstRecord();
     foreach (array('get' => $listGet, 'search' => $listSearch, 'getMultiple' => $listGetMultiple) as $fn => $listRecord) {
         $this->assertTrue($listRecord instanceof Addressbook_Model_List, $fn . ' did not return a list: ' . var_export($listRecord, TRUE));
         $this->assertEquals(0, count($listRecord->members), 'Hidden sclever should not appear in list members returned by ' . $fn . '(): ' . print_r($listRecord->toArray(), TRUE));
     }
 }
예제 #19
0
 /**
  * try to delete self
  */
 public function testDeleteSelf()
 {
     $this->setExpectedException('Tinebase_Exception_Record_NotAllowed');
     Admin_Controller_User::getInstance()->delete(Tinebase_Core::getUser()->getId());
 }
 /**
  * testSyncLists
  * 
  * @see 0005768: create addressbook lists when migrating users
  * 
  * @todo make this work for LDAP accounts backend: currently the user is not present in sync backend but in sql
  */
 public function testSyncLists()
 {
     if (Tinebase_Group::getInstance() instanceof Tinebase_Group_Ldap) {
         $this->markTestSkipped('@todo make this work for LDAP accounts backend');
     }
     $testGroup = $this->testAddGroup();
     // don't use any existing persona here => will break other tests
     $testUser = new Tinebase_Model_FullUser(array('accountLoginName' => Tinebase_Record_Abstract::generateUID(), 'accountPrimaryGroup' => $testGroup->getId(), 'accountDisplayName' => Tinebase_Record_Abstract::generateUID(), 'accountLastName' => Tinebase_Record_Abstract::generateUID(), 'accountFullName' => Tinebase_Record_Abstract::generateUID(), 'visibility' => Tinebase_Model_User::VISIBILITY_DISPLAYED));
     $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($testUser);
     $testUser->contact_id = $contact->getId();
     $testUser = Tinebase_User::getInstance()->addUserInSqlBackend($testUser);
     Tinebase_User::createContactForSyncedUser($testUser);
     Tinebase_User::getInstance()->updateUserInSqlBackend($testUser);
     $this->testSetGroupMembers($testGroup, array($testUser->accountId));
     Tinebase_Group::syncListsOfUserContact(array($testGroup->getId()), $testUser->contact_id);
     $group = Tinebase_Group::getInstance()->getGroupById($testGroup);
     $this->assertTrue(!empty($group->list_id), 'list id empty: ' . print_r($group->toArray(), TRUE));
     $list = Addressbook_Controller_List::getInstance()->get($group->list_id);
     $this->assertEquals($group->getId(), $list->group_id);
     $this->assertEquals($group->name, $list->name);
     $this->assertTrue(!empty($list->members), 'list members empty: ' . print_r($list->toArray(), TRUE) . ' should contain: ' . print_r($testUser->toArray(), TRUE));
     $this->assertContains($testUser->contact_id, $list->members);
     $appConfigDefaults = Admin_Controller::getInstance()->getConfigSettings();
     $this->assertTrue(!empty($appConfigDefaults), 'app config defaults empty');
     $internal = $appConfigDefaults[Admin_Model_Config::DEFAULTINTERNALADDRESSBOOK];
     $this->assertEquals($internal, $list->container_id, 'did not get correct internal container');
     // sync again -> should not change anything
     Tinebase_Group::syncListsOfUserContact(array($group->getId()), $testUser->contact_id);
     $listAgain = Addressbook_Controller_List::getInstance()->get($group->list_id);
     $this->assertEquals($list->toArray(), $listAgain->toArray());
     // change list id -> should get list by (group) name
     $group->list_id = NULL;
     $group = Tinebase_Group::getInstance()->updateGroup($group);
     Tinebase_Group::syncListsOfUserContact(array($group->getId()), $testUser->contact_id);
     $this->assertEquals($list->getId(), Tinebase_Group::getInstance()->getGroupById($group)->list_id);
 }
예제 #21
0
 /**
  * returns multiple records prepared for json transport
  *
  * @param Tinebase_Record_RecordSet $_records Tinebase_Record_Abstract
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @return array data
  */
 protected function _multipleRecordsToJson(Tinebase_Record_RecordSet $_records, $_filter = NULL)
 {
     switch ($_records->getRecordClassName()) {
         case 'Tinebase_Model_AccessLog':
             // TODO use _resolveUserFields and remove this
             foreach ($_records as $record) {
                 if (!empty($record->account_id)) {
                     try {
                         $record->account_id = Admin_Controller_User::getInstance()->get($record->account_id)->toArray();
                     } catch (Tinebase_Exception_NotFound $e) {
                         $record->account_id = Tinebase_User::getInstance()->getNonExistentUser('Tinebase_Model_FullUser')->toArray();
                     }
                 }
             }
             break;
         case 'Tinebase_Model_Container':
         case 'Tinebase_Model_CustomField_Config':
             $applications = Tinebase_Application::getInstance()->getApplications();
             foreach ($_records as $record) {
                 $idx = $applications->getIndexById($record->application_id);
                 if ($idx !== FALSE) {
                     $record->application_id = $applications[$idx];
                 }
             }
             break;
     }
     $result = parent::_multipleRecordsToJson($_records, $_filter);
     return $result;
 }
 /**
  * @see Tinebase_Setup_DemoData_Abstract
  */
 protected function _beforeCreate()
 {
     $be = new Addressbook_Backend_Sql();
     foreach ($this->_personas as $login => $fullName) {
         try {
             $user = Tinebase_User::getInstance()->getFullUserByLoginName($login);
             $contact = Addressbook_Controller_Contact::getInstance()->get($user->contact_id);
         } catch (Tinebase_Exception_NotFound $e) {
             list($given, $last) = explode(' ', $fullName);
             $group = Tinebase_Group::getInstance()->getGroupByName('Users');
             $groupId = $group->getId();
             $emailDomain = $this->_getMailDomain();
             $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@' . $emailDomain));
             if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
                 $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED);
                 $user->container_id = $internalAddressbook->getId();
                 $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user);
                 $user->contact_id = $contact->getId();
             }
             Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create');
             $user = Tinebase_User::getInstance()->addUser($user);
             Tinebase_Group::getInstance()->addGroupMember($groupId, $user);
             if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
                 $listBackend = new Addressbook_Backend_List();
                 $listBackend->addListMember($group->list_id, $user->contact_id);
             }
             $this->_setUserPassword($user);
         }
         if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
             $ar = array_merge($this->_dataMapping[$login], $this->_dataMapping['default']);
             $filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DemoData' . DIRECTORY_SEPARATOR . 'persona_' . $login . '.jpg';
             if (file_exists($filename)) {
                 $handle = fopen($filename, "r");
                 $content = fread($handle, filesize($filename));
                 fclose($handle);
                 $be->_saveImage($contact->getId(), $content);
             }
             foreach ($ar as $property => $value) {
                 $contact->{$property} = $value;
             }
             Addressbook_Controller_Contact::getInstance()->update($contact);
         }
         $this->_personas[$login] = $user;
     }
     $this->_createGroups();
     $this->_createRoles();
     $this->_createSharedTags();
 }
예제 #23
0
 /**
  * Deletes a set of records.
  * 
  * If one of the records could not be deleted, no record is deleted
  * 
  * @param   array array of record identifiers
  * @return  void
  * @throws Tinebase_Exception_NotFound|Tinebase_Exception
  */
 public function delete($_ids)
 {
     $courses = $this->getMultiple($_ids);
     $groupController = Admin_Controller_Group::getInstance();
     $userController = Admin_Controller_User::getInstance();
     $groupsToDelete = array();
     $usersToDelete = array();
     foreach ($courses as $course) {
         $groupsToDelete[] = $course->group_id;
         $usersToDelete = array_merge($usersToDelete, $groupController->getGroupMembers($course->group_id));
     }
     Courses_Controller::getInstance()->suspendEvents();
     $userController->delete(array_unique($usersToDelete));
     $groupController->delete(array_unique($groupsToDelete));
     Courses_Controller::getInstance()->resumeEvents();
     parent::delete($_ids);
 }
 /**
  * try to get all access log entries
  */
 public function testGetAccessLogsWithDeletedUser()
 {
     $clienttype = 'Unittest';
     $user = $this->testSaveAccount();
     $this->_addAccessLog(new Tinebase_Model_FullUser($user), $clienttype);
     Admin_Controller_User::getInstance()->delete($user['accountId']);
     $accessLogs = $this->_json->searchAccessLogs($this->_getAccessLogFilter($user['accountLoginName'], $clienttype), array());
     $this->assertGreaterThan(0, sizeof($accessLogs['results']));
     $this->assertGreaterThan(0, $accessLogs['totalcount']);
     $testLogEntry = $accessLogs['results'][0];
     $this->assertEquals(Tinebase_User::getInstance()->getNonExistentUser()->accountDisplayName, $testLogEntry['account_id']['accountDisplayName']);
     $this->assertEquals($clienttype, $testLogEntry['clienttype']);
     $this->_json->deleteAccessLogs(array($testLogEntry['id']));
 }
예제 #25
0
 /**
  * creates/updates a record
  *
  * @todo move non api specific stuff to controller!
  * 
  * @param  array $recordData
  * @return array created/updated record
  */
 public function saveCourse($recordData)
 {
     // create course and group from json data
     $course = new Courses_Model_Course(array(), TRUE);
     $course->setFromJsonInUsersTimezone($recordData);
     $group = new Tinebase_Model_Group(array(), TRUE);
     $group->setFromJsonInUsersTimezone($recordData);
     $i18n = Tinebase_Translation::getTranslation('Courses');
     $groupNamePrefix = $i18n->_('Course');
     $groupNamePrefix = is_array($groupNamePrefix) ? $groupNamePrefix[0] : $groupNamePrefix;
     $group->name = $groupNamePrefix . '-' . $course->name;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($group->toArray(), true));
     }
     if (empty($group->id)) {
         $savedGroup = $this->_groupController->create($group);
         $course->group_id = $savedGroup->getId();
         $savedRecord = $this->_controller->create($course);
     } else {
         $savedRecord = $this->_controller->update($course);
         $currentMembers = $this->_groupController->getGroupMembers($course->group_id);
         $newCourseMembers = array_diff((array) $group->members, $currentMembers);
         $this->_controller->addCourseMembers($course, $newCourseMembers);
         $deletedAccounts = array_diff($currentMembers, (array) $group->members);
         // delete members wich got removed from course
         Admin_Controller_User::getInstance()->delete($deletedAccounts);
     }
     // add/remove members to/from internet/fileserver group
     if (!empty($group->members)) {
         $this->_manageAccessGroups($group->members, $savedRecord->internet, 'internet');
         $this->_manageAccessGroups($group->members, $savedRecord->fileserver, 'fileserver');
     }
     return $this->_recordToJson($savedRecord);
 }