Пример #1
0
 /**
  * set up tests
  *
  */
 public function setUp()
 {
     $this->_transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
     $this->_backend = new Calendar_Backend_Sql();
     $this->_personas = Zend_Registry::get('personas');
     foreach ($this->_personas as $loginName => $user) {
         $defaultCalendarId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $user->getId());
         $this->_personasContacts[$loginName] = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId());
         $this->_personasDefaultCals[$loginName] = Tinebase_Container::getInstance()->getContainerById($defaultCalendarId);
     }
     $this->_testUser = Tinebase_Core::getUser();
     $this->_testUserContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId($this->_testUser->getId());
     $this->_testCalendar = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => 'PHPUnit test calendar', 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => $this->_backend->getType(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()), true));
     $this->_testCalendars = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
     $this->_testCalendars->addRecord($this->_testCalendar);
 }
 /**
  * fetch devices for user
  * 
  * @param Tinebase_Model_FullUser $user
  */
 protected function _getDevicesForUser($user)
 {
     $deviceBackend = new ActiveSync_Backend_Device();
     $deviceFilter = new ActiveSync_Model_DeviceFilter(array(array('field' => 'owner_id', 'operator' => 'equals', 'value' => $user->getId())));
     $devices = $deviceBackend->search($deviceFilter);
     return $devices;
 }
Пример #3
0
 protected function _getCalendarVTimezone()
 {
     $timezone = Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::TIMEZONE, $this->_user->getId());
     // create vcalendar object with timezone information
     $vcalendar = new Sabre_VObject_Component('CALENDAR');
     $vcalendar->add(new Sabre_VObject_Component_VTimezone($timezone));
     // Taking out \r to not screw up the xml output
     return str_replace("\r", "", $vcalendar->serialize());
 }
Пример #4
0
 /**
  * import the accounts from eGroupWare 1.4
  *
  * @todo add primary group or use Admin_Controller_User::getInstance()->create
  * @todo import user password
  */
 protected function importAccounts()
 {
     $this->_log->INFO('start importing egw users');
     $select = $this->_egwDb->select()->from(array('accounts' => 'egw_accounts'))->joinLeft(array('contacts' => 'egw_addressbook'), $this->_egwDb->quoteIdentifier('accounts.account_id') . ' = ' . $this->_egwDb->quoteIdentifier('contacts.account_id'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('accounts.account_type') . ' = ?', 'u'));
     $accounts = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_OBJ);
     foreach ($accounts as $account) {
         $user = new Tinebase_Model_FullUser(array('accountId' => $account->account_id, 'accountLoginName' => $account->account_lid, 'accountLastLogin' => $account->account_lastlogin > 0 ? new Tinebase_DateTime($account->account_lastlogin) : NULL, 'accountLastLoginfrom' => $account->account_lastloginfrom, 'accountLastPasswordChange' => $account->account_lastpwd_change > 0 ? new Tinebase_DateTime($account->account_lastpwd_change) : NULL, 'accountStatus' => $account->account_status == 'A' ? 'enabled' : 'disabled', 'accountExpires' => $account->account_expires > 0 ? new Tinebase_DateTime($account->account_expires) : NULL, 'accountPrimaryGroup' => abs($account->account_primary_group), 'accountLastName' => $account->n_family ? $account->n_family : 'Lastname', 'accountFirstName' => $account->n_given ? $account->n_given : 'Firstname', 'accountEmailAddress' => isset($account->email) ? $account->email : $account->contact_email));
         $this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . ' user: '******'accountId', $user->accountId);
             $user = Tinebase_User::getInstance()->updateUser($user);
         } catch (Tinebase_Exception_NotFound $ten) {
             $user = Tinebase_User::getInstance()->addUser($user);
         }
         // (re)set password
         Tinebase_User::getInstance()->setPassword($user, $account->account_pwd, FALSE);
         // plase user in his groups
         Tinebase_Group::getInstance()->addGroupMember($user->accountPrimaryGroup, $user);
     }
     $this->_log->NOTICE('imported ' . count($accounts) . ' users from egw');
 }
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     if ($this->_emailTestClass instanceof Felamimail_Controller_MessageTest) {
         $this->_emailTestClass->tearDown();
     }
     if ($this->_headerValueToDelete !== NULL) {
         $result = $this->_imap->search(array($this->_headerValueToDelete));
         foreach ($result as $messageUid) {
             $this->_imap->removeMessage($messageUid);
         }
     }
     // reset user if changed
     if (is_object($this->_testUser) && Tinebase_Core::getUser()->getId() !== $this->_testUser->getId()) {
         Tinebase_Core::set(Tinebase_Core::USER, $this->_testUser);
     }
 }
 /**
  * create container without sync grant
  * 
  * @return Tinebase_Model_Container
  */
 protected function _getContainerWithoutSyncGrant()
 {
     if (isset($this->objects['container']['withoutSyncGrant'])) {
         return $this->objects['container']['withoutSyncGrant'];
     }
     try {
         $containerWithoutSyncGrant = Tinebase_Container::getInstance()->getContainerByName($this->_applicationName, 'ContainerWithoutSyncGrant-' . $this->_applicationName, Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser());
     } catch (Tinebase_Exception_NotFound $e) {
         $creatorGrants = array('account_id' => $this->_testUser->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);
         $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array($creatorGrants));
         $containerWithoutSyncGrant = new Tinebase_Model_Container(array('name' => 'ContainerWithoutSyncGrant-' . $this->_applicationName, 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName)->getId()));
         $containerWithSyncGrant = Tinebase_Container::getInstance()->addContainer($containerWithoutSyncGrant);
         Tinebase_Container::getInstance()->setGrants($containerWithSyncGrant, $grants, TRUE, FALSE);
     }
     $this->objects['container']['withoutSyncGrant'] = $containerWithoutSyncGrant;
     return $this->objects['container']['withoutSyncGrant'];
 }
 /**
  * Returns the list of properties
  *
  * @param array $requestedProperties
  * @return array
  */
 public function getProperties($requestedProperties)
 {
     $properties = array('{http://calendarserver.org/ns/}getctag' => round(time() / 60), 'id' => 'schedule-inbox', 'uri' => 'schedule-inbox', '{DAV:}resource-id' => 'urn:uuid:schedule-inbox', '{DAV:}owner' => new \Sabre\DAVACL\Property\Principal(Sabre\DAVACL\Property\Principal::HREF, 'principals/users/' . $this->_user->contact_id), '{DAV:}displayname' => 'Schedule Inbox', '{http://apple.com/ns/ical/}calendar-color' => '#666666', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-data' => new \Sabre\CalDAV\Property\SupportedCalendarData(), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-description' => 'Calendar schedule inbox', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-timezone' => Tinebase_WebDav_Container_Abstract::getCalendarVTimezone('Calendar'));
     $defaultCalendarId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $this->_user->getId());
     if (!empty($defaultCalendarId)) {
         $properties['{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-default-calendar-URL'] = new \Sabre\DAV\Property\Href('calendars/' . $this->_user->contact_id . '/' . $defaultCalendarId);
     }
     if (!empty(Tinebase_Core::getUser()->accountEmailAddress)) {
         $properties['{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-user-address-set'] = new \Sabre\DAV\Property\HrefList(array('mailto:' . Tinebase_Core::getUser()->accountEmailAddress), false);
     }
     $response = array();
     foreach ($requestedProperties as $prop) {
         if (isset($properties[$prop])) {
             $response[$prop] = $properties[$prop];
         }
     }
     return $response;
 }
 /**
  * look for user with the same login name
  * 
  * @param Tinebase_Model_FullUser $user
  * @return boolean
  * @throws Tinebase_Exception_SystemGeneric
  */
 protected function _checkLoginNameExistance(Tinebase_Model_FullUser $user)
 {
     try {
         $existing = Tinebase_User::getInstance()->getUserByLoginName($user->accountLoginName);
         if ($user->getId() === NULL || $existing->getId() !== $user->getId()) {
             throw new Tinebase_Exception_SystemGeneric('Login name already exists. Please choose another one.');
         }
     } catch (Tinebase_Exception_NotFound $tenf) {
     }
     return TRUE;
 }
 /**
  * add access log entry
  * 
  * @param Tinebase_Model_FullUser $_user
  * @param String $_clienttype
  */
 protected function _addAccessLog($_user, $_clienttype)
 {
     Tinebase_AccessLog::getInstance()->create(new Tinebase_Model_AccessLog(array('sessionid' => 'test_session_id', 'login_name' => $_user->accountLoginName, 'ip' => '127.0.0.1', 'li' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'result' => Zend_Auth_Result::SUCCESS, 'account_id' => $_user->getId(), 'clienttype' => $_clienttype)));
 }
 /**
  * check if user connected with too many user agent during the last hour
  *
  * @param Tinebase_Model_FullUser  $_user
  * @param int $numberOfAllowedUserAgents
  * @return bool
  */
 protected function _tooManyUserAgents($_user, $numberOfAllowedUserAgents = 3)
 {
     $result = false;
     $db = $this->_backend->getAdapter();
     $dbCommand = Tinebase_Backend_Sql_Command::factory($db);
     $select = $db->select()->distinct(true)->from($this->_backend->getTablePrefix() . $this->_backend->getTableName(), 'user_agent')->where($db->quoteIdentifier('account_id') . ' = ?', $_user->getId())->where($db->quoteIdentifier('li') . ' > NOW() - ' . $dbCommand->getInterval('HOUR', '1'))->where($db->quoteIdentifier('result') . ' <> ?', Tinebase_Auth::SUCCESS, Zend_Db::PARAM_INT)->limit(10);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $select);
     }
     $stmt = $db->query($select);
     if ($stmt->columnCount() > $numberOfAllowedUserAgents) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' More than ' . $numberOfAllowedUserAgents . ' different UserAgents? we don\'t trust you!');
         }
         $result = true;
     }
     $stmt->closeCursor();
     return $result;
 }
Пример #11
0
 /**
  * save user
  *
  * @param  array $recordData data of Tinebase_Model_FullUser
  * @return array  
  */
 public function saveUser($recordData)
 {
     $password = isset($recordData['accountPassword']) ? $recordData['accountPassword'] : '';
     $account = new Tinebase_Model_FullUser();
     // always re-evaluate fullname
     unset($recordData['accountFullName']);
     try {
         $account->setFromArray($recordData);
         if (isset($recordData['sambaSAM'])) {
             $account->sambaSAM = new Tinebase_Model_SAMUser($recordData['sambaSAM']);
         }
         if (isset($recordData['emailUser'])) {
             $account->emailUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->imapUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->smtpUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
         }
     } catch (Tinebase_Exception_Record_Validation $e) {
         // invalid data in some fields sent from client
         $result = array('errors' => $account->getValidationErrors(), 'errorMessage' => 'invalid data for some fields', 'status' => 'failure');
         return $result;
     }
     if ($account->getId() == NULL) {
         if (!Tinebase_User_Registration::getInstance()->checkUniqueUsername($account->accountLoginName)) {
             $result = array('errors' => 'invalid username', 'errorMessage' => 'Username already used.', 'status' => 'failure');
             return $result;
         }
         $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     } else {
         $account = Admin_Controller_User::getInstance()->update($account, $password, $password);
     }
     // after user update or creation add user to selected roles
     if (isset($recordData['accountRoles']) && $recordData['accountRoles']) {
         Tinebase_Acl_Roles::getInstance()->setRoleMemberships(array('id' => $account->accountId, 'type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER), $recordData['accountRoles']);
     }
     $result = $this->_recordToJson($account);
     // add primary group to account for the group selection combo box
     $group = Tinebase_Group::getInstance()->getGroupById($account->accountPrimaryGroup);
     // add user groups
     $userGroups = Tinebase_Group::getInstance()->getMultiple(Tinebase_Group::getInstance()->getGroupMemberships($account->accountId))->toArray();
     // add user roles
     $userRoles = Tinebase_Acl_Roles::getInstance()->getMultiple(Tinebase_Acl_Roles::getInstance()->getRoleMemberships($account->accountId))->toArray();
     // encode the account array
     $result['accountPrimaryGroup'] = $group;
     // encode the groups array
     $result['groups'] = array('results' => $userGroups, 'totalcount' => count($userGroups));
     // encode the roles array
     $result['accountRoles'] = array('results' => $userRoles, 'totalcount' => count($userRoles));
     return $result;
 }
 /**
  * returns array of raw Dovecot data
  *
  * @param  Tinebase_Model_FullUser  $_user
  * @param  Tinebase_Model_FullUser  $_newUserProperties
  * @return array
  */
 protected function _recordToRawData(Tinebase_Model_FullUser $_user, Tinebase_Model_FullUser $_newUserProperties)
 {
     $rawData = array();
     if (isset($_newUserProperties->imapUser)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_newUserProperties->imapUser->toArray(), true));
         }
         foreach ($_newUserProperties->imapUser as $key => $value) {
             $property = isset($this->_propertyMapping[$key]) || array_key_exists($key, $this->_propertyMapping) ? $this->_propertyMapping[$key] : false;
             if ($property && !in_array($key, $this->_readOnlyFields)) {
                 switch ($key) {
                     case 'emailUserId':
                     case 'emailUsername':
                         // do nothing
                         break;
                     case 'emailPassword':
                         $rawData[$property] = Hash_Password::generate($this->_config['emailScheme'], $value);
                         break;
                     case 'emailUID':
                         $rawData[$property] = !empty($this->_config['uid']) ? $this->_config['uid'] : $value;
                         break;
                     case 'emailGID':
                         $rawData[$property] = !empty($this->_config['gid']) ? $this->_config['gid'] : $value;
                         break;
                     case 'emailMailQuota':
                         $rawData[$property] = empty($value) ? 0 : $value;
                         break;
                     default:
                         $rawData[$property] = $value;
                         break;
                 }
             }
         }
     }
     foreach (array('uid', 'gid') as $key) {
         if (!(isset($rawData[$key]) || array_key_exists($key, $rawData))) {
             $rawData[$key] = $this->_config[$key];
         }
     }
     $rawData[$this->_propertyMapping['emailUserId']] = $_user->getId();
     if ($this->_config['domain'] !== null) {
         $emailUsername = $this->_appendDomain($_user->accountLoginName);
     } else {
         $emailUsername = $_newUserProperties->accountEmailAddress;
     }
     list($localPart, $domain) = explode('@', $emailUsername, 2);
     $rawData['domain'] = $domain;
     // replace home wildcards when storing to db
     // %d = domain
     // %n = user
     // %u == user@domain
     $search = array('%n', '%d', '%u');
     $replace = array($localPart, $domain, $emailUsername);
     $rawData[$this->_propertyMapping['emailHome']] = str_replace($search, $replace, $this->_config['emailHome']);
     $rawData[$this->_propertyMapping['emailUsername']] = $emailUsername;
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($rawData, true));
     }
     return $rawData;
 }
 /**
  * add an user
  * 
  * @todo fix $contactData['container_id'] = 1;
  *
  * @param   Tinebase_Model_FullUser  $_user
  * @return  Tinebase_Model_FullUser
  */
 public function addUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     $_user->isValid(TRUE);
     $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
     if (!isset($_user->accountId)) {
         $userId = $_user->generateUID();
         $_user->setId($userId);
     }
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = $this->_recordToRawData($_user);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding user to SQL backend: ' . $_user->accountLoginName);
     }
     $accountsTable->insert($accountData);
     return $this->getUserById($_user->getId(), 'Tinebase_Model_FullUser');
 }
 /**
  * save user
  *
  * @param  array $recordData data of Tinebase_Model_FullUser
  * @return array  
  */
 public function saveUser($recordData)
 {
     $password = isset($recordData['accountPassword']) ? $recordData['accountPassword'] : '';
     $account = new Tinebase_Model_FullUser();
     // always re-evaluate fullname
     unset($recordData['accountFullName']);
     try {
         $account->setFromJsonInUsersTimezone($recordData);
         if (isset($recordData['sambaSAM'])) {
             $account->sambaSAM = new Tinebase_Model_SAMUser($recordData['sambaSAM']);
         }
         if (isset($recordData['emailUser'])) {
             $account->emailUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->imapUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->smtpUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
         }
     } catch (Tinebase_Exception_Record_Validation $e) {
         // invalid data in some fields sent from client
         $result = array('errors' => $account->getValidationErrors(), 'errorMessage' => 'invalid data for some fields', 'status' => 'failure');
         return $result;
     }
     // this needs long 3execution time because cache invalidation may take long
     // @todo remove this when "0007266: make groups / group memberships cache cleaning more efficient" is resolved
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(300);
     // 5 minutes
     if ($account->getId() == NULL) {
         $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     } else {
         $account = Admin_Controller_User::getInstance()->update($account, $password, $password);
     }
     $result = $this->_recordToJson($account);
     // add primary group to account for the group selection combo box
     $group = Tinebase_Group::getInstance()->getGroupById($account->accountPrimaryGroup);
     // add user groups
     $userGroups = Tinebase_Group::getInstance()->getMultiple(Tinebase_Group::getInstance()->getGroupMemberships($account->accountId))->toArray();
     // add user roles
     $userRoles = Tinebase_Acl_Roles::getInstance()->getMultiple(Tinebase_Acl_Roles::getInstance()->getRoleMemberships($account->accountId))->toArray();
     // encode the account array
     $result['accountPrimaryGroup'] = $group->toArray();
     // encode the groups array
     $result['groups'] = array('results' => $userGroups, 'totalcount' => count($userGroups));
     // encode the roles array
     $result['accountRoles'] = array('results' => $userRoles, 'totalcount' => count($userRoles));
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     return $result;
 }
Пример #15
0
 /**
  * add an user
  * 
  * @todo fix $contactData['container_id'] = 1;
  *
  * @param   Tinebase_Model_FullUser  $_user
  * @return  Tinebase_Model_FullUser
  */
 public function addUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     if (!$_user->isValid()) {
         throw new Exception('invalid user object');
     }
     $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
     if (!isset($_user->accountId)) {
         $userId = $_user->generateUID();
         $_user->setId($userId);
     }
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = array('id' => $_user->accountId, 'login_name' => $_user->accountLoginName, 'status' => $_user->accountStatus, 'expires_at' => $_user->accountExpires instanceof DateTime ? $_user->accountExpires->get(Tinebase_Record_Abstract::ISO8601LONG) : NULL, 'primary_group_id' => $_user->accountPrimaryGroup, 'home_dir' => $_user->accountHomeDirectory, 'login_shell' => $_user->accountLoginShell, 'openid' => $_user->openid, 'visibility' => $_user->visibility, 'contact_id' => $_user->contact_id, $this->rowNameMapping['accountDisplayName'] => $_user->accountDisplayName, $this->rowNameMapping['accountFullName'] => $_user->accountFullName, $this->rowNameMapping['accountFirstName'] => $_user->accountFirstName, $this->rowNameMapping['accountLastName'] => $_user->accountLastName, $this->rowNameMapping['accountEmailAddress'] => $_user->accountEmailAddress);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding user to SQL backend: ' . $_user->accountLoginName);
     }
     $accountsTable->insert($accountData);
     return $this->getUserById($_user->getId(), 'Tinebase_Model_FullUser');
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     parent::setUp();
     $this->_json = new Phone_Frontend_Json();
     $this->_adminUser = Tinebase_Core::getUser();
     $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' => 'test setting', 'description' => 'test setting'));
     $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'model' => 'snom320', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId()));
     $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "1234567890cd", 'description' => 'user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none'));
     $this->_objects['phone1'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "a234567890cd", 'description' => 'second user phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none'));
     $this->_objects['phone2'] = new Voipmanager_Model_Snom_Phone(array('id' => Tinebase_Record_Abstract::generateUID(), 'macaddress' => "1a34567890cd", 'description' => 'jsmith phone', 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none'));
     $this->_objects['phonesetting'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone']->getId(), 'web_language' => 'English'));
     $this->_objects['phonesetting1'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone1']->getId(), 'web_language' => 'English'));
     $this->_objects['phonesetting2'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $this->_objects['phone2']->getId(), 'web_language' => 'English'));
     $this->_objects['phoneOwner'] = array('account_id' => $this->_adminUser->getId(), 'account_type' => 'user');
     $this->_objects['phoneOwner2'] = array('account_id' => $this->_personas['jsmith']->getId(), 'account_type' => 'user');
     $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner']));
     $rights1 = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner']));
     $rights2 = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner2']));
     $this->_objects['phone']->rights = $rights;
     $this->_objects['phone1']->rights = $rights1;
     $this->_objects['phone2']->rights = $rights2;
     $this->_objects['context'] = new Voipmanager_Model_Asterisk_Context(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'test context', 'description' => 'test context'));
     $this->_objects['sippeer'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId()));
     $this->_objects['sippeer1'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId()));
     $this->_objects['sippeer2'] = new Voipmanager_Model_Asterisk_SipPeer(array('id' => Tinebase_Record_Abstract::generateUID(), 'context_id' => $this->_objects['context']->getId()));
     $this->_objects['line'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone']->getId(), 'asteriskline_id' => $this->_objects['sippeer']->getId(), 'linenumber' => 1, 'lineactive' => 1));
     $this->_objects['line1'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone1']->getId(), 'asteriskline_id' => $this->_objects['sippeer1']->getId(), 'linenumber' => 1, 'lineactive' => 1));
     $this->_objects['line2'] = new Voipmanager_Model_Snom_Line(array('id' => Tinebase_Record_Abstract::generateUID(), 'snomphone_id' => $this->_objects['phone2']->getId(), 'asteriskline_id' => $this->_objects['sippeer2']->getId(), 'linenumber' => 1, 'lineactive' => 1));
     // create phone, location, template, rights
     $phoneBackend = new Voipmanager_Backend_Snom_Phone(array('modelName' => 'Phone_Model_MyPhone'));
     $snomLocationBackend = new Voipmanager_Backend_Snom_Location();
     $snomSettingBackend = new Voipmanager_Backend_Snom_Setting();
     $snomPhoneSettingBackend = new Voipmanager_Backend_Snom_PhoneSettings();
     $snomTemplateBackend = new Voipmanager_Backend_Snom_Template();
     $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software();
     $snomLineBackend = new Voipmanager_Backend_Snom_Line();
     $asteriskSipPeerBackend = new Voipmanager_Backend_Asterisk_SipPeer();
     $asteriskContextBackend = new Voipmanager_Backend_Asterisk_Context();
     $snomSoftwareBackend->create($this->_objects['software']);
     $snomLocationBackend->create($this->_objects['location']);
     $snomSettingBackend->create($this->_objects['setting']);
     $snomTemplateBackend->create($this->_objects['template']);
     $phoneBackend->create($this->_objects['phone']);
     $phoneBackend->create($this->_objects['phone1']);
     $phoneBackend->create($this->_objects['phone2']);
     $phoneBackend->setPhoneRights($this->_objects['phone']);
     $phoneBackend->setPhoneRights($this->_objects['phone1']);
     $phoneBackend->setPhoneRights($this->_objects['phone2']);
     $asteriskContextBackend->create($this->_objects['context']);
     $asteriskSipPeerBackend->create($this->_objects['sippeer']);
     $asteriskSipPeerBackend->create($this->_objects['sippeer1']);
     $asteriskSipPeerBackend->create($this->_objects['sippeer2']);
     $snomLineBackend->create($this->_objects['line']);
     $snomLineBackend->create($this->_objects['line1']);
     $snomLineBackend->create($this->_objects['line2']);
     $snomPhoneSettingBackend->create($this->_objects['phonesetting']);
     $snomPhoneSettingBackend->create($this->_objects['phonesetting1']);
     $snomPhoneSettingBackend->create($this->_objects['phonesetting2']);
     /******************** call history *************************/
     $phoneController = Phone_Controller::getInstance();
     $this->_objects['call1'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid1', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '0406437435'));
     $this->_objects['call2'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2', 'line_id' => $this->_objects['line']->getId(), 'phone_id' => $this->_objects['phone']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '26', 'destination' => '050364354'));
     $this->_objects['call2a'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid2a', 'line_id' => $this->_objects['line1']->getId(), 'phone_id' => $this->_objects['phone1']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '27', 'destination' => '050364354'));
     $this->_objects['call3'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid3', 'line_id' => $this->_objects['line2']->getId(), 'phone_id' => $this->_objects['phone2']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '78', 'destination' => '050998877'));
     $this->_objects['call4'] = new Phone_Model_Call(array('id' => 'phpunitcallhistoryid4', 'line_id' => $this->_objects['line2']->getId(), 'phone_id' => $this->_objects['phone2']->getId(), 'direction' => Phone_Model_Call::TYPE_INCOMING, 'source' => '78', 'destination' => '05036998877'));
     $this->_objects['paging'] = array('start' => 0, 'limit' => 50, 'sort' => 'start', 'dir' => 'ASC');
     $this->_objects['filter1'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => ''));
     $this->_objects['filter2'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '05036'), array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone1']->getId()))));
     $this->_objects['filter2a'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '05036'), array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone1']->getId()))));
     $this->_objects['filter2b'] = array(array('field' => 'destination', 'operator' => 'contains', 'value' => '05036'));
     $this->_objects['filter3'] = array(array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone']->getId()))));
     $this->_objects['filter4'] = array(array('field' => 'phone_id', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $this->_objects['phone2']->getId()))));
     $this->_objects['filter5'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => '998877'));
     // create calls
     $phoneController->callStarted($this->_objects['call1']);
     $phoneController->callStarted($this->_objects['call2']);
     $phoneController->callStarted($this->_objects['call2a']);
     $phoneController->callStarted($this->_objects['call3']);
     $phoneController->callStarted($this->_objects['call4']);
 }
 /**
  * returns array of raw Dbmail data
  *
  * @param  Tinebase_Model_EmailUser  $_user
  * @param  Tinebase_Model_EmailUser  $_newUserProperties
  * @return array
  */
 protected function _recordToRawData(Tinebase_Model_FullUser $_user, Tinebase_Model_FullUser $_newUserProperties)
 {
     $rawData = array();
     foreach ($_newUserProperties->imapUser as $key => $value) {
         $property = isset($this->_propertyMapping[$key]) || array_key_exists($key, $this->_propertyMapping) ? $this->_propertyMapping[$key] : false;
         if ($property && !in_array($key, $this->_readOnlyFields)) {
             switch ($key) {
                 case 'emailPassword':
                     $rawData[$property] = Hash_Password::generate($this->_config['emailScheme'], $value, false);
                     $rawData[$this->_propertyMapping['emailScheme']] = $this->_config['emailScheme'];
                     break;
                 case 'emailUserId':
                 case 'emailGID':
                 case 'emailUsername':
                     // do nothing
                     break;
                 case 'emailMailQuota':
                 case 'emailMailSize':
                 case 'emailSieveQuota':
                 case 'emailSieveSize':
                     // convert to bytes
                     $rawData[$property] = Tinebase_Helper::convertToBytes($value . 'M');
                     break;
                 default:
                     $rawData[$property] = $value;
             }
         }
     }
     $rawData[$this->_propertyMapping['emailUserId']] = $this->_hasTine20Userid === true ? $_user->getId() : $this->_convertToInt($_user->getId());
     if ($this->_hasTine20Userid === true) {
         $rawData[$this->_propertyMapping['emailGID']] = $this->_config['emailGID'];
         $rawData['client_idnr'] = $this->_convertToInt($this->_config['emailGID']);
     } else {
         $rawData[$this->_propertyMapping['emailGID']] = $this->_convertToInt($this->_config['emailGID']);
     }
     $rawData[$this->_propertyMapping['emailUsername']] = $this->_appendDomain($_user->accountLoginName);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($rawData, TRUE));
     }
     return $rawData;
 }
 /**
  * returns array of raw email user data
  *
  * @param  Tinebase_Model_EmailUser $_user
  * @param  Tinebase_Model_EmailUser $_newUserProperties
  * @throws Tinebase_Exception_UnexpectedValue
  * @return array
  * 
  * @todo   validate domains of aliases too
  */
 protected function _recordToRawData(Tinebase_Model_FullUser $_user, Tinebase_Model_FullUser $_newUserProperties)
 {
     $rawData = array();
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_newUserProperties->toArray(), true));
     }
     if (isset($_newUserProperties->smtpUser)) {
         foreach ($_newUserProperties->smtpUser as $key => $value) {
             $property = isset($this->_propertyMapping[$key]) || array_key_exists($key, $this->_propertyMapping) ? $this->_propertyMapping[$key] : false;
             if ($property) {
                 switch ($key) {
                     case 'emailAliases':
                         $rawData[$property] = array();
                         foreach ((array) $value as $address) {
                             if ($this->_checkDomain($address) === true) {
                                 $rawData[$property][] = $address;
                             }
                         }
                         break;
                     case 'emailForwards':
                         $rawData[$property] = is_array($value) ? $value : array();
                         break;
                     default:
                         $rawData[$property] = $value;
                         break;
                 }
             }
         }
     }
     if (!empty($_user->accountEmailAddress)) {
         $this->_checkDomain($_user->accountEmailAddress, TRUE);
     }
     $rawData[$this->_propertyMapping['emailAddress']] = $_user->accountEmailAddress;
     $rawData[$this->_propertyMapping['emailUserId']] = $_user->getId();
     $rawData[$this->_propertyMapping['emailUsername']] = $_user->accountLoginName;
     if (empty($rawData[$this->_propertyMapping['emailAddress']])) {
         $rawData[$this->_propertyMapping['emailAliases']] = null;
         $rawData[$this->_propertyMapping['emailForwards']] = null;
     }
     if (empty($rawData[$this->_propertyMapping['emailForwards']])) {
         $rawData[$this->_propertyMapping['emailForwardOnly']] = 0;
     }
     $rawData['domain'] = $this->_config['domain'];
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($rawData, true));
     }
     return $rawData;
 }
 /**
  * returns array of raw Dovecot data
  *
  * @param  Tinebase_Model_FullUser  $_user
  * @param  Tinebase_Model_FullUser  $_newUserProperties
  * @return array
  */
 protected function _recordToRawData(Tinebase_Model_FullUser $_user, Tinebase_Model_FullUser $_newUserProperties)
 {
     $rawData = array();
     if (isset($_newUserProperties->imapUser)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_newUserProperties->imapUser->toArray(), true));
         }
         foreach ($_newUserProperties->imapUser as $key => $value) {
             $property = isset($this->_propertyMapping[$key]) || array_key_exists($key, $this->_propertyMapping) ? $this->_propertyMapping[$key] : false;
             if ($property && !in_array($key, $this->_readOnlyFields)) {
                 switch ($key) {
                     case 'emailUserId':
                     case 'emailUsername':
                         // set later
                         break;
                     case 'emailPassword':
                         $rawData[$property] = Hash_Password::generate($this->_config['emailScheme'], $value);
                         break;
                     case 'emailMailQuota':
                         $rawData[$property] = empty($value) ? 0 : $value;
                         break;
                     default:
                         $rawData[$property] = $value;
                         break;
                 }
             }
         }
     }
     $rawData[$this->_propertyMapping['emailAddress']] = $_user->accountEmailAddress;
     $rawData[$this->_propertyMapping['emailForwardOnly']] = '0';
     // will be overwritten later
     $rawData[$this->_propertyMapping['emailUserId']] = $_user->getId();
     $rawData[$this->_propertyMapping['emailUsername']] = $_user->accountLoginName;
     $rawData[$this->_propertyMapping['emailHome']] = '/' . $_user->accountLoginName . '_' . substr($_user->getId(), 0, 8);
     $rawData['domain'] = $this->_config['domain'];
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($rawData, true));
     }
     return $rawData;
 }
 /**
  * set quota directly on IMAP server
  * 
  * @param Tinebase_Model_FullUser $_user
  * @param Zend_Mail_Protocol_Imap $_imap
  * @param string $_mailboxString
  */
 protected function _setImapQuota(Tinebase_Model_FullUser $_user, Zend_Mail_Protocol_Imap $_imap = NULL, $_mailboxString = NULL)
 {
     $imap = $_imap !== NULL ? $_imap : $this->_getImapConnection();
     $mailboxString = $_mailboxString !== NULL ? $_mailboxString : $this->_getUserMailbox($_user->accountLoginName);
     if (isset($_user->imapUser)) {
         $limit = $_user->imapUser->emailMailQuota > 0 ? Tinebase_Helper::convertToBytes($_user->imapUser->emailMailQuota . 'M') / 1024 : null;
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Setting quota of user " . $_user->getId() . " to " . $limit);
         }
         $imap->setQuota($mailboxString, 'STORAGE', $limit);
     }
 }
 /**
  * updates an existing user
  *
  * @todo check required objectclasses?
  *
  * @param  Tinebase_Model_FullUser  $_account
  * @return Tinebase_Model_FullUser
  */
 public function updateUserInSyncBackend(Tinebase_Model_FullUser $_account)
 {
     if ($this->_isReadOnlyBackend) {
         return;
     }
     Tinebase_Group::getInstance()->addGroupMemberInSyncBackend($_account->accountPrimaryGroup, $_account->getId());
     $ldapEntry = $this->_getLdapEntry('accountId', $_account);
     $ldapData = $this->_user2ldap($_account, $ldapEntry);
     foreach ($this->_ldapPlugins as $plugin) {
         $plugin->inspectUpdateUser($_account, $ldapData, $ldapEntry);
     }
     // do we need to rename the entry?
     // TODO move to rename()
     $dn = Zend_Ldap_Dn::factory($ldapEntry['dn'], null);
     $rdn = $dn->getRdn();
     if ($rdn['CN'] != $ldapData['cn']) {
         $newDN = $this->generateDn($_account);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  rename ldap entry to: ' . $newDN);
         }
         $this->_ldap->rename($dn, $newDN);
     }
     // no need to update this attribute, it's not allowed to change and even might not be updateable
     unset($ldapData[$this->_userUUIDAttribute]);
     // remove cn as samba forbids updating the CN (even if it does not change...
     // 0x43 (Operation not allowed on RDN; 00002016: Modify of RDN 'CN' on CN=...,CN=Users,DC=example,DC=org
     // not permitted, must use 'rename' operation instead
     unset($ldapData['cn']);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  $dn: ' . $ldapEntry['dn']);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . '  $ldapData: ' . print_r($ldapData, true));
     }
     $this->_ldap->update($ldapEntry['dn'], $ldapData);
     // refetch user from ldap backend
     $user = $this->getUserByPropertyFromSyncBackend('accountId', $_account, 'Tinebase_Model_FullUser');
     return $user;
 }
Пример #22
0
 /**
  * add one record
  *
  * @param   Tinebase_Record_Interface $_record
  * @return  Tinebase_Record_Interface
  */
 public function create(Tinebase_Record_Interface $_record)
 {
     $course = parent::create($_record);
     // add teacher account
     $i18n = Tinebase_Translation::getTranslation('Courses');
     $courseName = strtolower($course->name);
     $loginName = strtolower($i18n->_('teacher') . '-' . $course->name);
     $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name);
     $account = new Tinebase_Model_FullUser(array('accountLoginName' => $loginName, 'accountLoginShell' => '/bin/false', 'accountStatus' => 'enabled', 'accountPrimaryGroup' => $course->group_id, 'accountLastName' => $i18n->_('Teacher'), 'accountDisplayName' => $course->name . ' ' . $i18n->_('Teacher Account'), 'accountFirstName' => $course->name, 'accountExpires' => NULL, 'accountEmailAddress' => isset($this->_config->domain) && !empty($this->_config->domain) ? $loginName . '@' . $this->_config->domain : '', 'accountHomeDirectory' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $courseName . '/' . $loginName : ''));
     if (isset($this->_config->samba)) {
         $samUser = new Tinebase_Model_SAMUser(array('homePath' => $this->_config->samba->basehomepath . $loginName, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $courseName . $this->_config->samba->logonscript_postfix_teacher, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $courseName . '\\' . $loginName));
         $account->sambaSAM = $samUser;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created teacher account for course ' . $course->name . ': ' . print_r($account->toArray(), true));
     }
     #$event = new Courses_Event_BeforeAddTeacher($account, $course);
     #Tinebase_Event::fireEvent($event);
     $password = $this->_config->get('teacher_password', $account->accountLoginName);
     $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     // add to teacher group if available
     if (isset($this->_config->teacher_group) && !empty($this->_config->teacher_group)) {
         Admin_Controller_Group::getInstance()->addGroupMember($this->_config->teacher_group, $account->getId());
     }
     // add to students group if available
     if (isset($this->_config->students_group) && !empty($this->_config->students_group)) {
         Admin_Controller_Group::getInstance()->addGroupMember($this->_config->students_group, $account->getId());
     }
     return $course;
 }
 /**
  * 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;
 }
Пример #24
0
 /**
  * check if user exists already in postfix user table
  * 
  * @param  Tinebase_Model_FullUser  $_user
  */
 protected function _userExists(Tinebase_Model_FullUser $_user)
 {
     $select = $this->_getSelect();
     $select->where($this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailUserId']) . ' = ?', $_user->getId());
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $select->__toString());
     // Perferom query - retrieve user from database
     $stmt = $this->_db->query($select);
     $queryResult = $stmt->fetch();
     $stmt->closeCursor();
     if (!$queryResult) {
         return false;
     }
     return true;
 }
 /**
  * import contactdata(phone, address, fax, birthday. photo)
  * 
  * @param Tinebase_Model_FullUser $syncedUser
  * @param array $options
  */
 public static function syncContactData($syncedUser, $options)
 {
     if (!Tinebase_Config::getInstance()->get(Tinebase_Config::SYNC_USER_CONTACT_DATA, true) || !isset($options['syncContactData']) || !$options['syncContactData'] || !Tinebase_Application::getInstance()->isInstalled('Addressbook') || $syncedUser->visibility === Tinebase_Model_FullUser::VISIBILITY_HIDDEN) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Contact data sync disabled');
         }
         return;
     }
     $addressbook = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     try {
         $contact = $addressbook->getByUserId($syncedUser->getId());
         $originalContact = clone $contact;
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' user: '******'::' . __LINE__ . ' new contact: ' . print_r($contact->toArray(), true) . ' orig contact:' . print_r($originalContact->toArray(), true));
         }
         // TODO allow to diff jpegphoto, too / maybe this should only be done when called via CLI/cronjob
         $diff = $contact->diff($originalContact, array('jpegphoto'));
         if (!$diff->isEmpty() || $originalContact->jpegphoto == 0 && !empty($contact->jpegphoto)) {
             // add modlog info
             Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
             if ($contact->container_id !== null) {
                 Tinebase_Container::getInstance()->increaseContentSequence($contact->container_id);
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating contact data for user ' . $syncedUser->accountLoginName);
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Diff: ' . print_r($diff->toArray(), true));
             }
             $addressbook->update($contact);
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' User contact is up to date.');
             }
         }
     } catch (Addressbook_Exception_NotFound $aenf) {
         self::createContactForSyncedUser($syncedUser);
         $syncedUser = Tinebase_User::getInstance()->updateUserInSqlBackend($syncedUser);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Contact information seems to be missing in sync backend');
         }
         Tinebase_Exception::log($tenf);
     }
 }
 /**
  * check if user exists already in email backjend user table
  * 
  * @param  Tinebase_Model_FullUser  $_user
  * @throws Tinebase_Exception_Backend_Database
  */
 protected function _userExists(Tinebase_Model_FullUser $_user)
 {
     $select = $this->_getSelect();
     $select->where($this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailUserId']) . ' = ?', $_user->getId());
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $select->__toString());
     }
     // Perform query - retrieve user from database
     try {
         $stmt = $this->_db->query($select);
     } catch (Zend_Db_Statement_Exception $zdse) {
         if (Tinebase_Core::isLogLevel(Zend_Log::ERR)) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $zdse);
         }
         throw new Tinebase_Exception_Backend_Database($zdse->getMessage());
     }
     $queryResult = $stmt->fetch();
     $stmt->closeCursor();
     if (!$queryResult) {
         return false;
     }
     return true;
 }
 /**
  * update access log entry if needed
  * 
  * @param Tinebase_Model_FullUser $user
  * @param Tinebase_Model_AccessLog $accessLog
  */
 protected function _updateAccessLog(Tinebase_Model_FullUser $user, Tinebase_Model_AccessLog $accessLog)
 {
     if (!$accessLog->getId()) {
         $user->setLoginTime($accessLog->ip);
         if ($this->_writeAccessLog) {
             $accessLog->setId(Tinebase_Record_Abstract::generateUID());
             $accessLog = Tinebase_AccessLog::getInstance()->create($accessLog);
         }
     }
     Tinebase_Core::set(Tinebase_Core::USERACCESSLOG, $accessLog);
 }
 /**
  * check admin role membership
  * 
  * @param Tinebase_Model_FullUser $user
  */
 protected function _checkAdminRole($user)
 {
     $roleMemberships = Tinebase_Acl_Roles::getInstance()->getRoleMemberships($user->getId());
     $adminRoleFound = FALSE;
     // TODO allow to configure this / pass it as param
     $adminRoleName = 'admin role';
     foreach ($roleMemberships as $roleId) {
         $role = Tinebase_Acl_Roles::getInstance()->getRoleById($roleId);
         if ($role->name === $adminRoleName) {
             $adminRoleFound = TRUE;
             break;
         }
     }
     if (!$adminRoleFound || !Tinebase_Acl_Roles::getInstance()->hasRight('Admin', $user->getId(), Tinebase_Acl_Rights::ADMIN)) {
         echo "Admin role not found for user " . $user->accountLoginName . ".\n";
         try {
             $adminRole = Tinebase_Acl_Roles::getInstance()->getRoleByName($adminRoleName);
         } catch (Tinebase_Exception_NotFound $tenf) {
             $adminRole = $this->_createNewAdminRoleForAdmin($adminRoleName);
         }
         Tinebase_Acl_Roles::getInstance()->setRoleMembers($adminRole->getId(), array(array('id' => $user->getId(), 'type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)));
         echo "Added user " . $user->accountLoginName . " to role '{$adminRoleName}''.\n";
         // @todo clear roles/groups cache
     }
 }