* Finish task#48104
This commit is contained in:
@@ -656,7 +656,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;
|
||||
|
||||
@@ -32,7 +32,13 @@ 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 = array();
|
||||
if(!$this->app->user->admin)
|
||||
{
|
||||
$projects = $this->mr->getAllGitlabProjects();
|
||||
}
|
||||
$MRList = $this->mr->getList($mode, $param, $orderBy, $pager, $projects);
|
||||
|
||||
/* Save current URI to session. */
|
||||
$this->session->set('mrList', $this->app->getURI(true), 'repo');
|
||||
@@ -53,6 +59,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;
|
||||
|
||||
+55
-1
@@ -42,17 +42,35 @@ class mrModel extends model
|
||||
* @param string $param
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @param array $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())
|
||||
{
|
||||
$filterProjectSql = '';
|
||||
if(!empty($filterProjects))
|
||||
{
|
||||
foreach($filterProjects as $gitlabID => $projects)
|
||||
{
|
||||
$projectIDs = array_keys($projects);
|
||||
if(!empty($projectIDs)) $filterProjectSql .= "(gitlabID = {$gitlabID} and sourceProject ".helper::dbIN($projectIDs).") or ";
|
||||
}
|
||||
|
||||
if($filterProjectSql)
|
||||
{
|
||||
$filterProjectSql = substr($filterProjectSql, 0, -3); // Remove last or.
|
||||
$filterProjectSql = '(' . $filterProjectSql . ')';
|
||||
}
|
||||
}
|
||||
|
||||
$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 +94,42 @@ class mrModel extends model
|
||||
return array('' => '') + $MR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all gitlab server project,private projects that do not include guest permissions.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getAllGitlabProjects()
|
||||
{
|
||||
$gitlabIDs = $this->dao->select('distinct gitlabID')->from(TABLE_MR)
|
||||
->where('deleted')->eq('0')
|
||||
->fetchPairs('gitlabID');
|
||||
|
||||
$allProjects = array();
|
||||
$gitlabUsers = $this->dao->select('openID,providerID')->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gitlab')
|
||||
->andWhere('account')->eq($this->app->user->account)
|
||||
->fetchPairs('providerID', 'openID');
|
||||
foreach($gitlabIDs as $gitlabID)
|
||||
{
|
||||
if(!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.
|
||||
*
|
||||
|
||||
@@ -64,13 +64,13 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($MRList as $MR):?>
|
||||
<?php if(!isset($projects[$MR->sourceProject])) $projects[$MR->sourceProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject); ?>
|
||||
<?php if(!isset($projects[$MR->targetProject])) $projects[$MR->targetProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject); ?>
|
||||
<?php if(!isset($projects[$MR->gitlabID][$MR->sourceProject])) $projects[$MR->gitlabID][$MR->sourceProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->sourceProject); ?>
|
||||
<?php if(!isset($projects[$MR->gitlabID][$MR->targetProject])) $projects[$MR->gitlabID][$MR->targetProject] = $this->loadModel('gitlab')->apiGetSingleProject($MR->gitlabID, $MR->targetProject); ?>
|
||||
<tr>
|
||||
<td class='text'><?php echo $MR->id;?></td>
|
||||
<td class='text'><?php echo html::a(inlink('view', "mr={$MR->id}"), $MR->title);?></td>
|
||||
<td class='text' title='<?php echo $projects[$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch;?>'><?php echo $projects[$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch;?></td>
|
||||
<td class='text' title='<?php echo $projects[$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch;?>'><?php echo $projects[$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch;?></td>
|
||||
<td class='text' title='<?php echo $projects[$MR->gitlabID][$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch;?>'><?php echo $projects[$MR->gitlabID][$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch;?></td>
|
||||
<td class='text' title='<?php echo $projects[$MR->gitlabID][$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch;?>'><?php echo $projects[$MR->gitlabID][$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch;?></td>
|
||||
<?php if($MR->status == 'closed'):?>
|
||||
<td class='text'><?php echo zget($lang->mr->statusList, $MR->status);?></td>
|
||||
<?php else:?>
|
||||
|
||||
Reference in New Issue
Block a user