Exemplo n.º 1
0
 public function _dispatchActionAndView($action, $repoId, $repositoryName, $user)
 {
     $pane = $this->request->get('pane');
     switch ($action) {
         #CREATE REF
         case 'create':
             $this->addView('create');
             break;
             #admin
         #admin
         case 'view':
             $this->addAction('getRepositoryDetails', array($this->groupId, $repoId));
             $this->addView('view');
             break;
             #ADD REF
         #ADD REF
         case 'add':
             $this->addAction('createReference', array($this->groupId, $repositoryName));
             $this->addView('index');
             break;
             #DELETE a repository
         #DELETE a repository
         case 'del':
             $this->addAction('deleteRepository', array($this->groupId, $repoId));
             $this->addView('index');
             break;
             #EDIT
         #EDIT
         case 'edit':
             $repository = $this->factory->getRepositoryById($repoId);
             if (empty($repository)) {
                 $this->addError($this->getText('actions_params_error'));
                 $this->redirect('/plugins/git/?action=index&group_id=' . $this->groupId);
                 return false;
             }
             if ($this->isAPermittedAction('clone') && $this->request->get('clone')) {
                 $valid = new Valid_UInt('parent_id');
                 $valid->required();
                 if ($this->request->valid($valid)) {
                     $parentId = (int) $this->request->get('parent_id');
                 }
                 $this->addAction('cloneRepository', array($this->groupId, $repositoryName, $parentId));
                 $this->addAction('getRepositoryDetails', array($this->groupId, $parentId));
                 $this->addView('view');
             } else {
                 if ($this->isAPermittedAction('save') && $this->request->get('save')) {
                     $repoDesc = null;
                     if ($this->request->exist('repo_desc')) {
                         $repoDesc = GitRepository::DEFAULT_DESCRIPTION;
                         $valid = new Valid_Text('repo_desc');
                         $valid->required();
                         if ($this->request->valid($valid)) {
                             $repoDesc = $this->request->get('repo_desc');
                         }
                     }
                     $repoAccess = null;
                     $valid = new Valid_String('repo_access');
                     $valid->required();
                     if ($this->request->valid($valid) || is_array($this->request->get('repo_access'))) {
                         $repoAccess = $this->request->get('repo_access');
                     }
                     $this->addAction('save', array($this->groupId, $repoId, $repoAccess, $repoDesc, $pane));
                     $this->addView('view');
                 } else {
                     $this->addError($this->getText('controller_access_denied'));
                     $this->redirect('/plugins/git/?group_id=' . $this->groupId);
                 }
             }
             break;
             #repo_management
         #repo_management
         case 'repo_management':
             $repository = $this->factory->getRepositoryById($repoId);
             if (empty($repository)) {
                 $this->addError($this->getText('actions_repo_not_found'));
                 $this->redirect('/plugins/git/?action=index&group_id=' . $this->groupId);
                 return false;
             }
             $this->addAction('repoManagement', array($repository));
             $this->addView('repoManagement');
             break;
         case 'mail':
             $this->processRepoManagementNotifications($pane, $repoId, $repositoryName, $user);
             break;
             #fork
         #fork
         case 'fork':
             $this->addAction('repoManagement', array($this->groupId, $repoId));
             $this->addView('forkRepositories');
             break;
             #confirm_private
         #confirm_private
         case 'confirm_private':
             if ($this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion')) {
                 $repository = $this->factory->getRepositoryById($repoId);
                 $this->addAction('confirmDeletion', array($this->groupId, $repository));
                 $this->addView('confirm_deletion', array(0 => array('repo_id' => $repoId)));
             } else {
                 if ($this->isAPermittedAction('save') && $this->request->get('save')) {
                     $valid = new Valid_Text('repo_desc');
                     $valid->required();
                     if ($this->request->valid($valid)) {
                         $repoDesc = $this->request->get('repo_desc');
                     }
                     $valid = new Valid_String('repo_access');
                     $valid->required();
                     if ($this->request->valid($valid)) {
                         $repoAccess = $this->request->get('repo_access');
                     }
                     $this->addAction('confirmPrivate', array($this->groupId, $repoId, $repoAccess, $repoDesc));
                     $this->addView('confirmPrivate');
                 }
             }
             break;
             #SET TO PRIVATE
         #SET TO PRIVATE
         case 'set_private':
             $this->addAction('setPrivate', array($this->groupId, $repoId));
             $this->addView('view');
             break;
         case 'fork_repositories':
             $this->addAction('getProjectRepositoryList', array($this->groupId));
             $this->addView('forkRepositories');
             break;
         case 'admin-git-admins':
             if ($this->request->get('submit')) {
                 $valid = new Valid_Numeric(GitPresenters_AdminGitAdminsPresenter::GIT_ADMIN_SELECTBOX_NAME);
                 $project = $this->projectManager->getProject($this->groupId);
                 if ($this->request->validArray($valid)) {
                     $select_project_ids = $this->request->get(GitPresenters_AdminGitAdminsPresenter::GIT_ADMIN_SELECTBOX_NAME);
                     if ($select_project_ids) {
                         $this->addAction('updateGitAdminGroups', array($project, $user, $select_project_ids));
                     } else {
                         $this->addError($this->getText('no_data_retrieved'));
                     }
                 } else {
                     $this->addError($this->getText('not_valid_request'));
                 }
             }
             $this->addView('adminGitAdminsView', array($this->areMirrorsEnabledForProject()));
             break;
         case 'admin':
         case 'admin-gerrit-templates':
             $project = $this->projectManager->getProject($this->groupId);
             if ($this->request->get('save')) {
                 $template_content = $this->request->getValidated('git_admin_config_data', 'text');
                 if ($this->request->getValidated('git_admin_template_id', 'uint')) {
                     $template_id = $this->request->get('git_admin_template_id');
                     $this->addAction('updateTemplate', array($project, $user, $template_content, $template_id));
                 } else {
                     $template_name = $this->request->getValidated('git_admin_file_name', 'string');
                     $this->addAction('createTemplate', array($project, $user, $template_content, $template_name));
                 }
             }
             if ($this->request->get('delete')) {
                 if ($this->request->getValidated('git_admin_template_id', 'uint')) {
                     $template_id = $this->request->get('git_admin_template_id');
                     $this->addAction('deleteGerritTemplate', array($template_id, $project, $user));
                 }
             }
             if ($this->permissions_manager->userIsGitAdmin($user, $project)) {
                 $this->addAction('generateGerritRepositoryAndTemplateList', array($project, $user));
                 $this->addView('adminGerritTemplatesView', array($this->areMirrorsEnabledForProject()));
             } else {
                 $this->addError($this->getText('controller_access_denied'));
                 $this->redirect('/plugins/git/?action=index&group_id=' . $this->groupId);
                 return false;
             }
             break;
         case 'admin-mass-update':
             if ($this->request->get('save-mass-change') || $this->request->get('go-to-mass-change')) {
                 $this->checkSynchronizerToken('/plugins/git/?group_id=' . (int) $this->groupId . '&action=admin-mass-update');
                 $repositories = $this->getRepositoriesFromIds($this->request->get('repository_ids'));
                 if (!$repositories) {
                     $this->addError($this->getText('actions_repo_not_found'));
                     $this->redirect('/plugins/git/?action=index&group_id=' . $this->groupId);
                 }
             }
             if ($this->request->get('go-to-mass-change')) {
                 $this->addAction('setSelectedRepositories', array($repositories));
                 $this->addView('adminMassUpdateView');
                 return;
             }
             if ($this->request->get('save-mass-change')) {
                 $this->addAction('updateMirroring', array($this->request->getProject(), $repositories, $this->request->get('selected_mirror_ids')));
             }
             $this->addView('adminMassUpdateSelectRepositoriesView');
             break;
         case 'admin-default-settings':
             $this->addView('adminDefaultSettings', array($this->areMirrorsEnabledForProject()));
             break;
         case 'fetch_git_config':
             $project = $this->projectManager->getProject($this->groupId);
             $this->setDefaultPageRendering(false);
             $this->addAction('fetchGitConfig', array($repoId, $user, $project));
             break;
         case 'fetch_git_template':
             $project = $this->projectManager->getProject($this->groupId);
             $template_id = $this->request->getValidated('template_id', 'uint');
             $this->setDefaultPageRendering(false);
             $this->addAction('fetchGitTemplate', array($template_id, $user, $project));
             break;
         case 'fork_repositories_permissions':
             $scope = self::SCOPE_PERSONAL;
             $valid = new Valid_UInt('repos');
             $valid->required();
             if ($this->request->validArray($valid)) {
                 $repos = $this->request->get('repos');
             }
             $valid = new Valid_UInt('to_project');
             if ($this->request->valid($valid)) {
                 $toProject = $this->request->get('to_project');
             }
             $valid = new Valid_String('path');
             $valid->required();
             $path = '';
             if ($this->request->valid($valid)) {
                 $path = $this->request->get('path');
             }
             $valid = new Valid_String('choose_destination');
             $valid->required();
             if ($this->request->valid($valid)) {
                 $scope = $this->request->get('choose_destination');
             }
             if (!empty($repos)) {
                 $this->addAction('forkRepositoriesPermissions', array($repos, $toProject, $path, $scope));
                 $this->addView('forkRepositoriesPermissions');
             } else {
                 $this->addError($this->getText('actions_params_error'));
                 $this->addAction('getProjectRepositoryList', array($this->groupId));
                 $this->addView('forkRepositories');
             }
             break;
         case 'do_fork_repositories':
             try {
                 if ($this->request->get('choose_destination') == self::SCOPE_PERSONAL) {
                     if ($this->user->isMember($this->groupId)) {
                         $this->_doDispatchForkRepositories($this->request, $user);
                     } else {
                         $this->addError($this->getText('controller_access_denied'));
                     }
                 } else {
                     $this->_doDispatchForkCrossProject($this->request, $user);
                 }
             } catch (MalformedPathException $e) {
                 $this->addError($this->getText('fork_malformed_path'));
             }
             $this->addAction('getProjectRepositoryList', array($this->groupId));
             $this->addView('forkRepositories');
             break;
         case "view_last_git_pushes":
             $vGroupId = new Valid_GroupId();
             $vGroupId->required();
             if ($this->request->valid($vGroupId)) {
                 $groupId = $this->request->get('group_id');
             }
             $vWeeksNumber = new Valid_UInt('weeks_number');
             if ($this->request->valid($vWeeksNumber)) {
                 $weeksNumber = $this->request->get('weeks_number');
             }
             if (empty($weeksNumber) || $weeksNumber > Git_LastPushesGraph::MAX_WEEKSNUMBER) {
                 $weeksNumber = 12;
             }
             $imageRenderer = new Git_LastPushesGraph($groupId, $weeksNumber);
             $imageRenderer->display();
             break;
         case 'migrate_to_gerrit':
             if (ForgeConfig::get('sys_auth_type') !== ForgeConfig::AUTH_TYPE_LDAP) {
                 $this->redirect('/plugins/git/?group_id=' . $this->groupId);
                 break;
             }
             $repo = $this->factory->getRepositoryById($repoId);
             $remote_server_id = $this->request->getValidated('remote_server_id', 'uint');
             $gerrit_template_id = $this->getValidatedGerritTemplateId($repo);
             if (empty($repo) || empty($remote_server_id) || empty($gerrit_template_id)) {
                 $this->addError($this->getText('actions_params_error'));
                 $this->redirect('/plugins/git/?group_id=' . $this->groupId);
             } else {
                 try {
                     $project_exists = $this->gerritProjectAlreadyExists($remote_server_id, $repo);
                     if ($project_exists) {
                         $this->addError($this->getText('gerrit_project_exists'));
                     } else {
                         $this->addAction('migrateToGerrit', array($repo, $remote_server_id, $gerrit_template_id));
                     }
                 } catch (Git_Driver_Gerrit_Exception $e) {
                     $this->addError($this->getText('gerrit_server_down'));
                 }
                 $this->addAction('redirectToRepoManagementWithMigrationAccessRightInformation', array($this->groupId, $repoId, $pane));
             }
             break;
         case 'disconnect_gerrit':
             $repo = $this->factory->getRepositoryById($repoId);
             if (empty($repo)) {
                 $this->addError($this->getText('actions_params_error'));
                 $this->redirect('/plugins/git/?group_id=' . $this->groupId);
             } else {
                 $this->addAction('disconnectFromGerrit', array($repo));
                 $this->addAction('redirectToRepoManagement', array($this->groupId, $repoId, $pane));
             }
             break;
         case 'delete_gerrit_project':
             $repo = $this->factory->getRepositoryById($repoId);
             $server = $this->gerrit_server_factory->getServerById($repo->getRemoteServerId());
             $project_gerrit_name = $this->driver_factory->getDriver($server)->getGerritProjectName($repo);
             try {
                 $this->driver_factory->getDriver($server)->deleteProject($server, $project_gerrit_name);
             } catch (ProjectDeletionException $exception) {
                 $this->addError($this->getText('project_deletion_not_possible', array($project_gerrit_name, $exception->getMessage())));
             } catch (Git_Driver_Gerrit_Exception $e) {
                 $this->addError($this->getText('gerrit_server_down'));
             }
             $migrate_access_right = $this->request->existAndNonEmpty('migrate_access_right');
             $this->addAction('redirectToRepoManagementWithMigrationAccessRightInformation', array($this->groupId, $repoId, $pane));
             break;
         case 'update_mirroring':
             $repository = $this->factory->getRepositoryById($repoId);
             if (!$repository) {
                 $this->addError($this->getText('actions_repo_not_found'));
             }
             $selected_mirror_ids = $this->request->get('selected_mirror_ids');
             if (is_array($selected_mirror_ids)) {
                 $this->addAction('updateMirroring', array($this->request->getProject(), array($repository), $selected_mirror_ids));
             } else {
                 $this->addError($this->getText('actions_mirror_ids_not_valid'));
             }
             $this->addAction('redirectToRepoManagement', array($this->groupId, $repository->getId(), $pane));
             break;
         case 'update_default_mirroring':
             $project = $this->request->getProject();
             $selected_mirror_ids = $this->request->get('selected_mirror_ids');
             if (is_array($selected_mirror_ids)) {
                 $this->addAction('updateDefaultMirroring', array($project, $selected_mirror_ids));
             } else {
                 $this->addError($this->getText('actions_mirror_ids_not_valid'));
             }
             $this->addView('adminDefaultSettings', array($this->areMirrorsEnabledForProject()));
             break;
         case 'restore':
             $this->addAction('restoreRepository', array($repoId, $this->groupId));
             break;
             #LIST
         #LIST
         default:
             $user_id = null;
             $valid = new Valid_UInt('user');
             $valid->required();
             if ($this->request->valid($valid)) {
                 $user_id = $this->request->get('user');
                 $this->addData(array('user' => $user_id));
             }
             $this->addAction('getProjectRepositoryList', array($this->groupId, $user_id));
             $this->addView('index');
             break;
     }
 }
Exemplo n.º 2
0
 public function _dispatchActionAndView($action, $repoId, $repositoryName, $user)
 {
     switch ($action) {
         #CREATE REF
         case 'create':
             $this->addView('create');
             break;
             #admin
         #admin
         case 'view':
             $this->addAction('getRepositoryDetails', array($this->groupId, $repoId));
             $this->addView('view');
             break;
             #ADD REF
         #ADD REF
         case 'add':
             $this->addAction('createReference', array($this->groupId, $repositoryName));
             $this->addView('index');
             break;
             #DELETE a repository
         #DELETE a repository
         case 'del':
             $this->addAction('deleteRepository', array($this->groupId, $repoId));
             $this->addView('index');
             break;
             #EDIT
         #EDIT
         case 'edit':
             if ($this->isAPermittedAction('clone') && $this->request->get('clone')) {
                 $valid = new Valid_UInt('parent_id');
                 $valid->required();
                 if ($this->request->valid($valid)) {
                     $parentId = (int) $this->request->get('parent_id');
                 }
                 $this->addAction('cloneRepository', array($this->groupId, $repositoryName, $parentId));
                 $this->addAction('getRepositoryDetails', array($this->groupId, $parentId));
                 $this->addView('view');
             } else {
                 if ($this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion')) {
                     $this->addAction('confirmDeletion', array($this->groupId, $repoId));
                     $this->addView('confirm_deletion', array(0 => array('repo_id' => $repoId)));
                 } else {
                     if ($this->isAPermittedAction('save') && $this->request->get('save')) {
                         $valid = new Valid_Text('repo_desc');
                         $valid->required();
                         if ($this->request->valid($valid)) {
                             $repoDesc = $this->request->get('repo_desc');
                         }
                         $valid = new Valid_String('repo_access');
                         $valid->required();
                         if ($this->request->valid($valid) || is_array($this->request->get('repo_access'))) {
                             $repoAccess = $this->request->get('repo_access');
                         }
                         $this->addAction('save', array($this->groupId, $repoId, $repoAccess, $repoDesc));
                         $this->addView('view');
                     } else {
                         $this->addError($this->getText('controller_access_denied'));
                         $this->redirect('/plugins/git/?group_id=' . $this->groupId);
                     }
                 }
             }
             break;
             #repo_management
         #repo_management
         case 'repo_management':
             $this->addAction('repoManagement', array($this->groupId, $repoId));
             $this->addView('repoManagement');
             break;
             #mail prefix
         #mail prefix
         case 'mail_prefix':
             $valid = new Valid_String('mail_prefix');
             $valid->required();
             if ($this->request->valid($valid)) {
                 $mailPrefix = $this->request->get('mail_prefix');
             } else {
                 $mailPrefix = '';
             }
             $this->addAction('notificationUpdatePrefix', array($this->groupId, $repoId, $mailPrefix));
             $this->addView('repoManagement');
             break;
             #add mail
         #add mail
         case 'add_mail':
             $validMails = array();
             $mails = array_map('trim', preg_split('/[,;]/', $this->request->get('add_mail')));
             $rule = new Rule_Email();
             $um = UserManager::instance();
             foreach ($mails as $mail) {
                 if ($rule->isValid($mail)) {
                     $validMails[] = $mail;
                 } else {
                     $user = $um->findUser($mail);
                     if ($user) {
                         $mail = $user->getEmail();
                         if ($mail) {
                             $validMails[] = $mail;
                         } else {
                             $this->addError($this->getText('no_user_mail', array($mail)));
                         }
                     } else {
                         $this->addError($this->getText('no_user', array($mail)));
                     }
                 }
             }
             $this->addAction('notificationAddMail', array($this->groupId, $repoId, $validMails));
             $this->addView('repoManagement');
             break;
             #remove mail
         #remove mail
         case 'remove_mail':
             $mails = array();
             $valid = new Valid_Email('mail');
             $valid->required();
             if ($this->request->validArray($valid)) {
                 $mails = $this->request->get('mail');
             }
             if (count($mails) > 0) {
                 $this->addAction('notificationRemoveMail', array($this->groupId, $repoId, $mails));
                 $this->addView('repoManagement');
             } else {
                 $this->addAction('repoManagement', array($this->groupId, $repoId));
                 $this->addView('repoManagement');
             }
             break;
             #fork
         #fork
         case 'fork':
             $this->addAction('repoManagement', array($this->groupId, $repoId));
             $this->addView('forkRepositories');
             break;
             #confirm_private
         #confirm_private
         case 'confirm_private':
             if ($this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion')) {
                 $this->addAction('confirmDeletion', array($this->groupId, $repoId));
                 $this->addView('confirm_deletion', array(0 => array('repo_id' => $repoId)));
             } else {
                 if ($this->isAPermittedAction('save') && $this->request->get('save')) {
                     $valid = new Valid_Text('repo_desc');
                     $valid->required();
                     if ($this->request->valid($valid)) {
                         $repoDesc = $this->request->get('repo_desc');
                     }
                     $valid = new Valid_String('repo_access');
                     $valid->required();
                     if ($this->request->valid($valid)) {
                         $repoAccess = $this->request->get('repo_access');
                     }
                     $this->addAction('confirmPrivate', array($this->groupId, $repoId, $repoAccess, $repoDesc));
                     $this->addView('confirmPrivate');
                 }
             }
             break;
             #SET TO PRIVATE
         #SET TO PRIVATE
         case 'set_private':
             $this->addAction('setPrivate', array($this->groupId, $repoId));
             $this->addView('view');
             break;
         case 'fork_repositories':
             $this->addAction('getProjectRepositoryList', array($this->groupId));
             $this->addView('forkRepositories');
             break;
         case 'do_fork_repositories':
             try {
                 if ($this->request->get('choose_destination') == 'personal') {
                     $this->_doDispatchForkRepositories($this->request, $user);
                 } else {
                     $this->_doDispatchForkCrossProject($this->request, $user);
                 }
             } catch (MalformedPathException $e) {
                 $this->addError($this->getText('fork_malformed_path'));
             }
             $this->addAction('getProjectRepositoryList', array($this->groupId));
             $this->addView('forkRepositories');
             break;
         case "view_last_git_pushes":
             $vGroupId = new Valid_GroupId();
             $vGroupId->required();
             if ($this->request->valid($vGroupId)) {
                 $groupId = $this->request->get('group_id');
             }
             $vWeeksNumber = new Valid_UInt('weeks_number');
             if ($this->request->valid($vWeeksNumber)) {
                 $weeksNumber = $this->request->get('weeks_number');
             }
             if (empty($weeksNumber) || $weeksNumber > Git_LastPushesGraph::MAX_WEEKSNUMBER) {
                 $weeksNumber = 12;
             }
             $imageRenderer = new Git_LastPushesGraph($groupId, $weeksNumber);
             $imageRenderer->display();
             break;
             #LIST
         #LIST
         default:
             $user_id = null;
             $valid = new Valid_UInt('user');
             $valid->required();
             if ($this->request->valid($valid)) {
                 $user_id = $this->request->get('user');
                 $this->addData(array('user' => $user_id));
             }
             $this->addAction('getProjectRepositoryList', array($this->groupId, $user_id));
             $this->addView('index');
             break;
     }
 }