diff --git a/db/update20.0.sql b/db/update20.0.sql index 52310426ba..966fcb1edb 100644 --- a/db/update20.0.sql +++ b/db/update20.0.sql @@ -142,6 +142,8 @@ CREATE TABLE `zt_artifactrepo` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +ALTER TABLE `zt_repo` ADD `lastCommit` DATETIME NULL DEFAULT NULL AFTER `lastSync`; + ALTER TABLE `zt_build` ADD `artifactRepoID` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `bugs`; CREATE TABLE IF NOT EXISTS `zt_session` ( diff --git a/db/zentao.sql b/db/zentao.sql index b997f1e4b1..95ade2ddd7 100755 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -1482,6 +1482,7 @@ CREATE TABLE IF NOT EXISTS `zt_repo` ( `acl` text NULL, `synced` tinyint(1) NOT NULL DEFAULT '0', `lastSync` datetime NULL, + `lastCommit` datetime NULL, `desc` text NULL, `extra` char(30) NOT NULL DEFAULT '', `preMerge` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '0', diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index 18b65e6d18..9105cc5f4e 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -322,14 +322,9 @@ class Gitea if(strpos($fromRevision, '^') !== false) { $list = execCmd(escapeCmd("$this->client log -2 $toRevision --pretty=format:%H -- $path"), 'array'); - if(isset($list[1])) - { - $fromRevision = $list[1]; - } - else - { - $fromRevision = 'HEAD^'; - } + if(!isset($list[1])) return execCmd(escapeCmd("$this->client show HEAD"), 'array'); + + $fromRevision = $list[1]; } $lines = execCmd(escapeCmd("$this->client diff $fromRevision $toRevision -- $path"), 'array'); return $lines; diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index 69728af6dc..cb5457fa2d 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -575,7 +575,7 @@ class gitlab $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at)); $commits[$commit->id] = $log; - $files[$commit->id] = $this->getFilesByCommit($log->revision); + if($getFile) $files[$commit->id] = $this->getFilesByCommit($log->revision); return array('commits' => $commits, 'files' => $files); } @@ -659,7 +659,7 @@ class gitlab * @access public * @return array */ - public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0, $page = 1, $getUrl = false) + public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0, $page = 1, $getUrl = false, $beginDate = '', $endDate = '') { $path = ltrim($path, DIRECTORY_SEPARATOR); $api = "commits"; @@ -668,17 +668,17 @@ class gitlab $param->path = urldecode($path); $param->ref_name = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch; - $fromDate = $this->getCommittedDate($fromRevision); - $toDate = $this->getCommittedDate($toRevision); + $fromDate = $beginDate ? $beginDate : $this->getCommittedDate($fromRevision); + $toDate = $endDate ? $endDate : $this->getCommittedDate($toRevision); $since = ''; $until = ''; - if($fromRevision and $toRevision) + if(($fromRevision && $toRevision) || ($beginDate && $endDate)) { $since = min($fromDate, $toDate); $until = max($fromDate, $toDate); } - elseif($fromRevision) + elseif($fromRevision || $beginDate) { $since = $fromDate; } @@ -949,4 +949,27 @@ class gitlab } return $lists; } + + /** + * 获取特定对象的api。 + * Get api url for target. + * + * @param string $target + * @access public + * @return string + */ + public function getApiUrl(string $target): string + { + if($target == 'project') + { + return str_replace('repository/', '', $this->root). "?private_token={$this->token}"; + } + $params = array(); + $params['private_token'] = $this->token; + $params['page'] = 1; + $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100; + + $api = $this->root . $target . '?' . http_build_query($params); + return $api; + } } diff --git a/lib/scm/gitrepo.class.php b/lib/scm/gitrepo.class.php index ad805caf62..1fd46f4fbe 100644 --- a/lib/scm/gitrepo.class.php +++ b/lib/scm/gitrepo.class.php @@ -310,7 +310,9 @@ class GitRepo if(strpos($fromRevision, '^') !== false) { $list = execCmd(escapeCmd("$this->client log -2 $toRevision --pretty=format:%H -- $path"), 'array'); - if(isset($list[1])) $fromRevision = $list[1]; + if(!isset($list[1])) return execCmd(escapeCmd("$this->client show HEAD"), 'array'); + + $fromRevision = $list[1]; } $lines = execCmd(escapeCmd("$this->client diff $fromRevision $toRevision -- $path"), 'array'); return $lines; diff --git a/lib/scm/gogs.class.php b/lib/scm/gogs.class.php index 95c9173b21..88fe4ecd3b 100644 --- a/lib/scm/gogs.class.php +++ b/lib/scm/gogs.class.php @@ -322,7 +322,9 @@ class Gogs if(strpos($fromRevision, '^') !== false) { $list = execCmd(escapeCmd("$this->client log -2 $toRevision --pretty=format:%H -- $path"), 'array'); - if(isset($list[1])) $fromRevision = $list[1]; + if(!isset($list[1])) return execCmd(escapeCmd("$this->client show HEAD"), 'array'); + + $fromRevision = $list[1]; } $lines = execCmd(escapeCmd("$this->client diff $fromRevision $toRevision -- $path"), 'array'); return $lines; diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 5f6e3087c6..b8ebfe26fe 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -115,8 +115,8 @@ class Subversion ksort($dirs); $tags = array(); - $trimmed = trim($path, '/'); - $prefix = empty($trimmed) ? '/' : '/' . $trimmed . '/'; + $trimed = trim($path, '/'); + $prefix = empty($trimed) ? '/' : '/' . $trimed . '/'; foreach($dirs as $dirNames) { ksort($dirNames); diff --git a/module/account/config/dtable.php b/module/account/config/dtable.php index 6609838678..696c01de3e 100644 --- a/module/account/config/dtable.php +++ b/module/account/config/dtable.php @@ -50,6 +50,7 @@ $config->account->actionList['edit']['icon'] = 'edit'; $config->account->actionList['edit']['text'] = $lang->edit; $config->account->actionList['edit']['hint'] = $lang->edit; $config->account->actionList['edit']['data-toggle'] = 'modal'; +$config->account->actionList['edit']['data-size'] = 'sm'; $config->account->actionList['edit']['showText'] = true; $config->account->actionList['edit']['url'] = array('module' => 'account', 'method' => 'edit', 'params' => 'id={id}'); diff --git a/module/account/control.php b/module/account/control.php index 37e0dbf6db..5a9f60d56c 100644 --- a/module/account/control.php +++ b/module/account/control.php @@ -67,8 +67,8 @@ class account extends control $this->loadModel('action')->create('account', $id, 'created'); - if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'reload')); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'), 'closeModal' => true)); + if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true)); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'callback' => 'loadCurrentPage()', 'closeModal' => true)); } $this->app->loadLang('serverroom'); diff --git a/module/account/css/common.ui.css b/module/account/css/common.ui.css index 9f7f8d06e7..1f67fbe25b 100644 --- a/module/account/css/common.ui.css +++ b/module/account/css/common.ui.css @@ -1 +1,9 @@ -#accountCreateForm .form-row {max-width: 500px;} \ No newline at end of file +#accountCreateForm .form-row {max-width: 500px;} + +#mainNavbar>.container {padding-top: 8px} +#mainNavbar .nav {justify-content: left; position: relative; left: 0px; top: -4px;} +@media (min-width: 1400px){#mainNavbar .nav {left: -12px;}} +#mainNavbar {background: none;} +#mainNavbar .nav-item>a {padding-right: 0.5rem} +#mainNavbar .nav-item>.active {color: unset; font-weight: 700;} +#mainNavbar .nav-item>a.active:after {position: absolute; content: ''; border-bottom: 2px solid #2e7fff; inset: 0 6px 0 15px;} diff --git a/module/account/model.php b/module/account/model.php index e6d53911e6..78ccf07232 100644 --- a/module/account/model.php +++ b/module/account/model.php @@ -53,7 +53,7 @@ class accountModel extends model /* Concatenate the conditions for the query. */ if($param) { - $query = $this->loadModel('search')->getQuery($param); + $query = $this->loadModel('search')->getZinQuery($param); if($query) { $this->session->set('accountQuery', $query->sql); diff --git a/module/account/ui/browse.html.php b/module/account/ui/browse.html.php index 166365cabf..e9262a5a19 100644 --- a/module/account/ui/browse.html.php +++ b/module/account/ui/browse.html.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace zin; -featureBar(li(searchToggle())); +$queryMenuLink = createLink('account', 'browse', "browseType=bySearch¶m={queryID}"); +featureBar +( + set::queryMenuLinkCallback(fn($key) => str_replace('{queryID}', (string)$key, $queryMenuLink)), + li(searchToggle()) +); /* zin: Define the toolbar on main menu. */ $canCreate = hasPriv('account', 'create'); $createLink = $this->createLink('account', 'create'); -$createItem = array('text' => $lang->account->create, 'url' => $createLink, 'class' => 'primary', 'icon' => 'plus', 'data-toggle' => 'modal'); +$createItem = array('text' => $lang->account->create, 'url' => $createLink, 'class' => 'primary', 'icon' => 'plus', 'data-toggle' => 'modal', 'data-size' => 'sm'); $tableData = initTableData($accountList, $config->account->dtable->fieldList, $this->account); diff --git a/module/artifactrepo/config/dtable.php b/module/artifactrepo/config/dtable.php index 1420c94a94..84bdb126c2 100644 --- a/module/artifactrepo/config/dtable.php +++ b/module/artifactrepo/config/dtable.php @@ -14,6 +14,7 @@ $config->artifactrepo->dtable->fieldList['format']['sortType'] = true; $config->artifactrepo->dtable->fieldList['products']['title'] = $lang->repo->product; $config->artifactrepo->dtable->fieldList['products']['name'] = 'productNames'; $config->artifactrepo->dtable->fieldList['products']['width'] = '300'; +$config->artifactrepo->dtable->fieldList['products']['hint'] = true; $config->artifactrepo->dtable->fieldList['type']['title'] = $lang->artifactrepo->type; $config->artifactrepo->dtable->fieldList['type']['sortType'] = true; @@ -23,6 +24,7 @@ $config->artifactrepo->dtable->fieldList['status']['sortType'] = true; $config->artifactrepo->dtable->fieldList['url']['title'] = $lang->artifactrepo->url; $config->artifactrepo->dtable->fieldList['url']['width'] = '400'; +$config->artifactrepo->dtable->fieldList['url']['hint'] = true; $config->artifactrepo->dtable->fieldList['actions']['type'] = 'actions'; $config->artifactrepo->dtable->fieldList['actions']['menu'] = array('edit', 'delete'); diff --git a/module/artifactrepo/control.php b/module/artifactrepo/control.php index e9ab968832..9f62c2fcab 100644 --- a/module/artifactrepo/control.php +++ b/module/artifactrepo/control.php @@ -23,7 +23,7 @@ class artifactrepo extends control @access public * @return void */ - public function browse($browseType = 'all', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 24, $pageID = 1) + public function browse($browseType = 'all', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 25, $pageID = 1) { /* Load pager. */ $this->app->loadClass('pager', true); @@ -38,7 +38,7 @@ class artifactrepo extends control $this->view->recTotal = $recTotal; $this->view->recPerPage = $recPerPage; $this->view->artifactRepos = $artifactRepos; - $this->view->products = $this->loadModel('product')->getPairs('', 0, '', 'all'); + $this->view->products = $this->loadModel('product')->getPairs('all', 0, '', 'all'); $this->view->pageLink = $this->createLink('artifactrepo', 'browse', "browseType={$browseType}&orderBy={$orderBy}&recTotal={$recTotal}&recPerPage={$recPerPage}&pageID={$pageID}"); $this->display(); @@ -57,6 +57,7 @@ class artifactrepo extends control { $repo = form::data($this->config->artifactrepo->form->create) ->join('products', ',') + ->add('editedBy', $this->app->user->account) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->get(); @@ -104,9 +105,14 @@ class artifactrepo extends control $artifactRepo = $this->artifactrepo->getByID($artifactRepoID); + $products = $this->loadModel('product')->getPairs('', 0, '', 'all'); + $linkedProducts = $this->loadModel('product')->getByIdList(explode(',', $artifactRepo->products)); + $linkedProductPairs = array_combine(array_keys($linkedProducts), helper::arrayColumn($linkedProducts, 'name')); + $products = $products + $linkedProductPairs; + $this->view->title = $this->lang->artifactrepo->edit; $this->view->artifactRepo = $artifactRepo; - $this->view->products = $this->loadModel('product')->getPairs('', 0, '', 'all'); + $this->view->products = $products; $this->display(); } @@ -138,7 +144,9 @@ class artifactrepo extends control { $repos = $this->artifactrepo->getServerRepos($serverID); - return print(json_encode($repos)); + if(!$repos['result']) return $this->send(array('result' => 'fail', 'message' => $this->lang->artifactrepo->loseConnect)); + + return print(json_encode($repos['data'])); } public function ajaxUpdateArtifactRepos() diff --git a/module/artifactrepo/js/create.ui.js b/module/artifactrepo/js/create.ui.js index 8ce9d80e57..aeab6790da 100644 --- a/module/artifactrepo/js/create.ui.js +++ b/module/artifactrepo/js/create.ui.js @@ -11,12 +11,19 @@ function getArtifactRepo(event) { const server = $(event.target).val(); const url = $.createLink('artifactrepo', 'ajaxGetArtifactRepos', 'serverID=' + server); + if(!server) return; toggleLoading('#repoName', true); $.get(url, function(response) { repoData = JSON.parse(response); + if(repoData.result !== undefined && repoData.result === 'fail') + { + zui.Modal.alert(repoData.message); + toggleLoading('#repoName', false); + return; + } var repoItems = []; for(i in repoData) { diff --git a/module/artifactrepo/lang/de.php b/module/artifactrepo/lang/de.php index 50a10e3071..136dc249a0 100644 --- a/module/artifactrepo/lang/de.php +++ b/module/artifactrepo/lang/de.php @@ -1,10 +1,14 @@ artifactrepo = new stdclass(); -$lang->artifactrepo->common = 'Browse artifact repo'; +$lang->artifactrepo->common = 'Artifact repo'; +$lang->artifactrepo->browse = 'Repo List'; $lang->artifactrepo->create = 'Add artifact repo'; $lang->artifactrepo->edit = 'Edit artifact repo'; $lang->artifactrepo->delete = 'Del artifact repo'; +$lang->artifactrepo->ajaxGetArtifactRepos = 'Api: Artifact Repo List'; +$lang->artifactrepo->ajaxUpdateArtifactRepos = 'Api: Update Status'; + $lang->artifactrepo->name = 'Name'; $lang->artifactrepo->serverID = 'Server'; $lang->artifactrepo->repoName = 'Artifact Repo'; @@ -13,4 +17,6 @@ $lang->artifactrepo->type = 'Type'; $lang->artifactrepo->status = 'Status'; $lang->artifactrepo->url = 'Repo Address'; -$lang->artifactrepo->confirmDelete = 'Are you sure you want to delete this aritfact repo?'; +$lang->artifactrepo->confirmDelete = 'Are you sure you want to delete this artifact repo?'; +$lang->artifactrepo->deleteError = 'The artifact repo is already associated with a build. Please cancel the association and try again'; +$lang->artifactrepo->loseConnect = 'Artifact repo server not responding'; diff --git a/module/artifactrepo/lang/en.php b/module/artifactrepo/lang/en.php index 6920b10e49..136dc249a0 100644 --- a/module/artifactrepo/lang/en.php +++ b/module/artifactrepo/lang/en.php @@ -1,10 +1,14 @@ artifactrepo = new stdclass(); -$lang->artifactrepo->common = 'Browse artifact repo'; +$lang->artifactrepo->common = 'Artifact repo'; +$lang->artifactrepo->browse = 'Repo List'; $lang->artifactrepo->create = 'Add artifact repo'; $lang->artifactrepo->edit = 'Edit artifact repo'; $lang->artifactrepo->delete = 'Del artifact repo'; +$lang->artifactrepo->ajaxGetArtifactRepos = 'Api: Artifact Repo List'; +$lang->artifactrepo->ajaxUpdateArtifactRepos = 'Api: Update Status'; + $lang->artifactrepo->name = 'Name'; $lang->artifactrepo->serverID = 'Server'; $lang->artifactrepo->repoName = 'Artifact Repo'; @@ -13,5 +17,6 @@ $lang->artifactrepo->type = 'Type'; $lang->artifactrepo->status = 'Status'; $lang->artifactrepo->url = 'Repo Address'; -$lang->artifactrepo->confirmDelete = 'The artifact repo cannot be restored after deletion. Are you sure you want to continue?'; +$lang->artifactrepo->confirmDelete = 'Are you sure you want to delete this artifact repo?'; $lang->artifactrepo->deleteError = 'The artifact repo is already associated with a build. Please cancel the association and try again'; +$lang->artifactrepo->loseConnect = 'Artifact repo server not responding'; diff --git a/module/artifactrepo/lang/fr.php b/module/artifactrepo/lang/fr.php index 50a10e3071..136dc249a0 100644 --- a/module/artifactrepo/lang/fr.php +++ b/module/artifactrepo/lang/fr.php @@ -1,10 +1,14 @@ artifactrepo = new stdclass(); -$lang->artifactrepo->common = 'Browse artifact repo'; +$lang->artifactrepo->common = 'Artifact repo'; +$lang->artifactrepo->browse = 'Repo List'; $lang->artifactrepo->create = 'Add artifact repo'; $lang->artifactrepo->edit = 'Edit artifact repo'; $lang->artifactrepo->delete = 'Del artifact repo'; +$lang->artifactrepo->ajaxGetArtifactRepos = 'Api: Artifact Repo List'; +$lang->artifactrepo->ajaxUpdateArtifactRepos = 'Api: Update Status'; + $lang->artifactrepo->name = 'Name'; $lang->artifactrepo->serverID = 'Server'; $lang->artifactrepo->repoName = 'Artifact Repo'; @@ -13,4 +17,6 @@ $lang->artifactrepo->type = 'Type'; $lang->artifactrepo->status = 'Status'; $lang->artifactrepo->url = 'Repo Address'; -$lang->artifactrepo->confirmDelete = 'Are you sure you want to delete this aritfact repo?'; +$lang->artifactrepo->confirmDelete = 'Are you sure you want to delete this artifact repo?'; +$lang->artifactrepo->deleteError = 'The artifact repo is already associated with a build. Please cancel the association and try again'; +$lang->artifactrepo->loseConnect = 'Artifact repo server not responding'; diff --git a/module/artifactrepo/lang/zh-cn.php b/module/artifactrepo/lang/zh-cn.php index c3cc7e3e02..f77c289b54 100644 --- a/module/artifactrepo/lang/zh-cn.php +++ b/module/artifactrepo/lang/zh-cn.php @@ -1,10 +1,14 @@ artifactrepo = new stdclass(); -$lang->artifactrepo->common = '浏览制品库'; +$lang->artifactrepo->common = '制品库'; +$lang->artifactrepo->browse = '制品库列表'; $lang->artifactrepo->create = '添加制品库'; $lang->artifactrepo->edit = '编辑制品库'; $lang->artifactrepo->delete = '删除制品库'; +$lang->artifactrepo->ajaxGetArtifactRepos = '接口:制品库列表'; +$lang->artifactrepo->ajaxUpdateArtifactRepos = '接口:更新制品库状态'; + $lang->artifactrepo->name = '名称'; $lang->artifactrepo->serverID = '服务器'; $lang->artifactrepo->repoName = '制品库'; @@ -13,5 +17,6 @@ $lang->artifactrepo->type = '类型'; $lang->artifactrepo->status = '状态'; $lang->artifactrepo->url = '库地址'; -$lang->artifactrepo->confirmDelete = '制品库删除后无法还原,你确认要继续么?'; +$lang->artifactrepo->confirmDelete = '您确认要删除该制品库吗?'; $lang->artifactrepo->deleteError = '当前制品库中制品已关联版本,请取消关联后重试。'; +$lang->artifactrepo->loseConnect = '制品库服务器无法连接'; diff --git a/module/artifactrepo/model.php b/module/artifactrepo/model.php index 79041a5b5e..7b52fa0289 100644 --- a/module/artifactrepo/model.php +++ b/module/artifactrepo/model.php @@ -71,12 +71,12 @@ class artifactrepoModel extends model if($server->type == 'nexus') { - $url = $server->url . '/service/rest/v1/repositorySettings'; + $url = $server->url . '/service/rest/v1/repositorySettings'; $auth = "{$server->account}:{$server->password}"; - $response = common::http($url, '', array(CURLOPT_USERPWD => $auth)); - $data = json_decode($response); - return is_array($data) ? $data : array(); + $response = common::http($url, '', array(CURLOPT_USERPWD => $auth), array(), 'data', 'POST', 10, true); + $data = array('result' => $response[1] == 200, 'data' => json_decode($response['body'])); + return $data; } return array(); diff --git a/module/artifactrepo/ui/browse.html.php b/module/artifactrepo/ui/browse.html.php index 2bf93ea6fe..ab18128229 100644 --- a/module/artifactrepo/ui/browse.html.php +++ b/module/artifactrepo/ui/browse.html.php @@ -26,8 +26,9 @@ foreach($artifactRepos as $repo) foreach($productList as $productID) { if(!isset($products[$productID])) continue; - $repo->productNames .= ' ' . zget($products, $productID, $productID); + $repo->productNames .= ',' . zget($products, $productID, $productID); } + $repo->productNames = trim($repo->productNames, ','); } } $artifactRepos = initTableData($artifactRepos, $config->artifactrepo->dtable->fieldList, $this->artifactrepo); diff --git a/module/artifactrepo/ui/create.html.php b/module/artifactrepo/ui/create.html.php index 017267a9f7..6717f8db41 100644 --- a/module/artifactrepo/ui/create.html.php +++ b/module/artifactrepo/ui/create.html.php @@ -13,6 +13,7 @@ namespace zin; formPanel ( set::title($lang->artifactrepo->create), + set::actionsClass('w-2/3'), formGroup ( set::width('2/3'), @@ -50,6 +51,7 @@ formPanel ( set::width('2/3'), set::name('type'), + set::required(true), set::label($lang->artifactrepo->type), set::readonly(true), input @@ -62,6 +64,7 @@ formPanel ( set::width('2/3'), set::name('status'), + set::required(true), set::label($lang->artifactrepo->status), set::readonly(true), ), diff --git a/module/artifactrepo/ui/edit.html.php b/module/artifactrepo/ui/edit.html.php index 112022bd99..d45cc267bd 100644 --- a/module/artifactrepo/ui/edit.html.php +++ b/module/artifactrepo/ui/edit.html.php @@ -13,6 +13,7 @@ namespace zin; formPanel ( set::title($lang->artifactrepo->edit), + set::actionsClass('w-2/3'), formGroup ( set::width('2/3'), diff --git a/module/cne/lang/de.php b/module/cne/lang/de.php new file mode 100644 index 0000000000..9a769aff7a --- /dev/null +++ b/module/cne/lang/de.php @@ -0,0 +1,28 @@ +CNE->InstallSuccess = 'Install Success'; +$lang->CNE->InstallFailure = 'Install Fail'; +$lang->CNE->serverError = 'CNE Server Error'; + +$lang->CNE->statusList = array(); +$lang->CNE->statusList['normal'] = 'Normal'; +$lang->CNE->statusList['abnormal'] = 'Abnormal'; +$lang->CNE->statusList['stopped'] = 'Stopped'; +$lang->CNE->statusList['unknown'] = 'UnKnown'; + +$lang->CNE->statusIcons = array(); +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; + +$lang->CNE->errorList = array(); +//$lang->CNE->errorList[400] = '不能包含特殊字符'; +$lang->CNE->errorList[400] = 'Request api fail'; +$lang->CNE->errorList[404] = 'Service no exist'; +$lang->CNE->errorList[40004] = 'Certificate does not match the domain'; +$lang->CNE->errorList[41001] = 'Certificate expired'; +$lang->CNE->errorList[41002] = 'Certificate mismatch'; +$lang->CNE->errorList[41003] = 'Incomplete certificate chain'; +$lang->CNE->errorList[41004] = 'Private key does not match the certificate'; +$lang->CNE->errorList[41005] = 'Certificate parsing failed'; +$lang->CNE->errorList[41006] = 'Key parsing failed'; diff --git a/module/cne/lang/en.php b/module/cne/lang/en.php index 6d371ed48f..9a769aff7a 100644 --- a/module/cne/lang/en.php +++ b/module/cne/lang/en.php @@ -1,28 +1,28 @@ CNE->InstallSuccess = 'Installation Succeeded'; -$lang->CNE->InstallFailure = 'Installation Failed'; +$lang->CNE->InstallSuccess = 'Install Success'; +$lang->CNE->InstallFailure = 'Install Fail'; $lang->CNE->serverError = 'CNE Server Error'; $lang->CNE->statusList = array(); $lang->CNE->statusList['normal'] = 'Normal'; -$lang->CNE->statusList['abnormal'] = 'Anomaly'; +$lang->CNE->statusList['abnormal'] = 'Abnormal'; $lang->CNE->statusList['stopped'] = 'Stopped'; -$lang->CNE->statusList['unknown'] = 'Unknown'; +$lang->CNE->statusList['unknown'] = 'UnKnown'; $lang->CNE->statusIcons = array(); -$lang->CNE->statusIcons['normal'] = ""; -$lang->CNE->statusIcons['abnormal'] = ""; -$lang->CNE->statusIcons['stopped'] = ""; -$lang->CNE->statusIcons['unknown'] = ""; +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; $lang->CNE->errorList = array(); -//$lang->CNE->errorList[400] = 'Only number and letter allowed'; -$lang->CNE->errorList[400] = 'Failed to request cluster info'; -$lang->CNE->errorList[404] = 'Service does not exist'; +//$lang->CNE->errorList[400] = '不能包含特殊字符'; +$lang->CNE->errorList[400] = 'Request api fail'; +$lang->CNE->errorList[404] = 'Service no exist'; $lang->CNE->errorList[40004] = 'Certificate does not match the domain'; -$lang->CNE->errorList[41001] = 'Certificate has expired'; +$lang->CNE->errorList[41001] = 'Certificate expired'; $lang->CNE->errorList[41002] = 'Certificate mismatch'; $lang->CNE->errorList[41003] = 'Incomplete certificate chain'; -$lang->CNE->errorList[41004] = 'Certificate and private key do not match'; -$lang->CNE->errorList[41005] = 'Failed parsing certificate'; -$lang->CNE->errorList[41006] = 'Failed parsing key'; +$lang->CNE->errorList[41004] = 'Private key does not match the certificate'; +$lang->CNE->errorList[41005] = 'Certificate parsing failed'; +$lang->CNE->errorList[41006] = 'Key parsing failed'; diff --git a/module/cne/lang/fr.php b/module/cne/lang/fr.php new file mode 100644 index 0000000000..9a769aff7a --- /dev/null +++ b/module/cne/lang/fr.php @@ -0,0 +1,28 @@ +CNE->InstallSuccess = 'Install Success'; +$lang->CNE->InstallFailure = 'Install Fail'; +$lang->CNE->serverError = 'CNE Server Error'; + +$lang->CNE->statusList = array(); +$lang->CNE->statusList['normal'] = 'Normal'; +$lang->CNE->statusList['abnormal'] = 'Abnormal'; +$lang->CNE->statusList['stopped'] = 'Stopped'; +$lang->CNE->statusList['unknown'] = 'UnKnown'; + +$lang->CNE->statusIcons = array(); +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; + +$lang->CNE->errorList = array(); +//$lang->CNE->errorList[400] = '不能包含特殊字符'; +$lang->CNE->errorList[400] = 'Request api fail'; +$lang->CNE->errorList[404] = 'Service no exist'; +$lang->CNE->errorList[40004] = 'Certificate does not match the domain'; +$lang->CNE->errorList[41001] = 'Certificate expired'; +$lang->CNE->errorList[41002] = 'Certificate mismatch'; +$lang->CNE->errorList[41003] = 'Incomplete certificate chain'; +$lang->CNE->errorList[41004] = 'Private key does not match the certificate'; +$lang->CNE->errorList[41005] = 'Certificate parsing failed'; +$lang->CNE->errorList[41006] = 'Key parsing failed'; diff --git a/module/cne/lang/vi.php b/module/cne/lang/vi.php new file mode 100644 index 0000000000..9a769aff7a --- /dev/null +++ b/module/cne/lang/vi.php @@ -0,0 +1,28 @@ +CNE->InstallSuccess = 'Install Success'; +$lang->CNE->InstallFailure = 'Install Fail'; +$lang->CNE->serverError = 'CNE Server Error'; + +$lang->CNE->statusList = array(); +$lang->CNE->statusList['normal'] = 'Normal'; +$lang->CNE->statusList['abnormal'] = 'Abnormal'; +$lang->CNE->statusList['stopped'] = 'Stopped'; +$lang->CNE->statusList['unknown'] = 'UnKnown'; + +$lang->CNE->statusIcons = array(); +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; + +$lang->CNE->errorList = array(); +//$lang->CNE->errorList[400] = '不能包含特殊字符'; +$lang->CNE->errorList[400] = 'Request api fail'; +$lang->CNE->errorList[404] = 'Service no exist'; +$lang->CNE->errorList[40004] = 'Certificate does not match the domain'; +$lang->CNE->errorList[41001] = 'Certificate expired'; +$lang->CNE->errorList[41002] = 'Certificate mismatch'; +$lang->CNE->errorList[41003] = 'Incomplete certificate chain'; +$lang->CNE->errorList[41004] = 'Private key does not match the certificate'; +$lang->CNE->errorList[41005] = 'Certificate parsing failed'; +$lang->CNE->errorList[41006] = 'Key parsing failed'; diff --git a/module/cne/lang/zh-cn.php b/module/cne/lang/zh-cn.php index 57539e5198..a034968fd7 100644 --- a/module/cne/lang/zh-cn.php +++ b/module/cne/lang/zh-cn.php @@ -10,10 +10,10 @@ $lang->CNE->statusList['stopped'] = '关闭'; $lang->CNE->statusList['unknown'] = '无数据'; $lang->CNE->statusIcons = array(); -$lang->CNE->statusIcons['normal'] = ""; -$lang->CNE->statusIcons['abnormal'] = ""; -$lang->CNE->statusIcons['stopped'] = ""; -$lang->CNE->statusIcons['unknown'] = ""; +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; $lang->CNE->errorList = array(); //$lang->CNE->errorList[400] = '不能包含特殊字符'; diff --git a/module/cne/lang/zh-tw.php b/module/cne/lang/zh-tw.php new file mode 100644 index 0000000000..a034968fd7 --- /dev/null +++ b/module/cne/lang/zh-tw.php @@ -0,0 +1,28 @@ +CNE->InstallSuccess = '安装成功'; +$lang->CNE->InstallFailure = '安装失败'; +$lang->CNE->serverError = 'CNE服务器出错'; + +$lang->CNE->statusList = array(); +$lang->CNE->statusList['normal'] = '正常'; +$lang->CNE->statusList['abnormal'] = '异常'; +$lang->CNE->statusList['stopped'] = '关闭'; +$lang->CNE->statusList['unknown'] = '无数据'; + +$lang->CNE->statusIcons = array(); +$lang->CNE->statusIcons['normal'] = "check"; +$lang->CNE->statusIcons['abnormal'] = "exclamation-pure"; +$lang->CNE->statusIcons['stopped'] = "pause-pure"; +$lang->CNE->statusIcons['unknown'] = "exclamation-pure"; + +$lang->CNE->errorList = array(); +//$lang->CNE->errorList[400] = '不能包含特殊字符'; +$lang->CNE->errorList[400] = '请求集群接口失败'; +$lang->CNE->errorList[404] = '服务不存在'; +$lang->CNE->errorList[40004] = '证书与域名不匹配'; +$lang->CNE->errorList[41001] = '证书过期'; +$lang->CNE->errorList[41002] = '证书不匹配'; +$lang->CNE->errorList[41003] = '证书链不完整'; +$lang->CNE->errorList[41004] = '私钥与证书不匹配'; +$lang->CNE->errorList[41005] = '证书解析失败'; +$lang->CNE->errorList[41006] = '密钥解析失败'; diff --git a/module/cne/model.php b/module/cne/model.php index cef2287884..d5ac00d3c7 100644 --- a/module/cne/model.php +++ b/module/cne/model.php @@ -50,7 +50,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $instanceList = $result->data; - return array_combine(array_column($instanceList, 'name'), $instanceList); + return array_combine(helper::arrayColumn($instanceList, 'name'), $instanceList); } /** @@ -335,7 +335,7 @@ class cneModel extends model $customDomain = $this->loadModel('setting')->getItem('owner=system&module=common§ion=domain&key=customDomain'); if($customDomain) return $customDomain; - return getenv('APP_DOMAIN') ? getenv('APP_DOMAIN') : $this->config->CNE->app->domain; + return getenv('APP_DOMAIN'); } /** @@ -449,7 +449,7 @@ class cneModel extends model $apiUrl = "/api/cne/statistics/app"; $result = $this->apiPost($apiUrl, $apiData, $this->config->CNE->api->headers); - if(!isset($result->code) || $result->code != 200)return array_combine(array_column($instancesMetrics, 'id'), $instancesMetrics); + if(!isset($result->code) || $result->code != 200)return array_combine(helper::arrayColumn($instancesMetrics, 'id'), $instancesMetrics); foreach($result->data as $k8sMetric) { @@ -468,7 +468,7 @@ class cneModel extends model $instancesMetrics[$k8sMetric->name]->memory->rate = $instancesMetrics[$k8sMetric->name]->memory->limit > 0 ? round($instancesMetrics[$k8sMetric->name]->memory->usage / $instancesMetrics[$k8sMetric->name]->memory->limit * 100, 2) : 0; } - return array_combine(array_column($instancesMetrics, 'id'), $instancesMetrics); + return array_combine(helper::arrayColumn($instancesMetrics, 'id'), $instancesMetrics); } /** @@ -839,22 +839,27 @@ class cneModel extends model { if(empty($mappings)) $mappings = array( array( - "key" => "admin_username", + "key" => "admin_username", "type" => "helm", "path" => "auth.username" ), array( - "key" => "admin_password", - "type" => "helm", - "path" => "auth.password" + "key" => "z_username", + "path" => "z_username", + "type" => "secret" ), array( - "key" => "admin_token", - "type" => "secret", - "path" => "api_token" + "key" => "z_password", + "path" => "z_password", + "type" => "secret" ), + array( + "key" => "api_token", + "path" => "api_token", + "type" => "secret" + ) ); - + $apiParams = new stdclass; $apiParams->cluster = ''; $apiParams->namespace = $instance->spaceData->k8space; @@ -993,7 +998,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** @@ -1057,7 +1062,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** @@ -1077,7 +1082,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** @@ -1144,8 +1149,12 @@ class cneModel extends model public function apiPost($url, $data, $header = array(), $host = '') { $requestUri = ($host ? $host : $this->config->CNE->api->host) . $url; - $result = json_decode(commonModel::http($requestUri, $data, array(CURLOPT_CUSTOMREQUEST => 'POST'), $header, 'json', 20)); - if($result && $result->code == 200) return $result; + $result = json_decode(commonModel::http($requestUri, $data, array(CURLOPT_CUSTOMREQUEST => 'POST'), $header, 'json', 'POST', 20)); + if($result && in_array($result->code, array(200, 201))) + { + $result->code = 200; + return $result; + } if($result) return $this->translateError($result); return $this->cneServerError(); @@ -1313,4 +1322,21 @@ class cneModel extends model $apiUrl = "/api/cne/platform/restore/status"; return $this->apiGet($apiUrl, $apiParams, $this->config->CNE->api->headers); } + + /** + * app资源调度尝试。 + * Try allocate for apps. + * + * @param array $apps + * @access public + * @return object + */ + public function tryAllocate(array $resources): object + { + $apiParams = new stdclass(); + $apiParams->requests = $resources; + + $apiUrl = "/api/cne/system/resource/try-allocate"; + return $this->apiPost($apiUrl, $apiParams, $this->config->CNE->api->headers); + } } diff --git a/module/git/model.php b/module/git/model.php index 2cea1db380..7df4b2771c 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -69,6 +69,8 @@ class gitModel extends model /* Get repos and load module. */ $this->setRepos(); $this->loadModel('job'); + $this->loadModel('gitlab'); + $this->loadModel('repo'); if(empty($this->repos)) return false; @@ -82,7 +84,11 @@ class gitModel extends model { $this->updateCommit($repo, $commentGroup, true); - if($repo->SCM == 'Gitlab') $this->loadModel('gitlab')->updateCodePath((int)$repo->serviceHost, (int)$repo->serviceProject, (int)$repo->id); + if($repo->SCM == 'Gitlab') + { + $this->gitlab->updateCodePath((int)$repo->serviceHost, (int)$repo->serviceProject, (int)$repo->id); + $this->repo->updateCommitDate((int)$repo->id); + } /* Create compile by tag. */ $jobs = zget($tagGroup, $repoID, array()); @@ -120,6 +126,8 @@ class gitModel extends model */ public function updateCommit($repo, $commentGroup, $printLog = true) { + if($repo->SCM == 'Gitlab') return; + /* Load module and print log. */ $this->loadModel('repo'); if($printLog) $this->printLog("begin repo $repo->id"); @@ -202,7 +210,7 @@ class gitModel extends model if(empty($objectIDs) or !isset($objectTypeMap[$objectType])) continue; $this->post->$objectType = $objectIDs; - $this->repo->link($repo->id, $log->revision, $objectTypeMap[$objectType]); + $this->repo->link($repo->id, $log->revision, $objectTypeMap[$objectType], 'commit'); } } } diff --git a/module/gitea/control.php b/module/gitea/control.php index dbd6c5ddac..d95e35ab6d 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -20,6 +20,8 @@ class gitea extends control { parent::__construct($moduleName, $methodName); + if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false); + /* This is essential when changing tab(menu) from gitea to repo. */ /* Optional: common::setMenuVars('devops', $this->session->repoID); */ if($this->app->rawMethod != 'binduser') $this->loadModel('ci')->setMenu(); @@ -163,8 +165,9 @@ class gitea extends control $changes = common::createChanges($oldGitea, $gitea); $this->loadModel('action')->logHistory($actionID, $changes); - $response['load'] = true; - $response['result'] = 'success'; + $response['load'] = $this->createLink('space', 'browse'); + $response['message'] = zget($this->lang->instance->notices, 'uninstallSuccess'); + $response['result'] = 'success'; return $this->send($response); } @@ -196,7 +199,7 @@ class gitea extends control * @access public * @return void */ - public function bindUser(int $giteaID, string $type = 'all') + public function bindUser($giteaID, $type = 'all') { $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); @@ -204,12 +207,12 @@ class gitea extends control if($_POST) { $this->gitea->bindUser($giteaID); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); + if(dao::isError()) return $this->sendError(dao::getError()); + return $this->sendSuccess(array('message' => $this->lang->saveSuccess, 'load' => helper::createLink('space', 'browse'))); } $userList = array(); - $giteaUsers = $this->gitea->apiGetUsers($giteaID); + $giteaUsers = $this->gitea->apiGetUsers($giteaID); $bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID); $matchedResult = $this->gitea->getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers); @@ -245,6 +248,7 @@ class gitea extends control $this->view->recTotal = count($userList); $this->view->userList = $userList; $this->view->userPairs = $userPairs; + $this->view->zentaoUsers = $zentaoUsers; $this->display(); } @@ -263,11 +267,13 @@ class gitea extends control $project = urldecode(base64_decode($project)); $branches = $this->gitea->apiGetBranches($giteaID, $project); - $options = ""; + + $options = array(); + $options[] = array('text' => '', 'value' => '');; foreach($branches as $branch) { - $options .= ""; + $options[] = array('text' => $branch->name, 'value' => $branch->name); } - $this->send($options); + return print(json_encode($options)); } } diff --git a/module/gitea/js/binduser.js b/module/gitea/js/binduser.js new file mode 100644 index 0000000000..014d06eeb1 --- /dev/null +++ b/module/gitea/js/binduser.js @@ -0,0 +1,24 @@ +$(document).ready(function() +{ + $('.gitlab-user-bind').change(function() + { + var user = zentaoUsers[$(this).val()]; + if(user !== undefined) + { + $(this).parent().parent().find('.email').text(user.email) + } + }); + + $(document).on('click', '.zentao-users .chosen-container', function() + { + var $obj = $(this).prev('select'); + var value = $obj.val(); + if($obj.hasClass('filled')) return false; + + $obj.empty(); + $obj.append($('#userList').html()); + $obj.val(value); + $obj.addClass('filled'); + $obj.trigger("chosen:updated"); + }) +}); diff --git a/module/gitea/js/binduser.ui.js b/module/gitea/js/binduser.ui.js index d1537ecfb7..4bfcde782f 100644 --- a/module/gitea/js/binduser.ui.js +++ b/module/gitea/js/binduser.ui.js @@ -10,7 +10,27 @@ window.setUserEmail = function() window.renderGitlabUser = function(result, {row}) { const giteaID = row.data.giteaID; - result.push({html: ``}); + result.push({html: ''}); return result; } + +window.bindUser = function() +{ + const myDTable = $('#table-gitea-binduser').zui('dtable'); + const formData = myDTable.$.getFormData(); + + var bindData = $('#table-gitea-binduser').zui('dtable').$.props.data; + var postData = {}; + postData['giteaUserNames[]'] = []; + for(i in bindData) + { + postData['giteaUserNames[]'].push(bindData[i].giteaID); + postData['zentaoUsers[' + bindData[i].giteaID + ']'] = formData['zentaoUsers[' + bindData[i].giteaID + ']']; + } + + $.ajaxSubmit({ + url: $.createLink('gitea', 'bindUser', 'giteaID=' + giteaID + '&type=' + type), + data: postData + }); +} diff --git a/module/gitea/lang/de.php b/module/gitea/lang/de.php index e73cc56f5a..e7484dabc0 100644 --- a/module/gitea/lang/de.php +++ b/module/gitea/lang/de.php @@ -13,6 +13,7 @@ $lang->gitea->giteaAccount = 'Gitea Account'; $lang->gitea->giteaEmail = 'Email'; $lang->gitea->zentaoAccount = 'Zentao Account'; $lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->all = 'All'; $lang->gitea->notBind = 'Not bind'; $lang->gitea->binded = 'Binded'; $lang->gitea->bindDynamic = '%s and Zentao user %s'; diff --git a/module/gitea/lang/en.php b/module/gitea/lang/en.php index 667b7c82b5..046590c667 100644 --- a/module/gitea/lang/en.php +++ b/module/gitea/lang/en.php @@ -13,6 +13,7 @@ $lang->gitea->giteaAccount = 'Gitea Account'; $lang->gitea->giteaEmail = 'Email'; $lang->gitea->zentaoAccount = 'Zentao Account'; $lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->all = 'All'; $lang->gitea->notBind = 'Not bind'; $lang->gitea->binded = 'Binded'; $lang->gitea->bindDynamic = '%s and Zentao user %s'; diff --git a/module/gitea/lang/fr.php b/module/gitea/lang/fr.php index e73cc56f5a..e7484dabc0 100644 --- a/module/gitea/lang/fr.php +++ b/module/gitea/lang/fr.php @@ -13,6 +13,7 @@ $lang->gitea->giteaAccount = 'Gitea Account'; $lang->gitea->giteaEmail = 'Email'; $lang->gitea->zentaoAccount = 'Zentao Account'; $lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->all = 'All'; $lang->gitea->notBind = 'Not bind'; $lang->gitea->binded = 'Binded'; $lang->gitea->bindDynamic = '%s and Zentao user %s'; diff --git a/module/gitea/lang/zh-cn.php b/module/gitea/lang/zh-cn.php index f160a3e110..144da40f6c 100644 --- a/module/gitea/lang/zh-cn.php +++ b/module/gitea/lang/zh-cn.php @@ -13,6 +13,7 @@ $lang->gitea->giteaAccount = 'Gitea用户'; $lang->gitea->giteaEmail = '邮箱'; $lang->gitea->zentaoAccount = '禅道用户'; $lang->gitea->bindingStatus = '绑定状态'; +$lang->gitea->all = '全部'; $lang->gitea->notBind = '未绑定'; $lang->gitea->binded = '已绑定'; $lang->gitea->bindDynamic = '%s与禅道用户%s'; diff --git a/module/gitea/model.php b/module/gitea/model.php index b2603eedd3..b9a4d8605a 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -98,9 +98,9 @@ class giteaModel extends model * * @param int $giteaID * @access public - * @return bool + * @return array */ - public function bindUser(int $giteaID): bool + public function bindUser($giteaID) { $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); $users = $this->post->zentaoUsers; @@ -116,7 +116,7 @@ class giteaModel extends model if(count($repeatUsers)) { - dao::$errors[] = sprintf($this->lang->gitea->bindUserError, join(',', $repeatUsers)); + dao::$errors = sprintf($this->lang->gitea->bindUserError, join(',', $repeatUsers)); return false; } @@ -148,8 +148,6 @@ class giteaModel extends model $this->loadModel('action')->create('giteauser', $giteaID, 'bind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$account]->realname)); } } - - return true; } /** @@ -308,13 +306,13 @@ class giteaModel extends model /** * Get matched gitea users. * - * @param int $giteaID - * @param array $giteaUsers - * @param array $zentaoUsers + * @param int $giteaID + * @param array $giteaUsers + * @param array $zentaoUsers * @access public * @return array */ - public function getMatchedUsers(int $giteaID, array $giteaUsers, array $zentaoUsers): array + public function getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers) { $matches = new stdclass; foreach($giteaUsers as $giteaUser) @@ -331,9 +329,9 @@ class giteaModel extends model $matchedUsers = array(); foreach($giteaUsers as $giteaUser) { - if(isset($bindedUsers[$giteaUser->account])) + if(isset($bindedUsers[$giteaUser->id])) { - $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->account]; + $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->id]; $matchedUsers[$giteaUser->id] = $giteaUser; continue; } @@ -379,6 +377,7 @@ class giteaModel extends model $gitea = $this->getByID($giteaID); $oauth = "oauth2:{$gitea->token}@"; $project->tokenCloneUrl = preg_replace('/(http(s)?:\/\/)/', "\$1$oauth", $project->html_url); + $project->tokenCloneUrl = str_replace(array('https://', 'http://'), strstr($url, ':', true) . '://', $project->tokenCloneUrl); } return $project; diff --git a/module/gitea/ui/binduser.html.php b/module/gitea/ui/binduser.html.php index 39505c6713..9832051775 100644 --- a/module/gitea/ui/binduser.html.php +++ b/module/gitea/ui/binduser.html.php @@ -24,6 +24,8 @@ featureBar toolbar(); jsVar('zentaoUsers', $zentaoUsers); +jsVar('giteaID', $giteaID); +jsVar('type', $type); $config->gitea->dtable->bindUser->fieldList['giteaEmail']['onRenderCell'] = jsRaw('renderGitlabUser'); $config->gitea->dtable->bindUser->fieldList['zentaoUsers']['controlItems'] = $userPairs; form @@ -48,7 +50,7 @@ form array( 'text' => $lang->save, 'btnType' => 'primary', - 'onClick' => jsRaw("() => {\$('#bindForm').trigger('submit')}") + 'onClick' => jsRaw("() => {bindUser()}") ), array( 'text' => $lang->goback, diff --git a/module/gitea/view/binduser.html.php b/module/gitea/view/binduser.html.php index faddecc316..ec2af2764f 100644 --- a/module/gitea/view/binduser.html.php +++ b/module/gitea/view/binduser.html.php @@ -11,60 +11,66 @@ */ ?> +createLink('gitea', 'browse', ""); ?> +