*Finish task#48107,48106,48105,48103 and adjust code
This commit is contained in:
@@ -117,6 +117,7 @@ $config->gitlab->objectTypes['story'] = '需求';
|
||||
|
||||
$config->gitlab->accessLevel = array();
|
||||
$config->gitlab->accessLevel['guest'] = 10;
|
||||
$config->gitlab->accessLevel['reporter'] = 20;
|
||||
$config->gitlab->accessLevel['developer'] = 30;
|
||||
$config->gitlab->accessLevel['maintainer'] = 40;
|
||||
$config->gitlab->accessLevel['owner'] = 50;
|
||||
|
||||
@@ -669,11 +669,12 @@ class gitlabModel extends model
|
||||
/**
|
||||
* Get projects of one gitlab.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $gitlabID
|
||||
* @param string $simple
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function apiGetProjects($gitlabID)
|
||||
public function apiGetProjects($gitlabID, $simple = 'true')
|
||||
{
|
||||
$apiRoot = $this->getApiRoot($gitlabID);
|
||||
if(!$apiRoot) return array();
|
||||
@@ -683,7 +684,7 @@ class gitlabModel extends model
|
||||
$allResults = array();
|
||||
for($page = 1; true; $page++)
|
||||
{
|
||||
$results = json_decode(commonModel::http($url . "&page={$page}&per_page=100"));
|
||||
$results = json_decode(commonModel::http($url . "&simple={$simple}&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;
|
||||
|
||||
+14
-1
@@ -82,12 +82,16 @@ class mr extends control
|
||||
return $this->send($result);
|
||||
}
|
||||
|
||||
$gitlabHosts = $this->loadModel('gitlab')->getPairs();
|
||||
$gitlabUsers = $this->gitlab->getGitLabListByAccount();
|
||||
foreach($gitlabHosts as $gitlabID=> $gitlabHost) if(!$this->app->user->admin and !isset($gitlabUsers[$gitlabID])) unset($gitlabHosts[$gitlabID]);
|
||||
|
||||
$this->app->loadLang('repo'); /* Import lang in repo module. */
|
||||
$this->app->loadLang('compile');
|
||||
$this->view->title = $this->lang->mr->create;
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed');
|
||||
$this->view->jobList = $this->loadModel('job')->getList();
|
||||
$this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
|
||||
$this->view->gitlabHosts = $gitlabHosts;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -152,6 +156,15 @@ class mr extends control
|
||||
|
||||
$gitlabUsers = $this->gitlab->getUserAccountIdPairs($MR->gitlabID);
|
||||
|
||||
/* Check permissions. */
|
||||
if(!$this->app->user->admin)
|
||||
{
|
||||
$sourceProject = $this->gitlab->apiGetSingleProject($MR->gitlabID, $MR->sourceProject);
|
||||
$isDeveloper = $this->gitlab->checkUserAccess($MR->gitlabID, 0, $sourceProject, array(), 'developer');
|
||||
|
||||
if(!isset($gitlabUsers[$this->app->user->account]) or !$isDeveloper) die(js::alert($this->lang->mr->errorLang[3]) . js::locate($this->createLink('mr', 'browse')));
|
||||
}
|
||||
|
||||
/* Import lang for required modules. */
|
||||
$this->loadModel('repo');
|
||||
$this->loadModel('job');
|
||||
|
||||
@@ -5,7 +5,7 @@ $(function()
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
if(gitlabID == '') return false;
|
||||
|
||||
var url = createLink('repo', 'ajaxgetgitlabprojects', "gitlabID=" + gitlabID);
|
||||
var url = createLink('repo', 'ajaxgetgitlabprojects', "gitlabID=" + gitlabID + "&projectIdList=&filter=IS_DEVELOPER");
|
||||
$.get(url, function(response)
|
||||
{
|
||||
$('#sourceProject').html('').append(response);
|
||||
|
||||
+4
-7
@@ -94,7 +94,7 @@ class mrModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all gitlab server project,private projects that do not include guest permissions.
|
||||
* Get all gitlab server projects. If not an administrator, the role of project member should be higher than guest.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
@@ -106,14 +106,11 @@ class mrModel extends model
|
||||
->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();
|
||||
$gitlabUsers = $this->gitlab->getGitLabListByAccount();
|
||||
foreach($gitlabIDList as $gitlabID)
|
||||
{
|
||||
if(!$this->app->user->admin and !isset($gitlabUsers[$gitlabID])) continue;
|
||||
$allProjects[$gitlabID] = $this->gitlab->apiGetProjects($gitlabID);
|
||||
$allProjects[$gitlabID] = $this->gitlab->apiGetProjects($gitlabID, 'false');
|
||||
}
|
||||
|
||||
$allProjectPairs = array();
|
||||
@@ -121,7 +118,7 @@ class mrModel extends model
|
||||
{
|
||||
foreach($projects as $key => $project)
|
||||
{
|
||||
if(empty($project->permissions->project_access->access_level) or $project->permissions->project_access->access_level <= 10) continue;
|
||||
if($this->gitlab->checkUserAccess($gitlabID, 0, $project, array(), 'reporter') == false) continue;
|
||||
$allProjectPairs[$gitlabID][$project->id] = $project;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-2
@@ -1123,9 +1123,24 @@ class repo extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetGitlabProjects($gitlabID, $projectIdList = '')
|
||||
public function ajaxGetGitlabProjects($gitlabID, $projectIdList = '', $filter = '')
|
||||
{
|
||||
$projects = $this->loadModel('gitlab')->apiGetProjects($gitlabID);
|
||||
if($this->app->user->admin)
|
||||
{
|
||||
$projects = $this->loadModel('gitlab')->apiGetProjects($gitlabID);
|
||||
}
|
||||
else
|
||||
{
|
||||
$gitlabUser = $this->loadModel('gitlab')->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
|
||||
if(!$gitlabUser) $this->send(array('message' => array()));
|
||||
|
||||
$projects = $this->loadModel('gitlab')->apiGetProjects($gitlabID, $filter ? 'false' : 'true');
|
||||
if($filter == 'IS_DEVELOPER')
|
||||
{
|
||||
foreach($projects as $key => $project) if($this->gitlab->checkUserAccess($gitlabID, 0, $project, array(), 'developer') == false) unset($projects[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!$projects) $this->send(array('message' => array()));
|
||||
$projectIdList = $projectIdList ? explode(',', $projectIdList) : null;
|
||||
|
||||
Reference in New Issue
Block a user