* Finish task #60565,60566.

This commit is contained in:
caoyanyi
2022-07-12 09:45:31 +08:00
parent a5b2c8de20
commit e5ffd04c34
18 changed files with 485 additions and 798 deletions
+91 -370
View File
@@ -911,176 +911,6 @@ class gitlab extends control
$this->display();
}
/**
* Browse gitlab protect branch.
*
* @param int $gitlabID
* @param int $projectID
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $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, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
$branches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, $keyword, $orderBy);
/* Pager. */
$this->app->loadClass('pager', $static = true);
$recTotal = count($branches);
$pager = new pager($recTotal, $recPerPage, $pageID);
$branchList = array_chunk($branches, $pager->recPerPage);
$this->view->keyword = $keyword;
$this->view->pager = $pager;
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv;
$this->view->levelLang = $this->lang->gitlab->branch->branchCreationLevelList;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->project = $project;
$this->view->orderBy = $orderBy;
$this->view->branchList = empty($branchList) ? $branchList: $branchList[$pageID - 1];
$this->display();
}
/**
* Set a gitlab protect branch.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @access public
* @return void
*/
public function createBranchPriv($gitlabID, $projectID, $branch = '')
{
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->gitlab->checkUserAccess($gitlabID, $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 = urldecode(helper::safe64Decode($branch));
if($_POST)
{
$this->gitlab->createBranchPriv($gitlabID, $projectID, $branch);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseBranchPriv', "gitlabID=$gitlabID&projectID=$projectID")));
}
$branchPriv = new stdClass();
$branchPriv->name = '';
$branchPriv->mergeAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
$branchPriv->pushAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
$title = $this->lang->gitlab->createBranchPriv;
if($branch)
{
$title = $this->lang->gitlab->editBranchPriv;
$branchPriv = $this->gitlab->apiGetSingleBranchPriv($gitlabID, $projectID, $branch);
$branchPriv->name = helper::safe64Encode(urlencode($branchPriv->name));
$branchPriv->mergeAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->merge_access_levels);
$branchPriv->pushAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->push_access_levels);
}
$gitlabBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
$protectBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc');
$protectNames = array_keys($protectBranches);
$branches = array();
foreach($gitlabBranches as $oneBranch)
{
if(!in_array($oneBranch->name, $protectNames) || $oneBranch->name == $branch)
{
$branchName = helper::safe64Encode(urlencode($oneBranch->name));
$branches[$branchName] = $oneBranch->name;
}
}
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $title;
$this->view->pageTitle = $title;
$this->view->gitlabID = $gitlabID;
$this->view->branch = $branch;
$this->view->projectID = $projectID;
$this->view->branches = $branches;
$this->view->branchPriv = $branchPriv;
$this->display();
}
/**
* Edit a gitlab branch protect.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @access public
* @return void
*/
public function editBranchPriv($gitlabID, $projectID, $branch)
{
echo $this->fetch('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch");
}
/**
* Delete a gitlab protect branch.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @param string $confirm
* @access public
* @return void
*/
public function deleteBranchPriv($gitlabID, $projectID, $branch, $confirm = 'no')
{
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->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
if($confirm != 'yes')
{
$branch = urlencode($branch);
return print(js::confirm($this->lang->gitlab->branch->confirmDelete , inlink('deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch&confirm=yes")));
}
/* Fix error when request type is PATH_INFO and the branch name contains '-'.*/
$branch = urldecode(helper::safe64Decode($branch));
$reponse = $this->gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch);
/* If the status code beginning with 20 is returned or empty is returned, it is successful. */
if(!$reponse or substr($reponse->message, 0, 2) == '20')
{
$this->loadModel('action')->create('gitlabbranchPriv', $branch, 'deleted', '', $branch);
return print(js::reload('parent'));
}
echo js::alert($reponse->message);
}
/**
* Browse gitlab tag.
*
@@ -1135,206 +965,6 @@ class gitlab extends control
$this->display();
}
/**
* Browse gitlab protect tag.
*
* @param int $gitlabID
* @param int $projectID
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_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, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$this->session->set('gitlabTagPrivList', $this->app->getURI(true));
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
$gitlabTags = array();
$allTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
foreach($allTags as $tag)
{
$gitlabTags[$tag->name] = $tag;
}
$tagList = array();
$gitlabProtectTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID);
foreach($gitlabProtectTags as $gitlabProtectTag)
{
$tag = new stdClass();
$tag->name = $gitlabProtectTag->name;
$tag->lastCommitter = isset($gitlabTags[$tag->name]) ? $gitlabTags[$tag->name]->commit->committer_name : '';
$tag->accessLevels = $gitlabProtectTag->create_access_levels;
$tagList[] = $tag;
}
/* Data search. */
if($keyword)
{
foreach($tagList as $key => $tag)
{
if(strpos($tag->name, $keyword) === false) unset($tagList[$key]);
}
$tagList = array_values($tagList);
}
/* Data sort. */
list($order, $sort) = explode('_', $orderBy);
$orderList = array();
foreach($tagList as $tag) $orderList[] = $tag->$order;
array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $tagList);
/* Pager. */
$this->app->loadClass('pager', $static = true);
$recTotal = count($tagList);
$pager = new pager($recTotal, $recPerPage, $pageID);
$tagList = array_chunk($tagList, $pager->recPerPage);
$this->view->gitlab = $this->gitlab->getByID($gitlabID);
$this->view->pager = $pager;
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->keyword = $keyword;
$this->view->project = $project;
$this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1];
$this->view->orderBy = $orderBy;
$this->display();
}
/**
* Set a gitlab protect tag.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function createTagPriv($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')));
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
if($_POST)
{
$this->gitlab->createTagPriv($gitlabID, $projectID);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID")));
}
$gitlabTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
$protectTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc');
$protectNames = array_keys($protectTags);
$tags = array();
foreach($gitlabTags as $tag)
{
if(!in_array($tag->name, $protectNames)) $tags[$tag->name] = $tag->name;
}
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->createTagPriv;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->tags = $tags;
$this->display();
}
/**
* Edit a gitlab protect tag.
*
* @param int $gitlabID
* @param int $projectID
* @param string $tag
* @access public
* @return void
*/
public function editTagPriv($gitlabID, $projectID, $tag = '')
{
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->gitlab->checkUserAccess($gitlabID, $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 = urldecode(helper::safe64Decode($tag));
if($_POST)
{
$this->gitlab->createTagPriv($gitlabID, $projectID, $tag);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID")));
}
$tagPriv = $this->gitlab->apiGetSingleTagPriv($gitlabID, $projectID, $tag);
$tagPriv->createAccessLevel = $this->gitlab->checkAccessLevel($tagPriv->create_access_levels);
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->editTagPriv;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->tagPriv = $tagPriv;
$this->view->tag = $tag;
$this->display();
}
/**
* Delete a gitlab protect tag.
*
* @param int $gitlabID
* @param int $projectID
* @param string $tag
* @access public
* @return void
*/
public function deleteTagPriv($gitlabID, $projectID, $tag)
{
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->gitlab->checkUserAccess($gitlabID, $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 = urldecode(helper::safe64Decode($tag));
$reponse = $this->gitlab->apiDeleteTagPriv($gitlabID, $projectID, $tag);
/* If the status code beginning with 20 is returned or empty is returned, it is successful. */
if(!$reponse or substr($reponse->message, 0, 2) == '20')
{
$this->loadModel('action')->create('gitlabtagpriv', 0, 'deleted', '', $tag);
return print(js::reload('parent'));
}
echo js::alert($reponse->message);
}
/**
* Import gitlab issue to zentaopms.
*
@@ -1746,4 +1376,95 @@ class gitlab extends control
echo js::alert($reponse->message);
}
/**
* Manage a gitlab branch protected.
*
* @param int $repoID
* @param int $projectID
* @access public
* @return void
*/
public function manageBranchPriv($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, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$hasAccessBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc');
foreach($hasAccessBranches as $branch)
{
$branch->pushAccess = $this->gitlab->checkAccessLevel($branch->push_access_levels);
$branch->mergeAccess = $this->gitlab->checkAccessLevel($branch->merge_access_levels);
}
if(!empty($_POST))
{
$result = $this->gitlab->manageBranchPrivs($gitlabID, $projectID, $hasAccessBranches);
if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result))));
return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID")));
}
$allBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
$noAccessBranches = array();
foreach($allBranches as $branch)
{
if(!isset($hasAccessBranches[$branch->name])) $noAccessBranches[$branch->name] = $branch->name;
}
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->hasAccessBranches = $hasAccessBranches;
$this->view->noAccessBranches = $noAccessBranches;
$this->display();
}
/**
* Manage a gitlab tag protected.
*
* @param int $repoID
* @param int $projectID
* @access public
* @return void
*/
public function manageTagPriv($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, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
}
$hasAccessTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc');
foreach($hasAccessTags as $tag)
{
$tag->createAccess = $this->gitlab->checkAccessLevel($tag->create_access_levels);
}
if(!empty($_POST))
{
$result = $this->gitlab->manageTagPrivs($gitlabID, $projectID, $hasAccessTags);
if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result))));
return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID")));
}
$allTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
$noAccessTags = array();
foreach($allTags as $tag)
{
if(!isset($hasAccessTags[$tag->name])) $noAccessTags[$tag->name] = $tag->name;
}
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->hasAccessTags = $hasAccessTags;
$this->view->noAccessTags = $noAccessTags;
$this->display();
}
}