* Refactor binguser view of gitlab.
This commit is contained in:
@@ -38,7 +38,7 @@ class gitlab extends control
|
||||
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
|
||||
{
|
||||
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
/* Admin user don't need bind. */
|
||||
@@ -138,14 +138,18 @@ class gitlab extends control
|
||||
|
||||
$gitlab = $this->gitlab->getByID($gitlabID);
|
||||
$user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token);
|
||||
if(!isset($user->is_admin) or !$user->is_admin) return print(js::alert($this->lang->gitlab->tokenLimit) . js::locate($this->createLink('gitlab', 'edit', array('gitlabID' => $gitlabID))));
|
||||
if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->tokenLimit, 'locate' => $this->createLink('gitlab', 'edit', array('gitlabID' => $gitlabID))));
|
||||
|
||||
$gitlabNames = array();
|
||||
$gitlabUsers = $this->gitlab->apiGetUsers($gitlabID);
|
||||
foreach($gitlabUsers as $user) $gitlabNames[$user->id] = $user->realname . '@' . $user->account;
|
||||
|
||||
$zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->where('deleted')->eq('0')->fetchAll('account');
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$users = $this->post->zentaoUsers;
|
||||
$gitlabNames = $this->post->gitlabUserNames;
|
||||
$users = array();
|
||||
foreach($_POST as $k => $v) if(substr($k, 0, 6) === 'users-') $users[substr($k, 6)] = $v;
|
||||
$accountList = array();
|
||||
$repeatUsers = array();
|
||||
foreach($users as $openID => $user)
|
||||
@@ -185,10 +189,9 @@ class gitlab extends control
|
||||
$this->loadModel('action')->create('gitlabuser', $openID, 'bind', '', sprintf($this->lang->gitlab->bindDynamic, $gitlabNames[$openID], $zentaoUsers[$account]->realname));
|
||||
}
|
||||
}
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer));
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('gitlab', 'browse')));
|
||||
}
|
||||
|
||||
$gitlabUsers = $this->gitlab->apiGetUsers($gitlabID);
|
||||
$bindedUsers = $this->gitlab->getUserAccountIdPairs($gitlabID);
|
||||
$matchedResult = $this->gitlab->getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers);
|
||||
$matchedResult = array_column(json_decode(json_encode($matchedResult), true), null, "email");
|
||||
@@ -205,6 +208,38 @@ class gitlab extends control
|
||||
return $type == 'binded' ? false : true;
|
||||
});
|
||||
|
||||
$bindedGitlabUsers = $unBindGitlabUsers = array();
|
||||
|
||||
foreach($gitlabUsers as $user)
|
||||
{
|
||||
$user->zentaoEmail = !empty($matchedResult[$user->email]) ? $matchedResult[$user->email]['email'] : '';
|
||||
$user->status = 'notBind';
|
||||
$user->realname = $user->realname . '@' . $user->account;
|
||||
|
||||
$user->zentaoAccount = isset($user->zentaoAccount) ? $user->zentaoAccount : '';
|
||||
$user->zentaoAccount = zget($userPairs, $user->zentaoAccount, '');
|
||||
if(in_array($user->id, $bindedUsers))
|
||||
{
|
||||
$user->status = 'bindedError';
|
||||
if(!empty($user->zentaoAccount)) $user->status = 'binded';
|
||||
}
|
||||
|
||||
if(!empty($user->zentaoAccount))
|
||||
{
|
||||
$bindedGitlabUsers[] = $user;
|
||||
}
|
||||
else
|
||||
{
|
||||
$unBindGitlabUsers[] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$gitlabUsers = array_merge($unBindGitlabUsers, $bindedGitlabUsers);
|
||||
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = new pager(count($gitlabUsers), 10000, 1);
|
||||
|
||||
$this->view->pager = $pager;
|
||||
$this->view->title = $this->lang->gitlab->bindUser;
|
||||
$this->view->zentaoUsers = $zentaoUsers;
|
||||
$this->view->userPairs = $userPairs;
|
||||
@@ -707,7 +742,7 @@ class gitlab extends control
|
||||
if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
|
||||
}
|
||||
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); // Fix bug#16741.
|
||||
|
||||
@@ -868,7 +903,7 @@ class gitlab extends control
|
||||
array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $branchList);
|
||||
|
||||
/* Pager. */
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$this->app->loadClass('pager', true);
|
||||
$recTotal = count($branchList);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
$branchList = array_chunk($branchList, $pager->recPerPage);
|
||||
@@ -942,7 +977,7 @@ class gitlab extends control
|
||||
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
|
||||
|
||||
/* Pager. */
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$tagList = array();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#featureBar {display: flex; gap: 1rem;}
|
||||
.gitlab-account-desc {color: #7d8392;font-size: 12px;}
|
||||
.notBind {color: #fc5959}
|
||||
.bindedError {color: #fc5959}
|
||||
@@ -0,0 +1,5 @@
|
||||
$('table').on('change', '.pick-value', function()
|
||||
{
|
||||
var user = zentaoUsers[$(this).val()];
|
||||
$('#' + $(this).attr('id').replace('users', 'zentaoEmail')).text(user.email);
|
||||
})
|
||||
@@ -235,3 +235,7 @@ $lang->gitlab->tag->accessLevel = 'Allow creation';
|
||||
$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?';
|
||||
$lang->gitlab->tag->emptyPrivNameError = 'Tag cannot be empty.';
|
||||
$lang->gitlab->tag->issetPrivNameError = 'The protection tag already exists.';
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -235,3 +235,7 @@ $lang->gitlab->tag->accessLevel = 'Allow creation';
|
||||
$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?';
|
||||
$lang->gitlab->tag->emptyPrivNameError = 'Tag cannot be empty.';
|
||||
$lang->gitlab->tag->issetPrivNameError = 'The protection tag already exists.';
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -235,3 +235,7 @@ $lang->gitlab->tag->accessLevel = 'Allow creation';
|
||||
$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?';
|
||||
$lang->gitlab->tag->emptyPrivNameError = 'Tag cannot be empty.';
|
||||
$lang->gitlab->tag->issetPrivNameError = 'The protection tag already exists.';
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -236,3 +236,7 @@ $lang->gitlab->tag->accessLevel = 'Allow creation';
|
||||
$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?';
|
||||
$lang->gitlab->tag->emptyPrivNameError = 'Tag cannot be empty.';
|
||||
$lang->gitlab->tag->issetPrivNameError = 'The protection tag already exists.';
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -235,3 +235,7 @@ $lang->gitlab->tag->accessLevel = '允许创建';
|
||||
$lang->gitlab->tag->protectConfirmDel = '确认删除该GitLab标签保护吗?';
|
||||
$lang->gitlab->tag->emptyPrivNameError = "标签不能为空";
|
||||
$lang->gitlab->tag->issetPrivNameError = "已存在该保护标签";
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -224,3 +224,7 @@ $lang->gitlab->tag->protected = '受保護';
|
||||
$lang->gitlab->tag->accessLevel = '允許創建';
|
||||
$lang->gitlab->tag->emptyPrivNameError = '標簽不能爲空';
|
||||
$lang->gitlab->tag->issetPrivNameError = '已存在該保護標簽';
|
||||
|
||||
$lang->gitlab->featureBar['binduser']['all'] = $lang->gitlab->all;
|
||||
$lang->gitlab->featureBar['binduser']['notBind'] = $lang->gitlab->notBind;
|
||||
$lang->gitlab->featureBar['binduser']['binded'] = $lang->gitlab->binded;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The binduser view file of gitlab module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Ke Zhao<zhaoke@easycorp.ltd>
|
||||
* @package gitlab
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
|
||||
namespace zin;
|
||||
|
||||
$userItems = array();
|
||||
foreach($userPairs as $enName => $name)
|
||||
{
|
||||
$userItems[] = array('text' => $name, 'value' => $enName);
|
||||
}
|
||||
jsVar('userItems', $userItems);
|
||||
jsVar('zentaoUsers', $zentaoUsers);
|
||||
jsVar('gitlabUsers', $gitlabUsers);
|
||||
jsVar('accountDesc', $lang->gitlab->accountDesc);
|
||||
|
||||
/* zin: Define the set::module('compile') feature bar on main menu. */
|
||||
featureBar
|
||||
(
|
||||
to::leading(array(backBtn(set::icon('back'), set::class('secondary'), $lang->goback))),
|
||||
set::current($type),
|
||||
set::link($this->createLink('gitlab', 'binduser', "gitlabID=$gitlabID&type={key}")),
|
||||
);
|
||||
|
||||
/* zin: Define the toolbar on main menu. */
|
||||
toolbar();
|
||||
|
||||
|
||||
$tbody = array();
|
||||
foreach($gitlabUsers as $index => $user)
|
||||
{
|
||||
$tbody[] = h::tr
|
||||
(
|
||||
h::td
|
||||
(
|
||||
avatar($user->avatar, set::size(20), setClass('mr-2')),
|
||||
$user->realname
|
||||
),
|
||||
h::td
|
||||
(
|
||||
$user->email
|
||||
),
|
||||
h::td
|
||||
(
|
||||
setID('zentaoEmail-' . $user->id),
|
||||
$user->zentaoEmail
|
||||
),
|
||||
h::td
|
||||
(
|
||||
formGroup
|
||||
(
|
||||
setID('bindUser' . $user->id),
|
||||
set::name("users-" . $user->id),
|
||||
set::value($user->zentaoAccount),
|
||||
set::control("picker"),
|
||||
set::items($userPairs)
|
||||
),
|
||||
),
|
||||
h::td
|
||||
(
|
||||
span
|
||||
(
|
||||
setClass($user->status),
|
||||
$lang->gitlab->{$user->status}
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
formPanel
|
||||
(
|
||||
h::table
|
||||
(
|
||||
setClass('table table-fixed'),
|
||||
h::tr
|
||||
(
|
||||
h::th
|
||||
(
|
||||
$lang->gitlab->gitlabAccount
|
||||
),
|
||||
h::th
|
||||
(
|
||||
$lang->gitlab->gitlabEmail
|
||||
),
|
||||
h::th
|
||||
(
|
||||
$lang->gitlab->zentaoEmail
|
||||
),
|
||||
h::th
|
||||
(
|
||||
set::width('300px'),
|
||||
$lang->gitlab->zentaoAccount,
|
||||
span(setClass('gitlab-account-desc'), $lang->gitlab->accountDesc)
|
||||
),
|
||||
h::th
|
||||
(
|
||||
set::width('100px'),
|
||||
$lang->gitlab->bindingStatus
|
||||
),
|
||||
),
|
||||
$tbody
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user