diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 164675e3d4..ebf95a2c43 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -678,7 +678,7 @@ class gitlabModel extends model $allResults = array(); for($page = 1; true; $page++) { - $results = json_decode(commonModel::http($host . "&simple=true&page={$page}&per_page=100")); + $results = json_decode(commonModel::http($url . "&page={$page}&per_page=100")); if(!is_array($results)) break; if(!empty($results)) $allResults = array_merge($allResults, $results); if(count($results)<100 or $page > 10) break; diff --git a/module/mr/control.php b/module/mr/control.php index b70439a853..f6f241039c 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -32,7 +32,9 @@ class mr extends control { $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); - $MRList = $this->mr->getList($mode, $param, $orderBy, $pager); + + $projects = $this->mr->getAllGitlabProjects(); + $MRList = $this->mr->getList($mode, $param, $orderBy, $pager, empty($projects) ? false : $projects); /* Save current URI to session. */ $this->session->set('mrList', $this->app->getURI(true), 'repo'); @@ -53,6 +55,7 @@ class mr extends control $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; $this->view->MRList = $MRList; + $this->view->projects = $projects; $this->view->pager = $pager; $this->view->mode = $mode; $this->view->param = $param; diff --git a/module/mr/model.php b/module/mr/model.php index 5565966381..f1b69d83c8 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -38,21 +38,38 @@ class mrModel extends model /** * Get MR list of gitlab project. * - * @param string $mode - * @param string $param - * @param string $orderBy - * @param object $pager + * @param string $mode + * @param string $param + * @param string $orderBy + * @param object $pager + * @param array|bool $filterProjects * @access public * @return array */ - public function getList($mode = 'all', $param = 'all', $orderBy = 'id_desc', $pager = null) + public function getList($mode = 'all', $param = 'all', $orderBy = 'id_desc', $pager = null, $filterProjects = array()) { + /* If filterProjects equals false,it means no permission. */ + if($filterProjects === false) return array(); + + $filterProjectSql = ''; + if(!empty($filterProjects)) + { + foreach($filterProjects as $gitlabID => $projects) + { + $projectIDList = array_keys($projects); + if(!empty($projectIDList)) $filterProjectSql .= "(gitlabID = {$gitlabID} and sourceProject ".helper::dbIN($projectIDList).") or "; + } + + if($filterProjectSql) $filterProjectSql = '(' . substr($filterProjectSql, 0, -3) . ')'; // Remove last or. + } + $MRList = $this->dao->select('*') ->from(TABLE_MR) ->where('deleted')->eq('0') ->beginIF($mode == 'status' and $param != 'all')->andWhere('status')->eq($param)->fi() ->beginIF($mode == 'assignee' and $param != 'all')->andWhere('assignee')->eq($param)->fi() ->beginIF($mode == 'creator' and $param != 'all')->andWhere('createdBy')->eq($param)->fi() + ->beginIF($filterProjectSql)->andWhere($filterProjectSql)->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); @@ -76,6 +93,42 @@ class mrModel extends model return array('' => '') + $MR; } + /** + * Get all gitlab server project,private projects that do not include guest permissions. + * + * @access public + * @return array + */ + public function getAllGitlabProjects() + { + $gitlabIDList = $this->dao->select('distinct gitlabID')->from(TABLE_MR) + ->where('deleted')->eq('0') + ->fetchPairs('gitlabID'); + + $allProjects = array(); + $gitlabUsers = $this->dao->select('providerID,openID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('account')->eq($this->app->user->account) + ->fetchPairs(); + foreach($gitlabIDList as $gitlabID) + { + if(!$this->app->user->admin and !isset($gitlabUsers[$gitlabID])) continue; + $allProjects[$gitlabID] = $this->gitlab->apiGetProjects($gitlabID); + } + + $allProjectPairs = array(); + foreach($allProjects as $gitlabID => $projects) + { + foreach($projects as $key => $project) + { + if(empty($project->permissions->project_access->access_level) or $project->permissions->project_access->access_level <= 10) continue; + $allProjectPairs[$gitlabID][$project->id] = $project; + } + } + + return $allProjectPairs; + } + /** * Create MR function. * diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 4a27fcd709..d017f89fa3 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -64,13 +64,11 @@
- sourceProject])) $projects[$MR->sourceProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject); ?> - targetProject])) $projects[$MR->targetProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject); ?>