diff --git a/db/zentao.sql b/db/zentao.sql index d05177fe58..4ecc3b3137 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -203,6 +203,7 @@ CREATE TABLE IF NOT EXISTS `zt_bug` ( `caseVersion` smallint(6) NOT NULL DEFAULT '1', `result` mediumint(8) unsigned NOT NULL, `repo` mediumint(8) unsigned NOT NULL, + `mr` mediumint(8) unsigned NOT NULL, `entry` varchar(255) NOT NULL, `lines` varchar(10) NOT NULL, `v1` varchar(40) NOT NULL, @@ -1250,6 +1251,12 @@ CREATE TABLE IF NOT EXISTS `zt_task` ( `lastEditedBy` varchar(30) NOT NULL, `lastEditedDate` datetime NOT NULL, `activatedDate` date NOT NULL, + `repo` mediumint(8) unsigned NOT NULL, + `mr` mediumint(8) unsigned NOT NULL, + `entry` varchar(255) NOT NULL, + `lines` varchar(10) NOT NULL, + `v1` varchar(40) NOT NULL, + `v2` varchar(40) NOT NULL, `deleted` enum('0','1') NOT NULL default '0', PRIMARY KEY (`id`), KEY `execution` (`execution`), diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 0262b979aa..f0923f5bb5 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -357,6 +357,7 @@ $lang->action->dynamicAction->release['notified'] = 'Notify Release'; $lang->action->dynamicAction->release['hidden'] = 'Hide Release'; $lang->action->dynamicAction->story['opened'] = 'Create Story'; +$lang->action->dynamicAction->story['importfromgitlab'] = "Issue associate create story"; $lang->action->dynamicAction->story['edited'] = 'Edit Story'; $lang->action->dynamicAction->story['activated'] = 'Activate Story'; $lang->action->dynamicAction->story['reviewed'] = 'Review Story'; @@ -397,6 +398,7 @@ $lang->action->dynamicAction->kanbanlane['moved'] = 'Move Swimlane'; $lang->action->dynamicAction->team['managedTeam'] = 'Manage Team'; $lang->action->dynamicAction->task['opened'] = 'Create Task'; +$lang->action->dynamicAction->task['importfromgitlab'] = "Issue associate create task"; $lang->action->dynamicAction->task['edited'] = 'Edit Task'; $lang->action->dynamicAction->task['commented'] = 'Task Comment'; $lang->action->dynamicAction->task['assigned'] = 'Assign Task'; @@ -430,6 +432,7 @@ $lang->action->dynamicAction->build['edited'] = 'Edit Build'; $lang->action->dynamicAction->build['deleted'] = 'Delete Build'; $lang->action->dynamicAction->bug['opened'] = 'Report Bug'; +$lang->action->dynamicAction->bug['importfromgitlab'] = "Issue associate create bug"; $lang->action->dynamicAction->bug['edited'] = 'Edit Bug'; $lang->action->dynamicAction->bug['activated'] = 'Activate Bug'; $lang->action->dynamicAction->bug['assigned'] = 'Assign Bug'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 40bc7d20d8..58fc5a8433 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -357,6 +357,7 @@ $lang->action->dynamicAction->release['notified'] = '通知发布'; $lang->action->dynamicAction->release['hidden'] = '隐藏发布'; $lang->action->dynamicAction->story['opened'] = "创建{$lang->SRCommon}"; +$lang->action->dynamicAction->story['importfromgitlab'] = "从Gitlab关联创建{$lang->SRCommon}"; $lang->action->dynamicAction->story['edited'] = "编辑{$lang->SRCommon}"; $lang->action->dynamicAction->story['activated'] = "激活{$lang->SRCommon}"; $lang->action->dynamicAction->story['reviewed'] = "评审{$lang->SRCommon}"; @@ -397,6 +398,7 @@ $lang->action->dynamicAction->kanbanlane['moved'] = '移动泳道'; $lang->action->dynamicAction->team['managedTeam'] = '维护团队'; $lang->action->dynamicAction->task['opened'] = '创建任务'; +$lang->action->dynamicAction->task['importfromgitlab'] = "从Gitlab关联创建任务"; $lang->action->dynamicAction->task['edited'] = '编辑任务'; $lang->action->dynamicAction->task['commented'] = '备注任务'; $lang->action->dynamicAction->task['assigned'] = '指派任务'; @@ -430,6 +432,7 @@ $lang->action->dynamicAction->build['edited'] = '编辑版本'; $lang->action->dynamicAction->build['deleted'] = '删除版本'; $lang->action->dynamicAction->bug['opened'] = '创建Bug'; +$lang->action->dynamicAction->bug['importfromgitlab'] = "从Gitlab关联创建Bug"; $lang->action->dynamicAction->bug['edited'] = '编辑Bug'; $lang->action->dynamicAction->bug['activated'] = '激活Bug'; $lang->action->dynamicAction->bug['assigned'] = '指派Bug'; diff --git a/module/gitlab/js/managegroupmembers.js b/module/gitlab/js/managegroupmembers.js index c67e34038e..a9391db43b 100644 --- a/module/gitlab/js/managegroupmembers.js +++ b/module/gitlab/js/managegroupmembers.js @@ -47,15 +47,19 @@ function deleteItem(obj) $(document).on('change', '[id^="levels"]', function() { + $tr = $(this).closest('tr'); $next = $(this).closest('td').next() - if($(this).val() == '50') + var ownerLevel = 50; + if($(this).val() == ownerLevel) { $next.prepend(''); $next.find('[id^="expires"]').addClass('hidden'); + $tr.find('a[onclick^="deleteItem"]').addClass('disabled'); } else { $next.find('[id^="expires"]').removeClass('hidden'); $next.find('input.disabled').remove(); + $tr.find('a[onclick^="deleteItem"]').removeClass('disabled'); } }) diff --git a/module/gitlab/view/managegroupmembers.html.php b/module/gitlab/view/managegroupmembers.html.php index 3821ad265d..08d5891c51 100644 --- a/module/gitlab/view/managegroupmembers.html.php +++ b/module/gitlab/view/managegroupmembers.html.php @@ -19,13 +19,14 @@ + name, "class='form-control' readonly");?> '') + $this->lang->gitlab->accessLevels, $member->access_level, "class='form-control chosen'");?> - access_level == '50'):?> + access_level == $ownerLevel):?> expires_at, "class='form-control form-date hidden'");?> @@ -35,7 +36,7 @@ ", '', "onclick='addItem(this)' class='btn btn-link'");?> - ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> + ", '', "onclick='deleteItem(this)' class='btn btn-link" . ($member->access_level == $ownerLevel ? ' disabled' : '') . "'");?> diff --git a/module/mr/control.php b/module/mr/control.php index d5b0bbb58d..674f66e75d 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -800,7 +800,7 @@ class mr extends control { if($this->post->reviewType == 'bug') $result = $this->mr->saveBug($repoID, $mr, $v1, $v2); if($this->post->reviewType == 'task') $result = $this->mr->saveTask($repoID, $mr, $v1, $v2); - if(dao::isError()) die(json_encode($result)); + if($result['result'] == 'fail') die(json_encode($result)); $objectID = $result['id']; $repo = $this->repo->getRepoById($repoID); diff --git a/module/mr/model.php b/module/mr/model.php index 8c290db811..9a577e46c5 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -573,7 +573,7 @@ class mrModel extends model if($singleDiff->state == 'empty') continue; $commits = $singleDiff->commits; $diffs = $singleDiff->diffs; - foreach ($diffs as $index => $diff) + foreach($diffs as $index => $diff) { if(empty($commits[$index])) continue; /* Make sure every file with same commitID is unique in $lines. */ @@ -793,11 +793,13 @@ class mrModel extends model */ public function getReview($repoID, $MRID, $revision = '') { + if(empty($repoID) OR empty($MRID)) return array(); + $reviews = array(); $bugs = $this->dao->select('t1.*, t2.realname')->from(TABLE_BUG)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.openedBy = t2.account') - ->where('t1.repo')->eq($repoID) - ->andWhere('t1.mr')->eq($MRID) + ->where('t1.repo')->eq((int)$repoID) + ->andWhere('t1.mr')->eq((int)$MRID) ->beginIF($revision)->andWhere('t1.v2')->eq($revision)->fi() ->andWhere('t1.deleted')->eq(0) ->fetchAll('id'); @@ -813,8 +815,8 @@ class mrModel extends model $tasks = $this->dao->select('t1.*, t2.realname')->from(TABLE_TASK)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.openedBy = t2.account') - ->where('t1.repo')->eq($repoID) - ->andWhere('t1.mr')->eq($MRID) + ->where('t1.repo')->eq((int)$repoID) + ->andWhere('t1.mr')->eq((int)$MRID) ->beginIF($revision)->andWhere('t1.v2')->eq($revision)->fi() ->andWhere('t1.deleted')->eq(0) ->fetchAll('id'); @@ -914,7 +916,7 @@ class mrModel extends model unset($data->commentText); $this->loadModel('bug'); - foreach(explode(',', $this->config->bug->create->requiredFields) as $requiredField) + foreach(explode(',', $this->config->bug->create->requiredFields . ',repo,mr') as $requiredField) { $requiredField = trim($requiredField); if(empty($requiredField)) continue; @@ -923,7 +925,7 @@ class mrModel extends model { $fieldName = $requiredField; if(isset($this->lang->bug->$requiredField)) $fieldName = $this->lang->bug->$requiredField; - dao::$errors[] = sprintf($this->lang->error->notempty, $fieldName); + dao::$errors[$requiredField][] = sprintf($this->lang->error->notempty, $fieldName); } } if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); @@ -992,7 +994,7 @@ class mrModel extends model if($task->assignedTo) $task->assignedDate = $now; $this->loadModel('task'); - foreach(explode(',', $this->config->task->create->requiredFields) as $requiredField) + foreach(explode(',', $this->config->task->create->requiredFields . ',repo,mr') as $requiredField) { $requiredField = trim($requiredField); if(empty($requiredField)) continue; @@ -1001,7 +1003,7 @@ class mrModel extends model { $fieldName = $requiredField; if(isset($this->lang->task->$requiredField)) $fieldName = $this->lang->task->$requiredField; - dao::$errors[] = sprintf($this->lang->error->notempty, $fieldName); + dao::$errors[$requiredField][] = sprintf($this->lang->error->notempty, $fieldName); } } if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); @@ -1082,10 +1084,11 @@ class mrModel extends model */ public function getLastReviewInfo($repoID) { - $lastReview = new stdclass(); - $lastReview->bug = $this->dao->select('*')->from(TABLE_BUG)->where('repo')->eq($repoID)->orderby('id_desc')->fetch(); - $lastReview->task = $this->dao->select('*')->from(TABLE_TASK)->where('repo')->eq($repoID)->orderby('id_desc')->fetch(); + if(empty($repoID)) return null; + $lastReview = new stdclass(); + $lastReview->bug = $this->dao->select('*')->from(TABLE_BUG)->where('repo')->eq((int)$repoID)->orderby('id_desc')->fetch(); + $lastReview->task = $this->dao->select('*')->from(TABLE_TASK)->where('repo')->eq((int)$repoID)->orderby('id_desc')->fetch(); return $lastReview; } diff --git a/module/mr/view/header.review.html.php b/module/mr/view/header.review.html.php index 5cf64cc281..7292b529b2 100644 --- a/module/mr/view/header.review.html.php +++ b/module/mr/view/header.review.html.php @@ -44,13 +44,13 @@ $this->loadModel('repo'); $taskModuleSelect = html::select('taskModule', $taskModules, $taskRepoModule, 'class="form-control chosen"'); $taskUserSelect = html::select('taskAssignedTo', $taskMembers, '', 'class="form-control chosen"'); -$taskExecutionSelect = html::select('taskExecution', $taskExecutions, $repoExecution, 'class="form-control chosen"'); +$taskExecutionSelect = html::select('taskExecution', $taskExecutions, $repoExecution, 'class="form-control chosen" onchange="changeExecution(this)"'); $reviewUrl = $this->createLink('mr', 'addReview', "repoID=$repoID&mr={$MR->id}&v1=$v1&v2="); $productSelect = html::select('product', $products, $repoProduct, 'class="product form-control chosen" onchange="changeProduct(this)"'); $branches = $this->loadModel('branch')->getPairs($repoProduct); $moduleSelect = html::select('module', $modules, $bugRepoModule, 'class="form-control chosen"'); -$executionSelect = html::select('execution', $executions, '', 'class="form-control chosen" onchange="changeExecution(this)"'); +$executionSelect = html::select('execution', $executions, '', 'class="form-control chosen"'); $typeSelect = html::select('repoType', $lang->repo->typeList, '', 'class="form-control chosen"'); $userSelect = html::select('assignedTo', $users, '', 'class="form-control chosen assignedTo"'); @@ -96,12 +96,14 @@ js::set('revision', '');
- - + + + + -
mr->reviewType;?>mr->reviewTypeList, 'bug', "class='form-control' onchange=changeReviewType(this)")?>mr->reviewType;?>mr->reviewTypeList, 'bug', "class='form-control' onchange=changeReviewType(this)")?>
repo->product?> +
@@ -161,7 +163,7 @@ js::set('revision', '');
-user->errorDeny, $lang->repo->common, $lang->repo->addReview);?> +user->errorDeny, $lang->mr->common, $lang->mr->addReview);?>
diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 3ee0d81265..479f87c305 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -735,6 +735,10 @@ class upgradeModel extends model $this->updateObjectBranch(); $this->updateProjectStories(); $this->appendExec('15_7_1'); + case '16_0_beta1': + $this->saveLogs('Execute 16_0_beta1'); + $this->adjustPriv16_0_beta1(); + $this->appendExec('16_0_beta1'); } $this->deletePatch(); @@ -5404,4 +5408,24 @@ class upgradeModel extends model return true; } + + /** + * Adjust priv 16_0_beta1. + * + * @access public + * @return bool + */ + public function adjustPriv16_0_beta1() + { + $groups = $this->dao->select('`group`')->from(TABLE_GROUPPRIV)->where('module')->eq('mr')->andWhere('method')->eq('addBug')->fetchPairs('group', 'group'); + foreach($groups as $groupID) + { + $groupPriv = new stdclass(); + $groupPriv->group = $groupID; + $groupPriv->module = 'mr'; + $groupPriv->method = 'addReview'; + $this->dao->replace(TABLE_GROUPPRIV)->data($groupPriv)->exec(); + } + return true; + } } diff --git a/test/model/mr/getdiffs.php b/test/model/mr/getdiffs.php new file mode 100644 index 0000000000..dadb786506 --- /dev/null +++ b/test/model/mr/getdiffs.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +> return null +使用正确的MR >> return normal + +*/ + +$mrModel = $tester->loadModel('mr'); + +$MR = ''; +$result = $mrModel->getDiffs($MR); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用空的MR + +$MR = $tester->dao->select('*')->from(TABLE_MR)->orderBy('id_desc')->limit(1)->fetch(); +$result = $mrModel->getDiffs($MR); +if(!empty($result)) +{ + $first = reset($result); + if(isset($first->fileName) and is_array($first->contents)) $result = 'return normal'; +} +r($result) && p() && e('return normal'); //使用正确的MR diff --git a/test/model/mr/getlastreviewinfo.php b/test/model/mr/getlastreviewinfo.php new file mode 100644 index 0000000000..f09591e8a8 --- /dev/null +++ b/test/model/mr/getlastreviewinfo.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +> return null +使用正确的repoID >> return normal + +*/ + +$mrModel = $tester->loadModel('mr'); + +$repoID = 0; +$result = $mrModel->getLastReviewInfo($repoID); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用空的repoID + +$repo = $tester->dao->select('*')->from(TABLE_REPO)->orderBy('id_desc')->limit(1)->fetch(); +$result = $mrModel->getLastReviewInfo($repo->id); +if(isset($result->bug) and isset($result->task)) $result = 'return normal'; +r($result) && p() && e('return normal'); //使用正确的repoID diff --git a/test/model/mr/getreview.php b/test/model/mr/getreview.php new file mode 100644 index 0000000000..adb4f46df4 --- /dev/null +++ b/test/model/mr/getreview.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +> return null +使用正确的repoID, MRID >> return normal +使用正确的repoID, MRID, 错误的revision >> return null + +*/ + +$mrModel = $tester->loadModel('mr'); + +$repoID = 0; +$MRID = 0; +$revision = ''; + +$result = $mrModel->getReview($repoID, $MRID, $revision); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用空的repoID, MRID, revision + +$MR = $tester->dao->select('*')->from(TABLE_MR)->orderBy('id_desc')->limit(1)->fetch(); +$repoID = $MR->repoID; +$MRID = $MR->id; +$result = $mrModel->getReview($repoID, $MRID, $revision); +if(!empty($result)) +{ + $first = reset($result); + if(isset($first['bug']) or isset($first['task'])) $result = 'return normal'; +} +r($result) && p() && e('return normal'); //使用正确的repoID, MRID + +$revision = '123qwe'; +$result = $mrModel->getReview($repoID, $MRID, $revision); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用正确的repoID, MRID, 错误的revision diff --git a/test/model/mr/savebug.php b/test/model/mr/savebug.php new file mode 100644 index 0000000000..db9118a8ec --- /dev/null +++ b/test/model/mr/savebug.php @@ -0,0 +1,44 @@ +#!/usr/bin/env php +> return false +使用正确的repoID, MRID。空的title。 >> return false +使用正确的repoID, MRID。POST数据正确。 >> Test Bug Review + +*/ + +$mrModel = $tester->loadModel('mr'); + +$_POST = array(); +$_POST['title'] = 'Test Bug Review'; +$_POST['commentText'] = 'Test Bug Review'; +$_POST['module'] = '1'; +$_POST['begin'] = '8'; +$_POST['end'] = '8'; +$_POST['product'] = '1'; +$_POST['assignedTo'] = ''; + +$repoID = 0; +$MRID = 0; +$v1 = 0; +$v2 = ''; +$result = $mrModel->saveBug($repoID, $MRID, $v1, $v2); +if($result['result'] == 'fail' and isset($result['message']['mr']) and isset($result['message']['repo'])) $result = 'return false'; +r($result) && p() && e('return false'); //使用空的repoID, MRID + +$_POST['title'] = ''; +$MR = $tester->dao->select('*')->from(TABLE_MR)->orderBy('id_desc')->limit(1)->fetch(); +$result = $mrModel->saveBug($MR->repoID, $MR->id, $v1, $v2); +if($result['result'] == 'fail' and isset($result['message']['title'])) $result = 'return false'; +r($result) && p() && e('return false'); //使用正确的repoID, MRID。空的title。 + +$_POST['title'] = 'Test Bug Review'; +$result = $mrModel->saveBug($MR->repoID, $MR->id, $v1, $v2); +r($result) && p('title') && e('Test Bug Review'); //使用正确的repoID, MRID。POST数据正确。 diff --git a/test/model/mr/savetask.php b/test/model/mr/savetask.php new file mode 100644 index 0000000000..5889dd4902 --- /dev/null +++ b/test/model/mr/savetask.php @@ -0,0 +1,45 @@ +#!/usr/bin/env php +> return false +使用正确的repoID, MRID。空的title。 >> return false +使用正确的repoID, MRID。POST数据正确。 >> Test Task Review + +*/ + +$mrModel = $tester->loadModel('mr'); + +$_POST = array(); +$_POST['title'] = 'Test Task Review'; +$_POST['commentText'] = 'Test Task Review'; +$_POST['taskModule'] = '1'; +$_POST['taskExecution'] = '1'; +$_POST['begin'] = '8'; +$_POST['end'] = '8'; +$_POST['taskAssignedTo'] = ''; +$_POST['entry'] = ''; + +$repoID = 0; +$MRID = 0; +$v1 = 0; +$v2 = ''; +$result = $mrModel->saveTask($repoID, $MRID, $v1, $v2); +if($result['result'] == 'fail' and isset($result['message']['mr']) and isset($result['message']['repo'])) $result = 'return false'; +r($result) && p() && e('return false'); //使用空的repoID, MRID + +$_POST['title'] = ''; +$MR = $tester->dao->select('*')->from(TABLE_MR)->orderBy('id_desc')->limit(1)->fetch(); +$result = $mrModel->saveTask($MR->repoID, $MR->id, $v1, $v2); +if($result['result'] == 'fail' and isset($result['message']['name'])) $result = 'return false'; +r($result) && p() && e('return false'); //使用正确的repoID, MRID。空的title。 + +$_POST['title'] = 'Test Task Review'; +$result = $mrModel->saveTask($MR->repoID, $MR->id, $v1, $v2); +r($result) && p('title') && e('Test Task Review'); //使用正确的repoID, MRID。POST数据正确。