* Finish task#46555

This commit is contained in:
zenggang
2021-12-30 03:08:42 +00:00
parent 6bbb031a07
commit bfde525f13
11 changed files with 268 additions and 3 deletions
+1
View File
@@ -126,6 +126,7 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab Group';
$lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected';
$lang->action->objectTypes['kanbanspace'] = 'Kanban Space';
$lang->action->objectTypes['kanban'] = 'Kanban';
$lang->action->objectTypes['kanbanregion'] = 'Kanban Region';
+1
View File
@@ -126,6 +126,7 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab群组';
$lang->action->objectTypes['gitlabbranch'] = 'GitLab分支';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保护分支';
$lang->action->objectTypes['gitlabtag'] = 'GitLab标签';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab标签保护';
$lang->action->objectTypes['kanbanspace'] = '看板空间';
$lang->action->objectTypes['kanban'] = '看板';
$lang->action->objectTypes['kanbanregion'] = '看板区域';
+98
View File
@@ -974,6 +974,104 @@ 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)
{
$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->levelLang = $this->lang->gitlab->branch->branchCreationLevelList;
$this->view->gitlabID = $gitlabID;
$this->view->projectID = $projectID;
$this->view->keyword = $keyword;
$this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
$this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1];
$this->view->orderBy = $orderBy;
$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)
{
$tag = base64_decode($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);
die(js::reload('parent'));
}
die(js::alert($reponse->message));
}
/**
* Import gitlab issue to zentaopms.
*
+7
View File
@@ -0,0 +1,7 @@
.text-c-counts > span {margin-left: 5px;}
#mainMenu .pull-left {margin-right: 15px;}
.c-actions-1 {width: 60px;}
#gitlabTagList .text-c-name .has-prefix{position: relative; display: flex; align-items: center;}
#gitlabTagList .text-c-name .label {flex: none;}
#gitlabTagList .text-c-name .tag-name {display: inline-block; max-width: calc(100% - 50px); padding-right: 10px;}
+17
View File
@@ -0,0 +1,17 @@
$(document).ready(function()
{
$('#tagSearch').click(function()
{
triggerSearch();
});
$('#keyword').keypress(function(event)
{
if(event.which == 13) triggerSearch();
})
});
function triggerSearch()
{
$("#tagForm").submit();
}
+5
View File
@@ -55,6 +55,9 @@ $lang->gitlab->editBranchPriv = 'Edit branch protected';
$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
$lang->gitlab->createTag = 'Create Tag';
$lang->gitlab->deleteTag = 'Delete tag';
$lang->gitlab->createTagPriv = 'Add tag protected';
$lang->gitlab->editTagPriv = 'Edit tag protected';
$lang->gitlab->deleteTagPriv = 'Delete tag protected';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "GitLab Name";
@@ -219,3 +222,5 @@ $lang->gitlab->tag->emptyRefError = "Create from cannot be empty.";
$lang->gitlab->tag->issetNameError = "The tag already exists";
$lang->gitlab->tag->confirmDelete = 'Do you want to delete this GitLab tag?';
$lang->gitlab->tag->protected = 'Protected';
$lang->gitlab->tag->accessLevel = 'Allow creation';
$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?';
+5
View File
@@ -55,6 +55,9 @@ $lang->gitlab->editBranchPriv = '编辑分支保护';
$lang->gitlab->deleteBranchPriv = '删除分支保护';
$lang->gitlab->createTag = '创建标签';
$lang->gitlab->deleteTag = '删除标签';
$lang->gitlab->createTagPriv = '添加标签保护';
$lang->gitlab->editTagPriv = '编辑标签保护';
$lang->gitlab->deleteTagPriv = '删除标签保护';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "{$lang->gitlab->common}名称";
@@ -219,3 +222,5 @@ $lang->gitlab->tag->emptyRefError = "创建自不能为空";
$lang->gitlab->tag->issetNameError = "已存在该标签";
$lang->gitlab->tag->confirmDelete = '确认删除该GitLab标签吗?';
$lang->gitlab->tag->protected = '受保护';
$lang->gitlab->tag->accessLevel = '允许创建';
$lang->gitlab->tag->protectConfirmDel = '确认删除该GitLab标签保护吗?';
+51 -2
View File
@@ -1485,8 +1485,16 @@ class gitlabModel extends model
if(!$pager)
{
$url = sprintf($apiRoot, "/projects/{$projectID}/repository/tags");
return json_decode(commonModel::http($url));
$allResults = array();
$url = sprintf($apiRoot, "/projects/{$projectID}/repository/tags");
for($page = 1; true; $page++)
{
$results = json_decode(commonModel::http($url . "&&page={$page}&per_page=100"));
if(!empty($results)) $allResults = array_merge($allResults, $results);
if(count($results)<100) break;
}
return $allResults;
}
else
{
@@ -1521,6 +1529,47 @@ class gitlabModel extends model
return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')));
}
/**
* Get protect tags of one project.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function apiGetTagPrivs($gitlabID, $projectID)
{
$apiRoot = $this->getApiRoot($gitlabID);
$url = sprintf($apiRoot, "/projects/{$projectID}/protected_tags");
$allResults = array();
for($page = 1; true; $page++)
{
$results = json_decode(commonModel::http($url . "&&page={$page}&per_page=100"));
if(!empty($results)) $allResults = array_merge($allResults, $results);
if(count($results)<100) break;
}
return $allResults;
}
/**
* Delete a gitab protect tag by api.
*
* @param int $gitlabID
* @param int $projectID
* @param string $tag
* @access public
* @return object
*/
public function apiDeleteTagPriv($gitlabID, $projectID, $tag)
{
if(empty($gitlabID)) return false;
$apiRoot = $this->getApiRoot($gitlabID);
$url = sprintf($apiRoot, "/projects/{$projectID}/protected_tags/{$tag}");
return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')));
}
/**
* Check webhook token by HTTP_X_GITLAB_TOKEN.
*
+80
View File
@@ -0,0 +1,80 @@
<?php
/**
* The browse view file of gitlab module of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Zeng <zenggang@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('vars', "keyword=%s&orderBy=id_desc&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?>
<?php js::set('gitlabID', $gitlabID)?>
<div id="mainMenu" class="clearfix">
<div class='pull-left'>
<?php echo html::linkButton('<i class="icon icon-back icon-sm"></i> ' . $lang->goback, $this->createLink('gitlab', 'browseProject', "gitlabID=$gitlabID"), 'self', '','btn btn-secondary');?>
</div>
<div id="sidebarHeader">
<div class="title" title="<?php echo $project->name_with_namespace; ?>"><?php echo $project->name_with_namespace; ?></div>
</div>
<div class="btn-toolbar pull-left">
<div>
<form id='tagForm' method='post'>
<?php echo html::input('keyword', $keyword, "class='form-control' placeholder='{$lang->gitlab->tag->placeholderSearch}' style='display: inline-block;width:auto;margin:0 10px'");?>
<a id="tagSearch" class="btn btn-primary"><?php echo $lang->gitlab->search?></a>
</form>
</div>
</div>
<div class="btn-toolbar pull-right">
<?php if(common::hasPriv('gitlab', 'createTag')) common::printLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID", "<i class='icon icon-plus'></i> " . $lang->gitlab->createTagPriv, '', "class='btn btn-primary'");?>
</div>
</div>
<?php if(empty($gitlabTagList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->noData;?></span>
<?php if(empty($keyword) and common::hasPriv('gitlab', 'createTag')):?>
<?php echo html::a($this->createLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), "<i class='icon icon-plus'></i> " . $lang->gitlab->createTagPriv, '', "class='btn btn-info'");?>
<?php endif;?>
</p>
</div>
<?php else:?>
<div id='mainContent' class='main-row'>
<form class='main-table' id='ajaxForm' method='post'>
<table id='gitlabTagList' class='table has-sort-head table-fixed'>
<?php $vars = "gitlabID={$gitlabID}&projectID={$projectID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
<thead>
<tr>
<th class='c-name text-left'><?php common::printOrderLink('name', $orderBy, $vars, $lang->gitlab->tag->name);?></th>
<th class='text-left'><?php echo $lang->gitlab->tag->lastCommitter;?></th>
<th class='text-left'><?php common::printOrderLink('accessLevels', $orderBy, $vars, $lang->gitlab->tag->accessLevel);?></th>
<th class='c-actions-2'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach ($gitlabTagList as $id => $gitlabTag): ?>
<?php $gitlabTag->accessLevel = $this->gitlab->checkAccessLevel($gitlabTag->accessLevels); ?>
<tr class='text'>
<td class='text-c-name' title='<?php echo $gitlabTag->name;?>'><?php echo $gitlabTag->name;?></td>
<td class='text'><?php echo $gitlabTag->lastCommitter;?></td>
<td class='text'><?php echo $levelLang[$gitlabTag->accessLevel];?></td>
<td class='c-actions text-left'>
<?php
common::printLink('gitlab', 'editTagPriv', "gitlabID=$gitlabID&projectID=$projectID&tag_name={$gitlabTag->name}", "<i class='icon icon-edit'></i> ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'");
common::printLink('gitlab', 'deleteTagPriv', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=" . urlencode(base64_encode($gitlabTag->name)), "<i class='icon icon-trash'></i> ", '', "title='{$lang->gitlab->deleteTagPriv}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->gitlab->tag->protectConfirmDel}\")==false) return false;'");
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php if($gitlabTagList):?>
<div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
<?php endif;?>
</form>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
+2
View File
@@ -1341,6 +1341,7 @@ $lang->resource->gitlab->browseTag = 'browseTag';
$lang->resource->gitlab->createTag = 'createTag';
$lang->resource->gitlab->deleteTag = 'deleteTag';
$lang->resource->gitlab->browseTagPriv = 'browseTagPriv';
$lang->resource->gitlab->deleteTagPriv = 'deleteTagPriv';
$lang->gitlab->methodOrder[5] = 'browse';
$lang->gitlab->methodOrder[10] = 'create';
@@ -1369,6 +1370,7 @@ $lang->gitlab->methodOrder[125] = 'createWebhook';
$lang->gitlab->methodOrder[130] = 'manageProjectMembers';
$lang->gitlab->methodOrder[135] = 'browseTag';
$lang->gitlab->methodOrder[140] = 'browseTagPriv';
$lang->gitlab->methodOrder[145] = 'deleteTagPriv';
/* merge request. */
$lang->resource->mr = new stdclass();
+1 -1
View File
@@ -230,7 +230,7 @@
<?php printf('%03d', $task->id);?>
</td>
<td><span class='label-pri label-pri-<?php echo $task->pri;?>' title='<?php echo zget($lang->task->priList, $task->pri, $task->pri);?>'><?php echo zget($lang->task->priList, $task->pri, $task->pri);?></span></td>
<td class='text-left nobr' title='<?php echo $task->name?>'><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), $task->name, '', 'data-app="product"');?></td>
<td class='text-left nobr' title='<?php echo $task->name?>'><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), $task->name);?></td>
<td><?php echo zget($users, $task->finishedBy);?></td>
<td><?php echo zget($users, $task->assignedTo);?></td>
<td>