public function appendUGroups(DOMElement $ugroups, Project $project) { foreach ($this->ugroups as $id => $name) { $ugroup = $this->ugroup_manager->getUGroupWithMembers($project, $id); $ugroup_node = $this->createUGroupNode($ugroups, $id, $name); $this->appendMembersForStaticGroups($ugroup_node, $ugroup); } }
/** * @return ProjectUGroup[] */ public function getListOfInvolvedStaticUgroups(Tracker $template_tracker) { $project = $template_tracker->getProject(); $ugroups = array(); foreach ($this->permissions_dao->getAuthorizedStaticUgroupIds($template_tracker->getId()) as $id) { $ugroups[] = $this->ugroup_manager->getUGroup($project, $id); } return $ugroups; }
public function getFullRESTValue(Tracker_FormElement_Field $field) { $class_user_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation'; $ugroup_representation = new $class_user_representation(); $ugroup_manager = new UGroupManager(); $project = $field->getTracker()->getProject(); $ugroup_representation->build($project->getID(), $ugroup_manager->getById($this->getUgroupId())); return $ugroup_representation; }
private function getIndexedUgroups(Project $project) { $ugroups = array(); $ugroup_manager = new UGroupManager(); $excluded_groups = array_merge(ProjectUGroup::$legacy_ugroups, array(ProjectUGroup::NONE, ProjectUGroup::ANONYMOUS)); if (!$project->isPublic()) { $excluded_groups = array_merge($excluded_groups, array(ProjectUGroup::REGISTERED)); } $all_ugroups = $ugroup_manager->getUGroups($project, $excluded_groups); foreach ($all_ugroups as $ugroup) { $ugroups[$ugroup->getId()] = $ugroup; } return $ugroups; }
/** * @return int[] array(102 => 324, 106 => 325, <template_ugroup_id> => <target_ugroup_id>, …) */ public function getMapping(Tracker $template_tracker, Project $target_project) { $template_ugroups = $this->permissions_retriever->getListOfInvolvedStaticUgroups($template_tracker); $target_ugroups = $this->ugroup_manager->getStaticUGroups($target_project); $ugroups = array(); foreach ($template_ugroups as $template_ugroup) { foreach ($target_ugroups as $target_ugroup) { if ($template_ugroup->getName() == $target_ugroup->getName()) { $ugroups[$template_ugroup->getId()] = $target_ugroup->getId(); } } } return $ugroups; }
/** * Extract Field data from XML input * * @param Tracker_FormElement_Field $field * @param SimpleXMLElement $field_change * * @return mixed */ public function getFieldData(Tracker_FormElement_Field $field, SimpleXMLElement $field_change) { $data = array('use_artifact_permissions' => (int) $field_change['use_perm'], 'u_groups' => array()); foreach ($field_change->ugroup as $ugroup_xml) { if (isset($ugroup_xml['ugroup_id'])) { $data['u_groups'][] = (int) $ugroup_xml['ugroup_id']; } elseif (isset($ugroup_xml['ugroup_name'])) { $ugroup_manager = new UGroupManager(); $ugroup = $ugroup_manager->getUGroupByName($field->getTracker()->getProject(), (string) $ugroup_xml['ugroup_name']); $data['u_groups'][] = $ugroup->getId(); } } return $data; }
protected function adminGitAdminsView($is_admin_mass_change_allowed) { $params = $this->getData(); $presenter = new GitPresenters_AdminGitAdminsPresenter($this->groupId, $is_admin_mass_change_allowed, $this->ugroup_manager->getStaticUGroups($this->project), $this->git_permissions_manager->getCurrentGitAdminUgroups($this->project->getId())); $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR) . '/templates'); echo $renderer->renderToString('admin', $presenter); }
/** * Build an instance of static value * * @return Tracker_FormElement_Field_List_Bind_UgroupsValue */ private function getUgroupsValueInstance($id, Project $project, $ugroup_id, $is_hidden) { $ugroup = $this->ugroup_manager->getUGroup($project, $ugroup_id); if ($ugroup) { return new Tracker_FormElement_Field_List_Bind_UgroupsValue($id, $ugroup, $is_hidden); } }
/** * @param SimpleXMLElement $xml_element_ugroups * * @return array */ private function getUgroupsFromXMLToAdd(Project $project, SimpleXMLElement $xml_element_ugroups) { $ugroups = array(); $project_members = array(); $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/ugroups.rng'); $this->xml_validator->validate($xml_element_ugroups, $rng_path); $this->logger->debug("XML Ugroups is valid"); foreach ($xml_element_ugroups->ugroup as $ugroup) { $ugroup_name = (string) $ugroup['name']; $ugroup_description = (string) $ugroup['description']; $dynamic_ugroup_id = $this->ugroup_manager->getDynamicUGoupIdByName($ugroup_name); if ($this->ugroup_manager->getUGroupByName($project, $ugroup_name) && empty($dynamic_ugroup_id)) { $this->logger->debug("Ugroup {$ugroup_name} already exists in project -> skipped"); continue; } $users = $this->getListOfUgroupMember($ugroup); if ($dynamic_ugroup_id == ProjectUGroup::PROJECT_MEMBERS) { $project_members = $users; } else { $ugroups[$ugroup_name]['name'] = $ugroup_name; $ugroups[$ugroup_name]['description'] = $ugroup_description; $ugroups[$ugroup_name]['users'] = $users; } } return array($ugroups, $project_members); }
function send_new_project_email(Project $project) { $ugroup_manager = new UGroupManager(); $admin_ugroup = $ugroup_manager->getUGroup($project, ProjectUGroup::PROJECT_ADMIN); foreach ($admin_ugroup->getMembers() as $user) { /* @var $user PFUser */ $language = $user->getLanguage(); $subject = $GLOBALS['sys_name'] . ' ' . $language->getText('include_proj_email', 'proj_approve', $project->getUnixName()); $presenter = new MailPresenterFactory(); $renderer = TemplateRendererFactory::build()->getRenderer(ForgeConfig::get('codendi_dir') . '/src/templates/mail/'); $mail = new TuleapRegisterMail($presenter, $renderer, "mail-project-register"); $mail = $mail->getMailProject($subject, $GLOBALS['sys_noreply'], $user->getEmail(), $project); $mail->send(); } return true; }
private function getUGroupManager() { if (empty($this->ugroup_manager)) { $this->ugroup_manager = UGroupManager::instance(); } return $this->ugroup_manager; }
/** * @return string Gerrit project name * * @throws Git_Driver_Gerrit_ProjectCreator_ProjectAlreadyexistsException * @throws Git_Driver_Gerrit_Exception * @throws Git_Command_Exception */ public function createGerritProject(Git_RemoteServer_GerritServer $gerrit_server, GitRepository $repository, $template_id) { $project = $repository->getProject(); $project_name = $project->getUnixName(); $ugroups = $this->ugroup_manager->getUGroups($project); $driver = $this->driver_factory->getDriver($gerrit_server); $name = $driver->getGerritProjectName($repository); if ($driver->doesTheProjectExist($gerrit_server, $name)) { throw new Git_Driver_Gerrit_ProjectCreator_ProjectAlreadyexistsException($name, $gerrit_server->getHost()); } $migrated_ugroups = $this->membership_manager->createArrayOfGroupsForServer($gerrit_server, $ugroups); $this->umbrella_manager->recursivelyCreateUmbrellaProjects(array($gerrit_server), $project); $gerrit_project_name = $driver->createProject($gerrit_server, $repository, $project_name); $this->pushMinimalPermissionsToMigrateTuleapRepoOnGerrit($gerrit_server, $repository); $this->exportGitBranches($gerrit_server, $gerrit_project_name, $repository); // This method behaviour & all should be transfered into "finalizeGerritProjectCreation" $this->pushFullTuleapAccessRightsToGerrit($repository, $gerrit_server, $migrated_ugroups, ForgeConfig::get('sys_default_domain') . '-' . self::GROUP_REPLICATION, $template_id); return $gerrit_project_name; }
protected function getRESTBindValue(Tracker_FormElement_Field_List_Value $value) { $project = $value->getProject(); $class_ugroup_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation'; $ugroup_representation = new $class_ugroup_representation(); $ugroup_representation->build($project->getID(), $this->ugroup_manager->getUGroup($project, $value->getUgroupId())); $class_ugroupvalue_representation = '\\Tuleap\\Tracker\\REST\\FieldListBindUGroupValueRepresentation'; $representation = new $class_ugroupvalue_representation(); $representation->build($value, $ugroup_representation); return $representation; }
/** * @return Tracker_UgroupPermissionsConsistencyMessage */ public function checkConsistency(Tracker $template_tracker, Project $target_project) { if ($template_tracker->getProject() == $target_project) { $this->messenger->allIsWell(); return; } $ugroups = $this->permissions_retriever->getListOfInvolvedStaticUgroups($template_tracker); if (!$ugroups) { $this->messenger->allIsWell(); return; } $template_ugroups_names = array_map(array($this, 'extractUGroupName'), $ugroups); $target_ugroups = $this->ugroup_manager->getStaticUGroups($target_project); $target_ugroups_names = array_map(array($this, 'extractUGroupName'), $target_ugroups); $diff = array_diff($template_ugroups_names, $target_ugroups_names); if ($diff) { $this->messenger->ugroupsMissing($diff); } else { $this->messenger->ugroupsAreTheSame($template_ugroups_names); } }
private function exportProjectUgroups(Project $project, SimpleXMLElement $into_xml) { $this->logger->debug("Exporting project's static ugroups"); $ugroups = $this->ugroup_manager->getStaticUGroups($project); if (empty($ugroups)) { return; } $ugroups_node = $into_xml->addChild('ugroups'); foreach ($ugroups as $ugroup) { $this->logger->debug("Current static ugroups: " . $ugroup->getName()); $ugroup_node = $ugroups_node->addChild('ugroup'); $ugroup_node->addAttribute('name', $ugroup->getNormalizedName()); $ugroup_node->addAttribute('description', $ugroup->getDescription()); $members_node = $ugroup_node->addChild('members'); foreach ($ugroup->getMembers() as $member) { $this->user_xml_exporter->exportUser($member, $members_node, 'member'); } } $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/ugroups.rng'); $this->xml_validator->validate($ugroups_node, $rng_path); }
function send_new_project_email(Project $project) { $ugroup_manager = new UGroupManager(); $admin_ugroup = $ugroup_manager->getUGroup($project, ProjectUGroup::PROJECT_ADMIN); $mail_manager = new MailManager(); $hp = Codendi_HTMLPurifier::instance(); foreach ($admin_ugroup->getMembers() as $user) { /* @var $user PFUser */ $language = $user->getLanguage(); $subject = $GLOBALS['sys_name'] . ' ' . $language->getText('include_proj_email', 'proj_approve', $project->getUnixName()); $message = ''; include $language->getContent('include/new_project_email', null, null, '.php'); $mail = $mail_manager->getMailByType('html'); $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject, CODENDI_PURIFIER_CONVERT_HTML)); $mail->setTo($user->getEmail()); $mail->setSubject($subject); $mail->setBodyHtml($message); $mail->send(); } return true; }
/** * @param array $gerrit_servers * @param Project $project */ private function createProjectOnServers(array $gerrit_servers, Project $project) { $ugroups = $this->ugroup_manager->getUGroups($project); $admin_ugroup = $this->getAdminUGroup($ugroups); $project_name = $project->getUnixName(); foreach ($gerrit_servers as $gerrit_server) { $this->membership_manager->createArrayOfGroupsForServer($gerrit_server, $ugroups); $driver = $this->driver_factory->getDriver($gerrit_server); if (!$driver->doesTheParentProjectExist($gerrit_server, $project_name)) { $admin_group_name = $project_name . '/' . $admin_ugroup->getNormalizedName(); $project_name = $driver->createProjectWithPermissionsOnly($gerrit_server, $project, $admin_group_name); } } }
private function getUgroupIdsForPermissions(Project $project, SimpleXMLElement $permission_xmlnode) { $ugroup_ids = array(); foreach ($permission_xmlnode->children() as $ugroup) { if ($ugroup->getName() === self::UGROUP_TAG) { $ugroup_name = (string) $ugroup; $ugroup = $this->ugroup_manager->getUGroupByName($project, $ugroup_name); if ($ugroup === null) { $this->logger->error("Could not find any ugroup named {$ugroup_name}"); throw new GitXmlImporterUGroupNotFoundException($ugroup_name); } array_push($ugroup_ids, $ugroup->getId()); } } return $ugroup_ids; }
protected function getUgroupRESTRepresentation($u_group_id) { $ugroup_manager = new UGroupManager($this->getDao()); $u_group = $ugroup_manager->getById($u_group_id); $classname_with_namespace = 'Tuleap\\Project\\REST\\UserGroupRepresentation'; $representation = new $classname_with_namespace(); $representation->build($this->getField()->getTracker()->getProject()->getID(), $u_group); return $representation; }
/** * Delete ugroup * * @return false if error */ function ugroup_delete($group_id, $ugroup_id) { global $Language; if (!$ugroup_id) { $GLOBALS['Response']->addFeedback('error', $Language->getText('project_admin_ugroup_utils', 'ug_not_given')); return false; } $project = ProjectManager::instance()->getProject($group_id); $ugroup_manager = new UGroupManager(); $ugroup = $ugroup_manager->getUGroupWithMembers($project, $ugroup_id); $sql = "DELETE FROM ugroup WHERE group_id=" . db_ei($group_id) . " AND ugroup_id=" . db_ei($ugroup_id); $result = db_query($sql); if (!$result || db_affected_rows($result) < 1) { $GLOBALS['Response']->addFeedback('error', $Language->getText('project_admin_editgroupinfo', 'upd_fail', db_error() ? db_error() : ' ')); return false; } $GLOBALS['Response']->addFeedback('info', $Language->getText('project_admin_ugroup_utils', 'g_del')); // Now remove users $sql = "DELETE FROM ugroup_user WHERE ugroup_id=" . db_ei($ugroup_id); $result = db_query($sql); if (!$result) { $GLOBALS['Response']->addFeedback('error', $Language->getText('project_admin_ugroup_utils', 'cant_remove_u', db_error())); return false; } $GLOBALS['Response']->addFeedback('info', $Language->getText('project_admin_ugroup_utils', 'all_u_removed')); // raise an event for ugroup deletion $em = EventManager::instance(); $em->processEvent('project_admin_ugroup_deletion', array('group_id' => $group_id, 'ugroup_id' => $ugroup_id, 'ugroup' => $ugroup)); // Last, remove permissions for this group $perm_cleared = permission_clear_ugroup($group_id, $ugroup_id); if (!$perm_cleared) { $GLOBALS['Response']->addFeedback('error', $Language->getText('project_admin_ugroup_utils', 'cant_remove_perm', db_error())); return false; } else { if ($perm_cleared > 1) { $perm_cleared--; $GLOBALS['Response']->addFeedback('warning', $Language->getText('project_admin_ugroup_utils', 'perm_warning', $perm_cleared)); } } // Now log in project history group_add_history('del_ug', '', $group_id, array($ugroup->getName())); return true; }
public function getFullRESTValue(Tracker_FormElement_Field_List_Value $value) { $class_user_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation'; $ugroup_representation = new $class_user_representation(); $ugroup_manager = new UGroupManager(); $project = $this->getField()->getTracker()->getProject(); $user_group = $ugroup_manager->getUGroupByName($project, $value->getLabel()); $ugroup_representation->build($project->getID(), $user_group); return $ugroup_representation; }
protected function getUgroupBindingSource($id) { $ugroup_manager = new UGroupManager(); return $ugroup_manager->getUgroupBindingSource($id); }
/** * Retrieve the recipient list for all ugroup_id's * * @return Array */ public function getRecipients() { $recipients = array(); $uGroupManager = new UGroupManager(); $um = UserManager::instance(); $ugroups = $this->getUgroups(true); foreach ($ugroups as $ugroupId) { if ($ugroupId < 100) { $members = $uGroupManager->getDynamicUGroupsMembers($ugroupId, $this->getTracker()->getGroupId()); if ($members && !$members->isError()) { foreach ($members as $member) { $user = $um->getUserById($member['user_id']); $recipients[$user->getId()] = $user; } } } else { $uGroup = $uGroupManager->getById($ugroupId); $members = $uGroup->getMembers(); foreach ($members as $user) { $recipients[$user->getId()] = $user; } } } return $recipients; }
function news_fetch_ugroups($project) { $ugroup_manager = new UGroupManager(); $hp = Codendi_HTMLPurifier::instance(); $excluded_ugroups = array(ProjectUGroup::NONE, ProjectUGroup::ANONYMOUS, ProjectUGroup::REGISTERED, ProjectUGroup::TRACKER_ADMIN); $ugroups = $ugroup_manager->getUGroups($project, $excluded_ugroups); $html = ''; $html .= '<select multiple="multiple" name="send_news_to[]">'; foreach ($ugroups as $ugroup) { $html .= '<option value="' . $ugroup->getId() . '">'; $html .= $hp->purify($ugroup->getTranslatedName()); $html .= '</option>'; } $html .= '</select>'; return $html; }
public function getRESTAvailableValues() { $type = $this->getBind()->getType(); if ($type === Tracker_FormElement_Field_List_Bind_Users::TYPE) { return array('resource' => array('type' => 'users', 'uri' => 'users/?query=')); } if ($type === Tracker_FormElement_Field_List_Bind_Ugroups::TYPE) { $class_user_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation'; $ugroup_manager = new UGroupManager(); $project = $this->getTracker()->getProject(); $user_groups = $ugroup_manager->getUGroups($project); $values = array(); foreach ($user_groups as $ugroup) { $ugroup_representation = new $class_user_representation(); $ugroup_representation->build($project->getID(), $ugroup); $values[] = $ugroup_representation; } return $values; } return parent::getRESTAvailableValues(); }
print '<P><h2>' . $Language->getText('project_admin_editugroup', 'ug_admin', $ugroup_name) . '</h2>'; echo '<p>' . $Language->getText('project_admin_editugroup', 'upd_ug_name') . '</p>'; echo '<form method="post" name="form_create" action="/project/admin/ugroup.php?group_id=' . $group_id . '" onSubmit="return selIt();"> <input type="hidden" name="func" value="do_update"> <input type="hidden" name="group_id" value="' . $group_id . '"> <input type="hidden" name="ugroup_id" value="' . $ugroup_id . '">'; display_name_and_desc_form($ugroup_name, $ugroup_description); echo '<tr><td></td><td><input type="submit" value="' . $Language->getText('global', 'btn_submit') . '" /></td></tr>'; echo '</table>'; echo '</form>'; $ugroupUpdateUsersAllowed = true; $em->processEvent(Event::UGROUP_UPDATE_USERS_ALLOWED, array('ugroup_id' => $ugroup_id, 'allowed' => &$ugroupUpdateUsersAllowed)); echo '<hr /><p><b>' . $Language->getText('project_admin_editugroup', 'group_members') . '</b></p>'; echo '<div style="padding-left:10px">'; // Get existing members from group $uGroupMgr = new UGroupManager(); $uGroup = $uGroupMgr->getById($request->get('ugroup_id')); $members = $uGroup->getMembers(); if (count($members) > 0) { echo '<form action="ugroup_remove_user.php" method="POST">'; echo '<input type="hidden" name="group_id" value="' . $group_id . '">'; echo '<input type="hidden" name="ugroup_id" value="' . $ugroup_id . '">'; echo '<table>'; $i = 0; $hp = Codendi_HTMLPurifier::instance(); $userHelper = UserHelper::instance(); foreach ($members as $user) { echo '<tr class="' . html_get_alt_row_color(++$i) . '">'; echo '<td>' . $hp->purify($userHelper->getDisplayNameFromUser($user)) . '</td>'; if ($ugroupUpdateUsersAllowed) { echo '<td>';
/** * Retrieve the recipient list for all ugroup_id * * @return Array */ private function getRecipientsFromUgroups() { $recipients = array(); $uGroupManager = new UGroupManager(); $ugroups = $this->getUgroups(true); foreach ($ugroups as $ugroupId) { if ($ugroupId < 100) { $members = $uGroupManager->getDynamicUGroupsMembers($ugroupId, $this->getTracker()->getGroupId()); } else { $uGroup = $uGroupManager->getById($ugroupId); $members = $uGroup->getMembers(); } foreach ($members as $user) { $recipients[$user->getId()] = $user; } } return $recipients; }