コード例 #1
0
 /**
  * import the groups from eGroupWare 1.4
  *
  */
 protected function importGroups()
 {
     $this->_log->INFO('start importing egw groups');
     $select = $this->_egwDb->select()->from(array('accounts' => 'egw_accounts'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('accounts.account_type') . ' = ?', 'g'));
     $groups = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_OBJ);
     foreach ($groups as $group) {
         $groupObject = new Tinebase_Model_Group(array('id' => abs($group->account_id), 'name' => $group->account_lid, 'description' => 'imported by Tine 2.0 group importer'));
         $this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . ' add group: ' . print_r($groupObject->toArray(), TRUE));
         try {
             Tinebase_Group::getInstance()->addGroup($groupObject);
         } catch (Exception $e) {
             $this->_log->WARN(__METHOD__ . '::' . __LINE__ . ' Could not add group: ' . $groupObject->name . ' Error message: ' . $e->getMessage());
         }
     }
     $this->_log->NOTICE('imported ' . count($groups) . ' groups from egw');
 }
コード例 #2
0
 /**
  * save course with corresponding group
  * 
  * @param Courses_Model_Course $course
  * @param Tinebase_Model_Group $group
  * @return Courses_Model_Course
  * 
  * @todo this should be moved to normal create/update (inspection) functions
  */
 public function saveCourseAndGroup(Courses_Model_Course $course, Tinebase_Model_Group $group)
 {
     $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__ . ' Saving course ' . $course->name . ' with group ' . $group->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($group->toArray(), true));
     }
     if (empty($group->id)) {
         $savedGroup = $this->_groupController->create($group);
         $course->group_id = $savedGroup->getId();
         $savedRecord = $this->create($course);
     } else {
         $savedRecord = $this->update($course);
         $currentMembers = $this->_groupController->getGroupMembers($course->group_id);
         $newCourseMembers = array_diff((array) $group->members, $currentMembers);
         if (count($newCourseMembers) > 0) {
             $this->addCourseMembers($course, $newCourseMembers);
         }
         $deletedAccounts = array_diff($currentMembers, (array) $group->members);
         // delete members which got removed from course
         $this->_userController->delete($deletedAccounts);
     }
     $groupMembers = Tinebase_Group::getInstance()->getGroupMembers($course->group_id);
     // add/remove members to/from internet/fileserver group
     if (!empty($groupMembers)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($groupMembers) . ' group members');
         }
         $this->_manageAccessGroups($groupMembers, $savedRecord);
         // $this->_manageAccessGroups($group->members, $savedRecord, 'fileserver');
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No group members found.');
         }
     }
     return $savedRecord;
 }
コード例 #3
0
 /**
  * create or update list in addressbook sql backend
  * 
  * @param  Tinebase_Model_Group  $group
  * @return Addressbook_Model_List
  */
 public function createOrUpdateByGroup(Tinebase_Model_Group $group)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($group->toArray(), TRUE));
     }
     try {
         if (empty($group->list_id)) {
             $list = $this->_backend->getByGroupName($group->name);
             if (!$list) {
                 // jump to catch block => no list_id provided and no existing list for group found
                 throw new Tinebase_Exception_NotFound('list_id is empty');
             }
             $group->list_id = $list->getId();
         } else {
             $list = $this->_backend->get($group->list_id);
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Update list ' . $group->name);
         }
         $list->name = $group->name;
         $list->description = $group->description;
         $list->email = $group->email;
         $list->type = Addressbook_Model_List::LISTTYPE_GROUP;
         $list->container_id = empty($group->container_id) ? $this->_getDefaultInternalAddressbook() : $group->container_id;
         $list->members = isset($group->members) ? $this->_getContactIds($group->members) : array();
         // add modlog info
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($list, 'update');
         $list = $this->_backend->update($list);
         $list = $this->get($list->getId());
     } catch (Tinebase_Exception_NotFound $tenf) {
         $list = $this->createByGroup($group);
     }
     return $list;
 }
コード例 #4
0
 /**
  * try to convert id of group object and check if correct exceptions are thrown 
  */
 public function testConvertGroupIdToIntWithGroup()
 {
     $this->setExpectedException('Tinebase_Exception_InvalidArgument');
     Tinebase_Model_Group::convertGroupIdToInt(new Tinebase_Model_Group(array('name' => 'tine20phpunit noid', 'description' => 'noid group')));
 }
 /**
  * returns ldap metadata of given group
  *
  * @param  string $_groupId
  * @return array
  * @throws Tinebase_Exception_NotFound
  * 
  * @todo remove obsolete code
  */
 protected function _getMetaData($_groupId)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $filter = Zend_Ldap_Filter::equals($this->_groupUUIDAttribute, $this->_encodeGroupId($groupId));
     $result = $this->getLdap()->search($filter, $this->_options['groupsDn'], $this->_groupSearchScope, array('objectclass', 'objectsid'));
     if (count($result) !== 1) {
         throw new Tinebase_Exception_NotFound("Group with id {$_groupId} not found.");
     }
     $group = $result->getFirst();
     return array('dn' => $group['dn'], 'objectclass' => $group['objectclass'], 'objectsid' => Tinebase_Ldap::decodeSid($group['objectsid'][0]));
 }
コード例 #6
0
 /**
  * returns ldap metadata of given group
  *
  * @param  int         $_groupId
  */
 protected function _getMetaData($_groupId)
 {
     $metaData = array();
     try {
         $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
         $group = $this->_ldap->fetch($this->_options['groupsDn'], 'objectGUID=' . $groupId, array('objectclass'));
         $metaData['dn'] = $group['dn'];
         $metaData['objectClass'] = $group['objectclass'];
         unset($metaData['objectClass']['count']);
     } catch (Tinebase_Exception_NotFound $e) {
         throw new Exception("group with id {$groupId} not found");
     }
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . '  $data: ' . print_r($metaData, true));
     return $metaData;
 }
コード例 #7
0
 /**
  * get group by id
  *
  * @param   string $_name
  * @return  Tinebase_Model_Group
  * @throws  Tinebase_Exception_Record_NotDefined
  */
 public function getGroupById($_groupId)
 {
     $groupdId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $result = $this->getGroupByPropertyFromSqlBackend('id', $groupdId);
     return $result;
 }
コード例 #8
0
 /**
  * import groups from typo3 
  * 
  * @return void
  */
 public function importGroups()
 {
     $select = $this->_t3db->select()->from('be_groups');
     //->where('deleted = 0'))
     $groups = $select->query()->fetchAll(Zend_Db::FETCH_ASSOC);
     foreach ($groups as $group) {
         $groupObject = new Tinebase_Model_Group(array('id' => $group['uid'], 'name' => $group['title'], 'description' => null));
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' add group: ' . print_r($groupObject->toArray(), TRUE));
         }
         try {
             parent::addGroup($groupObject);
         } catch (Exception $e) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not add group: ' . $groupObject->name . ' Error message: ' . $e->getMessage());
         }
     }
 }
 /**
  * add grants to container
  *
  * @todo    check that grant is not already given to container/type/accout combi
  * @param   int|Tinebase_Model_Container $_containerId
  * @param   int $_accountId
  * @param   array $_grants list of grants to add
  * @return  boolean
  * @throws  Tinebase_Exception_AccessDenied
  */
 public function addGrants($_containerId, $_accountType, $_accountId, array $_grants, $_ignoreAcl = FALSE)
 {
     $containerId = Tinebase_Model_Container::convertContainerIdToInt($_containerId);
     if ($_ignoreAcl !== TRUE and !$this->hasGrant(Tinebase_Core::getUser(), $_containerId, Tinebase_Model_Grants::GRANT_ADMIN)) {
         throw new Tinebase_Exception_AccessDenied('Permission to manage grants on container denied.');
     }
     switch ($_accountType) {
         case Tinebase_Acl_Rights::ACCOUNT_TYPE_USER:
             $accountId = Tinebase_Model_User::convertUserIdToInt($_accountId);
             break;
         case Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP:
             $accountId = Tinebase_Model_Group::convertGroupIdToInt($_accountId);
             break;
         case Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE:
             $accountId = '0';
             break;
         default:
             throw new Tinebase_Exception_InvalidArgument('invalid $_accountType');
             break;
     }
     $containerGrants = $this->getGrantsOfContainer($containerId, TRUE);
     $containerGrants->addIndices(array('account_type', 'account_id'));
     $existingGrants = $containerGrants->filter('account_type', $_accountType)->filter('account_id', $_accountId)->getFirstRecord();
     $id = Tinebase_Record_Abstract::generateUID();
     foreach ($_grants as $grant) {
         if ($existingGrants === NULL || !$existingGrants->{$grant}) {
             $data = array('id' => $id, 'container_id' => $containerId, 'account_type' => $_accountType, 'account_id' => $accountId, 'account_grant' => $grant);
             $this->_getContainerAclTable()->insert($data);
         }
     }
     $this->_setRecordMetaDataAndUpdate($containerId, 'update');
     return true;
 }
コード例 #10
0
ファイル: Group.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * update existing group
  *
  * @param Tinebase_Model_Group $_group
  * @return Tinebase_Model_Group
  */
 public function update(Tinebase_Model_Group $_group)
 {
     $this->checkRight('MANAGE_ACCOUNTS');
     // update default user group if name has changed
     $oldGroup = Tinebase_Group::getInstance()->getGroupById($_group->getId());
     $defaultGroupName = Tinebase_User::getBackendConfiguration(Tinebase_User::DEFAULT_USER_GROUP_NAME_KEY);
     if ($oldGroup->name == $defaultGroupName && $oldGroup->name != $_group->name) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updated default group name: ' . $oldGroup->name . ' -> ' . $_group->name);
         Tinebase_User::setBackendConfiguration($_group->name, Tinebase_User::DEFAULT_USER_GROUP_NAME_KEY);
         Tinebase_User::saveBackendConfiguration();
     }
     $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
     if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
         $_group->list_id = $oldGroup->list_id;
         $list = $this->createOrUpdateList($_group);
         $_group->list_id = $list->getId();
     }
     $group = Tinebase_Group::getInstance()->updateGroup($_group);
     Tinebase_Group::getInstance()->setGroupMembers($group->getId(), $_group->members);
     Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     $event = new Admin_Event_UpdateGroup();
     $event->group = $group;
     Tinebase_Event::fireEvent($event);
     return $group;
 }
コード例 #11
0
 /**
  * get group by id
  *
  * @param   string $_name
  * @return  Tinebase_Model_Group
  * @throws  Tinebase_Exception_Record_NotDefined
  */
 public function getGroupById($_groupId)
 {
     $groupdId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $select = $this->_getSelect();
     $select->where($this->_db->quoteIdentifier($this->_tableName . '.id') . ' = ?', $groupdId);
     $stmt = $this->_db->query($select);
     $queryResult = $stmt->fetch();
     $stmt->closeCursor();
     if (!$queryResult) {
         throw new Tinebase_Exception_Record_NotDefined('Group not found.');
     }
     $result = new Tinebase_Model_Group($queryResult, TRUE);
     return $result;
 }
コード例 #12
0
 /**
  * try to convert id of group object and check if correct exceptions are thrown 
  */
 public function testConvertGroupIdToIntWithGroup()
 {
     $this->setExpectedException('Tinebase_Exception_InvalidArgument');
     Tinebase_Model_Group::convertGroupIdToInt($this->objects['noIdGroup']);
 }
コード例 #13
0
 /**
  * returns ldap metadata of given group
  *
  * @param  string $_groupId
  * @return array
  * @throws Tinebase_Exception_NotFound
  * 
  * @todo remove obsolete code
  */
 protected function _getMetaData($_groupId)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $filter = Zend_Ldap_Filter::equals($this->_groupUUIDAttribute, Zend_Ldap::filterEscape($groupId));
     $result = $this->_ldap->search($filter, $this->_options['groupsDn'], $this->_groupSearchScope, array('objectclass'));
     if (count($result) !== 1) {
         throw new Tinebase_Exception_NotFound("Group with id {$_groupId} not found.");
     }
     return $result->getFirst();
 }
コード例 #14
0
 /**
  * returns ldap metadata of given group
  *
  * @param  int         $_groupId
  * @return array 
  * 
  * @todo remove obsolete code
  */
 protected function _getGroupMetaData($_groupId)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $filter = Zend_Ldap_Filter::equals($this->_options['groupUUIDAttribute'], Zend_Ldap::filterEscape($groupId));
     $result = $this->_ldap->search($filter, $this->_options['groupsDn'], Zend_Ldap::SEARCH_SCOPE_SUB, array('objectclass', 'sambasid'))->getFirst();
     return $result;
     /*
     } catch (Tinebase_Exception_NotFound $e) {
         throw new Exception("group with id $groupId not found");
     }
     */
 }
コード例 #15
0
 /**
  * creates/updates a record
  *
  * @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);
     $savedRecord = $this->_controller->saveCourseAndGroup($course, $group);
     return $this->_recordToJson($savedRecord);
 }
コード例 #16
0
 /**
  * get list of role memberships
  *
  * @param   int $accountId
  * @param   string $type
  * @return  array of array with role ids
  * @throws  Tinebase_Exception_NotFound
  */
 public function getRoleMemberships($accountId, $type = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)
 {
     if ($type === Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) {
         $accountId = Tinebase_Model_User::convertUserIdToInt($accountId);
         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($accountId);
         if (empty($groupMemberships)) {
             throw new Tinebase_Exception_NotFound('Any account must belong to at least one group. The account with accountId ' . $accountId . ' does not belong to any group.');
         }
         $classCacheId = Tinebase_Helper::convertCacheId($accountId . implode('', $groupMemberships) . $type);
     } else {
         if ($type === Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP) {
             $accountId = Tinebase_Model_Group::convertGroupIdToInt($accountId);
             $classCacheId = Tinebase_Helper::convertCacheId($accountId . $type);
         } else {
             throw new Tinebase_Exception_InvalidArgument('Invalid type: ' . $type);
         }
     }
     if (isset($this->_classCache[__FUNCTION__][$classCacheId])) {
         return $this->_classCache[__FUNCTION__][$classCacheId];
     }
     $select = $this->_getDb()->select()->distinct()->from(array('role_accounts' => SQL_TABLE_PREFIX . 'role_accounts'), array('role_id'))->where($this->_getDb()->quoteInto($this->_getDb()->quoteIdentifier('account_id') . ' = ?', $accountId) . ' AND ' . $this->_getDb()->quoteInto($this->_getDb()->quoteIdentifier('account_type') . ' = ?', $type));
     if ($type === Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) {
         $select->orwhere($this->_getDb()->quoteInto($this->_getDb()->quoteIdentifier('account_id') . ' IN (?)', $groupMemberships) . ' AND ' . $this->_getDb()->quoteInto($this->_getDb()->quoteIdentifier('account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP));
     }
     $stmt = $this->_getDb()->query($select);
     $memberships = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
     $this->_classCache[__FUNCTION__][$classCacheId] = $memberships;
     return $memberships;
 }
コード例 #17
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }