public function process() { $parameters = $this->getParametersAsArray(); //repo id $repositoryId = ''; if (!empty($parameters[0])) { $repositoryId = $parameters[0]; } else { $this->error('Missing argument repository id'); return false; } //repo access $repositoryAccess = ''; if (!empty($parameters[1])) { $repositoryAccess = $parameters[1]; } else { $this->error('Missing argument repository access'); return false; } //save $repository = new GitRepository(); $repository->setId($repositoryId); try { $repository->load(); $repository->setAccess($repositoryAccess); $repository->changeAccess(); } catch (GitDaoException $e) { $this->error($e->getMessage()); return false; } $this->done(); }
/** * Wrapper for GitRepository for unit testing purpose * * @param array $row data of the repository to instantiate * * @return GitRepository */ protected function getRepository($row) { $r = new GitRepository(); $r->setId($row[GitDao::REPOSITORY_ID]); $r->load(); return $r; }
public function __construct(GitPlugin $plugin) { parent::__construct(); $this->userManager = UserManager::instance(); $this->projectManager = ProjectManager::instance(); $this->factory = new GitRepositoryFactory(new GitDao(), $this->projectManager); $matches = array(); if (preg_match_all('/^\\/plugins\\/git\\/index.php\\/(\\d+)\\/([^\\/][a-zA-Z]+)\\/([a-zA-Z\\-\\_0-9]+)\\/\\?{0,1}.*/', $_SERVER['REQUEST_URI'], $matches)) { $this->request->set('group_id', $matches[1][0]); $this->request->set('action', $matches[2][0]); $repo_id = 0; //repository id is passed if (preg_match('/^([0-9]+)$/', $matches[3][0]) === 1) { $repo_id = $matches[3][0]; } else { //get repository by name and group id to retrieve repo id $repo = new GitRepository(); $repo->setName($matches[3][0]); $repo->setProject($this->projectManager->getProject($matches[1][0])); try { $repo->load(); } catch (Exception $e) { $this->addError('Bad request'); $this->redirect('/'); } $repo_id = $repo->getId(); } $this->request->set('repo_id', $repo_id); } $this->plugin = $plugin; $valid = new Valid_GroupId('group_id'); $valid->required(); if ($this->request->valid($valid)) { $this->groupId = (int) $this->request->get('group_id'); } $valid = new Valid_String('action'); $valid->required(); if ($this->request->valid($valid)) { $this->action = $this->request->get('action'); } if (empty($this->action)) { $this->action = 'index'; } if (empty($this->groupId)) { $this->addError('Bad request'); $this->redirect('/'); } $this->projectName = $this->projectManager->getProject($this->groupId)->getUnixName(); if (!PluginManager::instance()->isPluginAllowedForProject($this->plugin, $this->groupId)) { $this->addError($this->getText('project_service_not_available')); $this->redirect('/projects/' . $this->projectName . '/'); } $this->permittedActions = array(); }
function permission_user_allowed_to_change($params) { if (!$params['allowed']) { if (!$this->_cached_permission_user_allowed_to_change) { if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { require_once 'GitRepository.class.php'; $repository = new GitRepository(); $repository->setId($params['object_id']); try { $repository->load(); //Only project admin can update perms of project repositories //Only repo owner can update perms of personal repositories $user = UserManager::instance()->getCurrentUser(); $this->_cached_permission_user_allowed_to_change = $repository->belongsTo($user) || $user->isMember($repository->getProjectId(), 'A'); } catch (Exception $e) { // do nothing } } } $params['allowed'] = $this->_cached_permission_user_allowed_to_change; } }
/** * LIST OF MAILS TO NOTIFY */ protected function _listOfMails() { $r = new GitRepository(); $r->setId($this->repoId); $r->load(); $mails = $r->getNotifiedMails(); ?> <h3><?php echo $this->getText('notified_mails_title'); ?> </h3> <?php if (!empty($mails)) { ?> <form id="add_user_form" action="/plugins/git/" method="POST"> <input type="hidden" id="action" name="action" value="remove_mail" /> <input type="hidden" id="group_id" name="group_id" value="<?php echo $this->groupId; ?> " /> <input type="hidden" id="repo_id" name="repo_id" value="<?php echo $this->repoId; ?> " /> <table> <?php $i = 0; foreach ($mails as $mail) { echo '<tr class="' . html_get_alt_row_color(++$i) . '">'; echo '<td>' . $mail . '</td>'; echo '<td>'; echo '<input type="checkbox" name="mail[]" value="' . $this->HTMLPurifier->purify($mail) . '" />'; echo '</a>'; echo '</td>'; echo '</tr>'; } ?> </table> <input type="submit" value="<?php echo $GLOBALS['Language']->getText('global', 'btn_delete'); ?> " /> </form> <?php } else { ?> <h4><?php echo $this->getText('add_mail_existing'); ?> </h4> <?php } }
/** * This method allows one to save any repository attribues changes from the web interface. * @param <type> $repoId * @param <type> $repoAccess * @param <type> $repoDescription * @return <type> */ public function save($projectId, $repoId, $repoAccess, $repoDescription) { $c = $this->getController(); if (empty($repoId)) { $c->addError($this->getText('actions_params_error')); $c->redirect('/plugins/git/?action=index&group_id=' . $projectId); return false; } if (empty($repoAccess) || empty($repoDescription)) { $c->addError($this->getText('actions_params_error')); $c->redirect('/plugins/git/index.php/' . $projectId . '/view/' . $repoId . '/'); return false; } $repository = new GitRepository(); $repository->setId($repoId); try { $repository->load(); if (!empty($repoAccess)) { if ($repository->getBackend() instanceof Git_Backend_Gitolite) { $repository->getBackend()->savePermissions($repository, $repoAccess); } else { if ($repository->getAccess() != $repoAccess) { $this->systemEventManager->createEvent('GIT_REPO_ACCESS', $repoId . SystemEvent::PARAMETER_SEPARATOR . $repoAccess, SystemEvent::PRIORITY_HIGH); $c->addInfo($this->getText('actions_repo_access')); } } } if (strlen($repoDescription) > 1024) { $c->addError($this->getText('actions_long_description')); } elseif (!empty($repoDescription)) { $repository->setDescription($repoDescription); } } catch (GitDaoException $e) { $c->addError($this->getText('actions_repo_not_found')); $c->redirect('/plugins/git/?group_id=' . $projectId); return false; } catch (GitRepositoryException $e1) { die('GitRepositoryException'); $c->addError($e1->getMessage()); return false; } try { $repository->save(); } catch (GitDaoException $e) { $c->addError($e->getMessage()); $c->redirect('/plugins/git/index.php/' . $projectId . '/view/' . $repoId . '/'); return false; } $c->addInfo($this->getText('actions_save_repo_process')); $c->redirect('/plugins/git/index.php/' . $projectId . '/view/' . $repoId . '/'); return; }
function permission_user_allowed_to_change($params) { if (!$params['allowed']) { $user = $this->getCurrentUser(); $project = $this->getProjectManager()->getProject($params['group_id']); if ($this->getGitPermissionsManager()->userIsGitAdmin($user, $project)) { $this->_cached_permission_user_allowed_to_change = true; } if (!$this->_cached_permission_user_allowed_to_change) { if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { $repository = new GitRepository(); $repository->setId($params['object_id']); try { $repository->load(); //Only project admin can update perms of project repositories //Only repo owner can update perms of personal repositories $this->_cached_permission_user_allowed_to_change = $repository->belongsTo($user) || $this->getPermissionsManager()->userIsGitAdmin($user, $project); } catch (Exception $e) { // do nothing } } } $params['allowed'] = $this->_cached_permission_user_allowed_to_change; } }
public function process() { $parameters = $this->getParametersAsArray(); //print_r($parameters); $project = null; if (!empty($parameters[0])) { $project = $this->getProject($parameters[0]); } else { $this->error('Missing argument project id'); return false; } $repositoryName = ''; if (!empty($parameters[1])) { $repositoryName = $parameters[1]; } else { $this->error('Missing argument repository name'); return false; } $parentId = ''; if (!empty($parameters[2])) { $parentId = $parameters[2]; } else { $this->error('Missing argument parent id'); return false; } $userId = 0; if (!empty($parameters[3])) { $userId = $parameters[3]; } else { $this->error('Missing argument user id'); return false; } try { $repository = new GitRepository(); $repository->setProject($project); $repository->setId($parentId); //load before setting creator $repository->load(); $user = null; if (!empty($userId)) { $user = UserManager::instance()->getUserById($userId); } if (!empty($user)) { $repository->setCreator($user); } $repository->forkShell($repositoryName); $this->done(); } catch (GitDaoException $e1) { $this->error($e1->getMessage()); return false; } catch (GitDriverException $e2) { $this->error($e2->getMessage()); return false; } catch (GitBackendException $e3) { $this->error($e3->getMessage()); return false; } catch (Exception $e4) { $this->error($e4->getMessage()); return false; } }
/** * Load a repository from its id. Mainly used as a wrapper for tests * * @param $repositoryId Id of the repository * * @return GitRepository */ function loadRepositoryFromId($repositoryId) { $repository = new GitRepository(); $repository->setId($repositoryId); $repository->load(); return $repository; }