From 70d00fad9e18088fce1004f0ff7fd8ab4708a881 Mon Sep 17 00:00:00 2001 From: zenggang Date: Thu, 17 Mar 2022 03:07:38 +0000 Subject: [PATCH] * Code for task#50697,50685 --- db/update16.4.sql | 2 ++ db/zentao.sql | 1 + module/action/lang/en.php | 4 +-- module/action/lang/zh-cn.php | 4 +-- module/gitlab/control.php | 40 ++++++++++++++++------------ module/gitlab/lang/en.php | 1 + module/gitlab/lang/zh-cn.php | 1 + module/gitlab/view/binduser.html.php | 2 ++ module/mr/lang/en.php | 1 + module/mr/lang/zh-cn.php | 1 + module/mr/model.php | 4 +++ module/mr/view/create.html.php | 9 +++++++ module/mr/view/edit.html.php | 10 +++++++ 13 files changed, 59 insertions(+), 21 deletions(-) diff --git a/db/update16.4.sql b/db/update16.4.sql index 4b3b9b21ac..c7844d7d03 100644 --- a/db/update16.4.sql +++ b/db/update16.4.sql @@ -55,3 +55,5 @@ ALTER TABLE `zt_kanbancard` CHANGE `order` `order` mediumint NOT NULL DEFAULT '0 ALTER TABLE `zt_kanbanregion` CHANGE `order` `order` mediumint NOT NULL DEFAULT '0' AFTER `name`; ALTER TABLE `zt_kanbanspace` CHANGE `order` `order` mediumint NOT NULL DEFAULT '0' AFTER `status`; ALTER TABLE `zt_projectstory` CHANGE `branch` `branch` mediumint unsigned NOT NULL AFTER `product`; + +ALTER TABLE `zt_mr` ADD `squash` ENUM('0','1') NOT NULL DEFAULT '0' AFTER `removeSourceBranch`; diff --git a/db/zentao.sql b/db/zentao.sql index c437399460..e0423edba5 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -875,6 +875,7 @@ CREATE TABLE IF NOT EXISTS `zt_mr` ( `compileID` mediumint(8) unsigned NOT NULL, `compileStatus` char(30) NOT NULL, `removeSourceBranch` enum('0','1') NOT NULL DEFAULT '0', + `squash` enum('0','1') NOT NULL DEFAULT '0', `synced` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '1', `syncError` varchar(255) NOT NULL, `hasNoConflict` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '0', diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 1e9678ea2a..589c12de13 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -344,7 +344,8 @@ $lang->action->label->importedrelease = 'imported'; $lang->action->label->importedexecution = 'imported'; $lang->action->label->importedbuild = 'imported'; $lang->action->label->fromsonarqube = 'created a bug from SonarQube Issue named:'; -$lang->action->label->binduser = 'bind user'; +$lang->action->label->bind = 'bound'; +$lang->action->label->unbind = 'unbound'; /* Dynamic information is grouped by object. */ $lang->action->dynamicAction = new stdclass; @@ -824,4 +825,3 @@ $lang->action->desc->deletemr = '$date, $actoraction->desc->mergedmr = '$date, $actor merged code.'; $lang->action->desc->approve = '$date, $actor approved.'; $lang->action->desc->reject = '$date, $actor rejected.'; -$lang->action->desc->binduser = '$date, $actor modified bound user.'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 5d76e75bd2..0a9ffaa025 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -344,7 +344,8 @@ $lang->action->label->importedrelease = '导入了'; $lang->action->label->importedexecution = '导入了'; $lang->action->label->importedbuild = '导入了'; $lang->action->label->fromsonarqube = '由SonarQube问题创建'; -$lang->action->label->binduser = '绑定用户了'; +$lang->action->label->bind = '绑定了'; +$lang->action->label->unbind = '取消绑定了'; /* 动态信息按照对象分组 */ $lang->action->dynamicAction = new stdclass(); @@ -824,4 +825,3 @@ $lang->action->desc->deletemr = '$date, 由 $actoraction->desc->mergedmr = '$date, 由 $actor 合并了 代码。'; $lang->action->desc->approve = '$date, 由 $actor 审核通过。'; $lang->action->desc->reject = '$date, 由 $actor 拒绝。'; -$lang->action->desc->binduser = '$date, 由 $actor 修改了绑定用户。'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 724aab2b40..25130cfde3 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -149,9 +149,12 @@ class gitlab extends control $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)))); + $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); + if($_POST) { $users = $this->post->zentaoUsers; + $gitlabNames = $this->post->gitlabUserNames; $accountList = array(); $repeatUsers = array(); foreach($users as $openID => $user) @@ -167,30 +170,33 @@ class gitlab extends control $user->providerID = $gitlabID; $user->providerType = 'gitlab'; - /* Delete binded users and save new relationship. */ - $this->dao->delete()->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->exec(); + $oldUsers = $this->dao->select('*')->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->fetchAll('openID'); foreach($users as $openID => $account) { - if(!$account) continue; - $user->account = $account; - $user->openID = $openID; + $existAccount = isset($oldUsers[$openID]) ? $oldUsers[$openID] : ''; - $this->dao->delete() - ->from(TABLE_OAUTH) - ->where('openID')->eq($user->openID) - ->andWhere('providerType')->eq($user->providerType) - ->andWhere('providerID')->eq($user->providerID) - ->andWhere('account')->eq($user->account) - ->exec(); - - $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); + if($existAccount and $existAccount->account != $account) + { + $this->dao->delete() + ->from(TABLE_OAUTH) + ->where('openID')->eq($openID) + ->andWhere('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) + ->exec(); + $this->loadModel('action')->create('gitlabuser', $openID, 'unbind', '', sprintf($this->lang->gitlab->bindDynamic, $gitlabNames[$openID], $zentaoUsers[$existAccount->account]->realname)); + } + if(!$existAccount or $existAccount->account != $account) + { + if(!$account) continue; + $user->account = $account; + $user->openID = $openID; + $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); + $this->loadModel('action')->create('gitlabuser', $openID, 'bind', '', sprintf($this->lang->gitlab->bindDynamic, $gitlabNames[$openID], $zentaoUsers[$account]->realname)); + } } - $this->loadModel('action')->create('gitlab', $gitlabID, 'binduser'); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } - $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); - $this->view->title = $this->lang->gitlab->bindUser; $this->view->userPairs = $userPairs; $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlabID); diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 46b5576163..feaa6bb53b 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -18,6 +18,7 @@ $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->bindDynamic = '%s and Zentao user %s'; $lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.'; $lang->gitlab->lastUpdate = 'Last Update'; $lang->gitlab->confirmAddWebhook = 'Are you sure about creating Webhook?'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 6abf146af2..5f6d6120ce 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -18,6 +18,7 @@ $lang->gitlab->bindingStatus = '绑定状态'; $lang->gitlab->notBind = '未绑定'; $lang->gitlab->binded = '已绑定'; $lang->gitlab->bindedError = '绑定的用户已删除或者已修改,请重新绑定'; +$lang->gitlab->bindDynamic = '%s与禅道用户%s'; $lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。'; $lang->gitlab->lastUpdate = '最后更新'; $lang->gitlab->confirmAddWebhook = '您确定创建Webhook吗?'; diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index c8257a275c..2508ffa7c7 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -28,6 +28,7 @@ zentaoAccount)) continue;?> + id]", $gitlabUser->realname);?> avatar, "height=40");?> @@ -42,6 +43,7 @@ zentaoAccount)) continue;?> + id]", $gitlabUser->realname);?> avatar, "height=40");?> diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php index 4cc6056929..2b9f8e9ebc 100644 --- a/module/mr/lang/en.php +++ b/module/mr/lang/en.php @@ -60,6 +60,7 @@ $lang->mr->approvalResultList['reject'] = 'Reject'; $lang->mr->needApproved = 'This MR should be approved before merge'; $lang->mr->needCI = 'Merge only after passing CI'; $lang->mr->removeSourceBranch = 'Delete source branch after merge'; +$lang->mr->squash = 'Squash commits'; $lang->mr->repeatedOperation = 'Do not repeat operations'; diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 7ce0b5a9f1..4f9558935b 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -60,6 +60,7 @@ $lang->mr->approvalResultList['reject'] = '拒绝'; $lang->mr->needApproved = '需要通过评审才能合并'; $lang->mr->needCI = '需要通过构建才能合并'; $lang->mr->removeSourceBranch = '合并后删除源分支'; +$lang->mr->squash = '合并提交'; $lang->mr->repeatedOperation = '请勿重复操作'; diff --git a/module/mr/model.php b/module/mr/model.php index 0257ab0adc..07d84f3532 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -162,6 +162,7 @@ class mrModel extends model ->setDefault('repoID', 0) ->setDefault('removeSourceBranch','0') ->setDefault('needCI', 0) + ->setDefault('squash', 0) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->get(); @@ -197,6 +198,7 @@ class mrModel extends model $MRObject->title = $MR->title; $MRObject->description = $MR->description; $MRObject->remove_source_branch = $MR->removeSourceBranch == '1' ? true : false; + $MRObject->squash = $MR->squash == '1' ? 1 : 0; if($MR->assignee) { $gitlabAssignee = $this->gitlab->getUserIDByZentaoAccount($this->post->gitlabID, $MR->assignee); @@ -340,6 +342,7 @@ class mrModel extends model ->setDefault('repoID', 0) ->setDefault('removeSourceBranch','0') ->setDefault('needCI', 0) + ->setDefault('squash', 0) ->setDefault('editedBy', $this->app->user->account) ->setDefault('editedDate', helper::now()) ->setIF($this->post->needCI == 0, 'jobID', 0) @@ -368,6 +371,7 @@ class mrModel extends model $newMR->description = $MR->description; $newMR->target_branch = $MR->targetBranch; $newMR->remove_source_branch = $MR->removeSourceBranch == '1' ? true : false; + $newMR->squash = $MR->squash == '1' ? 1 : 0; if($MR->assignee) { $gitlabAssignee = $this->gitlab->getUserIDByZentaoAccount($oldMR->gitlabID, $MR->assignee); diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 624501db02..91b26e8ef4 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -76,6 +76,15 @@ job->common;?> + + mr->squash;?> + +
+ + +
+ + mr->assignee;?> diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index 84999c8b16..94ed0d2620 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -100,6 +100,16 @@ job->common;?> jobID, "class='form-control chosen'");?> + + mr->squash;?> + +
+ squash == '1' ? 'checked' : '' ?> + name="squash" value="1" id="squash"> + +
+ + mr->assignee;?>