Merge branch 'devops20_caoyanyi' into 'devops20'

Devops20 caoyanyi

See merge request easycorp/zentaopms!1560
This commit is contained in:
李玉春
2022-01-24 06:07:03 +00:00
6 changed files with 63 additions and 32 deletions
+54 -28
View File
@@ -307,10 +307,23 @@ class gitlab extends control
*/
public function browseGroup($gitlabID, $orderBy = 'name_asc')
{
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseGroup;
$this->view->gitlabID = $gitlabID;
$this->view->gitlabGroupList = $this->gitlab->apiGetGroups($gitlabID, $orderBy);
$this->view->orderBy = $orderBy;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$groups = $this->gitlab->apiGetGroups($gitlabID, $orderBy);
$adminGroups = $this->gitlab->apiGetGroups($gitlabID, $orderBy, $this->gitlab->config->accessLevel['owner']);
$adminGropuIDList = array();
foreach($adminGroups as $group) $adminGropuIDList[] = $group->id;
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseGroup;
$this->view->gitlabID = $gitlabID;
$this->view->gitlabGroupList = $groups;
$this->view->adminGropuIDList = $adminGropuIDList;
$this->view->orderBy = $orderBy;
$this->display();
}
@@ -323,6 +336,12 @@ class gitlab extends control
*/
public function createGroup($gitlabID)
{
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
if($_POST)
{
$this->gitlab->createGroup($gitlabID);
@@ -349,6 +368,15 @@ class gitlab extends control
*/
public function editGroup($gitlabID, $groupID)
{
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
$members = $this->gitlab->apiGetGroupMembers($gitlabID, $groupID, $openID);
if(empty($members)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
if($_POST)
{
$this->gitlab->editGroup($gitlabID);
@@ -837,7 +865,6 @@ class gitlab extends control
*/
public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1)
{
$openID = 0;
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin)
@@ -879,15 +906,14 @@ class gitlab extends control
*/
public function createBranchPriv($gitlabID, $projectID, $branch = '')
{
$openID = 0;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
/* Fix error when request type is PATH_INFO and the branch name contains '-'.*/
if($branch) $branch = str_replace('*', '-', $branch);
@@ -961,15 +987,14 @@ class gitlab extends control
*/
public function deleteBranchPriv($gitlabID, $projectID, $branch, $confirm = 'no')
{
$openID = 0;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
if($confirm != 'yes')
{
@@ -1005,10 +1030,14 @@ class gitlab extends control
*/
public function browseTag($gitlabID, $projectID, $orderBy = 'updated_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$this->session->set('gitlabTagList', $this->app->getURI(true));
@@ -1037,7 +1066,7 @@ class gitlab extends control
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->keyword = $keyword;
$this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
$this->view->project = $project;
$this->view->gitlabTagList = $tagList;
$this->view->orderBy = $orderBy;
$this->display();
@@ -1057,14 +1086,14 @@ class gitlab extends control
*/
public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$openID = 0;
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
if(!isset($project->owner) or $project->owner->id != $openID) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$this->session->set('gitlabTagPrivList', $this->app->getURI(true));
@@ -1133,15 +1162,14 @@ class gitlab extends control
*/
public function createTagPriv($gitlabID, $projectID)
{
$openID = 0;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
if($_POST)
{
@@ -1179,15 +1207,14 @@ class gitlab extends control
*/
public function editTagPriv($gitlabID, $projectID, $tag = '')
{
$openID = 0;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
/* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
$tag = str_replace('*', '-', $tag);
@@ -1222,15 +1249,14 @@ class gitlab extends control
*/
public function deleteTagPriv($gitlabID, $projectID, $tag)
{
$openID = 0;
if(!$this->app->user->admin)
{
$openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
}
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
/* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
$tag = str_replace('*', '-', $tag);
+1
View File
@@ -15,6 +15,7 @@ $lang->gitlab->confirmDelete = 'Do you want to delete this GitLab server?';
$lang->gitlab->gitlabAccount = 'GitLab Account';
$lang->gitlab->zentaoAccount = 'Zentao Account';
$lang->gitlab->bindingStatus = 'Binding Status';
$lang->gitlab->notBind = 'Not bind';
$lang->gitlab->binded = 'Binded';
$lang->gitlab->bindedError = 'The bound user has been deleted or modified. Please bind again.';
$lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.';
+1
View File
@@ -15,6 +15,7 @@ $lang->gitlab->confirmDelete = '确认删除该GitLab吗?';
$lang->gitlab->gitlabAccount = 'GitLab用户';
$lang->gitlab->zentaoAccount = '禅道用户';
$lang->gitlab->bindingStatus = '绑定状态';
$lang->gitlab->notBind = '未绑定';
$lang->gitlab->binded = '已绑定';
$lang->gitlab->bindedError = '绑定的用户已删除或者已修改,请重新绑定';
$lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。';
+3 -1
View File
@@ -544,13 +544,15 @@ class gitlabModel extends model
*
* @param int $gitlabID
* @param int $groupID
* @param int $userID
* @access public
* @return object
*/
public function apiGetGroupMembers($gitlabID, $groupID)
public function apiGetGroupMembers($gitlabID, $groupID, $userID = 0)
{
$apiRoot = $this->getApiRoot($gitlabID);
$url = sprintf($apiRoot, "/groups/$groupID/members/all");
if($userID) $url .= "&user_ids=$userID";
$allResults = array();
for($page = 1; true; $page++)
+1 -1
View File
@@ -37,7 +37,7 @@
<?php if($gitlabUser->email) echo " &lt;" . $gitlabUser->email . "&gt;";?>
</td>
<td><?php echo html::select("zentaoUsers[$gitlabUser->id]", $userPairs, '', "class='form-control select chosen'" );?></td>
<td></td>
<td><?php echo $lang->gitlab->notBind;?></td>
</tr>
<?php endforeach;?>
<?php foreach($gitlabUsers as $gitlabUser):?>
+3 -2
View File
@@ -55,9 +55,10 @@
<td class='text' title='<?php echo substr($gitlabGroup->created_at, 0, 10);?>'><?php echo substr($gitlabGroup->created_at, 0, 10);?></td>
<td class='c-actions text-left'>
<?php
$adminClass = in_array($gitlabGroup->id, $adminGropuIDList) ? '' : 'disabled';
common::printLink('gitlab', 'manageGroupMembers', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", "<i class='icon icon-team'></i> ", '',"title='{$lang->gitlab->group->manageMembers}' class='btn btn-primary'");
common::printLink('gitlab', 'editGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", "<i class='icon icon-edit'></i> ", '', "title='{$lang->gitlab->group->edit}' class='btn btn-primary'");
if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'deleteGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->gitlab->deleteGroup}' class='btn'");
common::printLink('gitlab', 'editGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", "<i class='icon icon-edit'></i> ", '', "title='{$lang->gitlab->group->edit}' class='btn btn-primary {$adminClass}'");
if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'deleteGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->gitlab->deleteGroup}' class='btn {$adminClass}'");
?>
</td>
</tr>