From 3387f129fb84e6dbcfd399df548e95d43bbe9094 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Thu, 11 May 2023 20:20:46 +0800 Subject: [PATCH] * Add an interface to query builds for block module. --- module/build/model.php | 21 ++++++++++++ module/build/test/build.class.php | 22 +++++++++++++ module/build/test/model/getbuildblockdata.php | 26 +++++++++++++++ .../model/yaml/getbuildblockdata/build.yaml | 32 +++++++++++++++++++ .../model/yaml/getbuildblockdata/project.yaml | 31 ++++++++++++++++++ .../yaml/getbuildblockdata/userview.yaml | 32 +++++++++++++++++++ test/data/build.yaml | 7 ++-- 7 files changed, 168 insertions(+), 3 deletions(-) create mode 100755 module/build/test/model/getbuildblockdata.php create mode 100644 module/build/test/model/yaml/getbuildblockdata/build.yaml create mode 100644 module/build/test/model/yaml/getbuildblockdata/project.yaml create mode 100644 module/build/test/model/yaml/getbuildblockdata/userview.yaml diff --git a/module/build/model.php b/module/build/model.php index 8e1319f005..2c971f2754 100644 --- a/module/build/model.php +++ b/module/build/model.php @@ -829,4 +829,25 @@ class buildModel extends model return $menu; } + + /** + * 为区块获取版本数据。 + * Get build's data for block. + * + * @param int $projectID + * @param string $orderBy + * @param int $limit + * @access public + * @return object[] + */ + public function getBuildBlockData(int $projectID = 0, string $orderBy = 'id_desc', int $limit = 10): array + { + return $this->dao->select('*')->from(TABLE_BUILD) + ->where('deleted')->eq('0') + ->beginIF(!$this->app->user->admin)->andWhere('execution')->in($this->app->user->view->sprints)->fi() + ->beginIF($projectID)->andWhere('project')->eq($projectID)->fi() + ->orderBy($orderBy) + ->limit($limit) + ->fetchAll(); + } } diff --git a/module/build/test/build.class.php b/module/build/test/build.class.php index a51cd8ba1f..1e1905faf0 100644 --- a/module/build/test/build.class.php +++ b/module/build/test/build.class.php @@ -428,4 +428,26 @@ class buildTest return $objects; } + + /** + * Test get build's data for block. + * + * @param int $projectID + * @param string $orderBy + * @param int $limit + * @param bool $adminUser + * @access public + * @return array + */ + public function getBuildBlockDataTest(int $projectID = 0, string $orderBy = 'id_desc', int $limit = 10, bool $adminUser = true): array + { + global $tester; + + if(!$adminUser) $tester->app->user->admin = false; + + $build = $this->objectModel->getBuildBlockData($projectID, $orderBy, $limit); + if(!$adminUser) $tester->app->user->admin = true; + + return $build; + } } diff --git a/module/build/test/model/getbuildblockdata.php b/module/build/test/model/getbuildblockdata.php new file mode 100755 index 0000000000..d344516ae9 --- /dev/null +++ b/module/build/test/model/getbuildblockdata.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +config('project')->gen(20); +zdTable('build')->config('build')->gen(20); +zdTable('userview')->config('userview')->gen(2); + +/** + +title=测试buildModel->getBuildBlockData(); +cid=1 +pid=1 + + +*/ + +$build = new buildTest(); + +r(count($build->getBuildBlockDataTest(2))) && p('') && e('2'); // 管理员获取项目ID为2的版本总数 +r(count($build->getBuildBlockDataTest(2, 'id_desc', 10, false))) && p('') && e('1'); // 非管理员获取项目ID为2的版本总数 +r(count($build->getBuildBlockDataTest(10, 'id_desc', 10))) && p('') && e('1'); // 管理员获取项目ID为10且不包括已删除版本的版本总数 +r(count($build->getBuildBlockDataTest(0, 'id_desc', 15))) && p('') && e('15'); // 管理员获取前15条记录的总数 +r($build->getBuildBlockDataTest(8, 'id_asc')) && p('0:name') && e('项目8版本8'); // 管理员获取项目为8的版本列表,按照id升序 diff --git a/module/build/test/model/yaml/getbuildblockdata/build.yaml b/module/build/test/model/yaml/getbuildblockdata/build.yaml new file mode 100644 index 0000000000..67d64628cf --- /dev/null +++ b/module/build/test/model/yaml/getbuildblockdata/build.yaml @@ -0,0 +1,32 @@ +title: table zt_build +author: Hu Fangzhou +desc: "" +version: "1.0" +fields: + - field: id + range: 1-20 + + - field: project + range: 1-10 + + - field: product + range: 1-10 + + - field: execution + range: 10-20 + + - field: name + fields: + - field: name1 + range: 项目{10},执行{10} + + - field: name2 + range: 1-10,11-20 + + - field: name3 + range: 版本 + + - field: name4 + range: 1-20 + - field: deleted + range: 0{19},1 diff --git a/module/build/test/model/yaml/getbuildblockdata/project.yaml b/module/build/test/model/yaml/getbuildblockdata/project.yaml new file mode 100644 index 0000000000..acbeedc1c0 --- /dev/null +++ b/module/build/test/model/yaml/getbuildblockdata/project.yaml @@ -0,0 +1,31 @@ +title: table zt_project +author: Hu Fangzhou +version: "1.0" +fields: + - field: id + range: 1-20 + - field: name + note: "名称" + fields: + - field: name1 + range: 项目{10},执行{10} + - field: name2 + range: 1-10{2} + - field: project + range: 0{10},1{3},2{2},4{3},6{2} + - field: type + range: project{10},sprint{4},stage{3},kanban{3} + - field: lifetime + range: "[]{10},short{2},long{1},ops{1},[]{6}" + - field: attribute + range: "[]{14},request,review,dev,[]{3}" + - field: begin + range: "20220101 000000:3M" + type: timestamp + format: "YY/MM/DD" + - field: end + range: "20230101 000000:1M" + type: timestamp + format: "YY/MM/DD" + - field: vision + range: rnd diff --git a/module/build/test/model/yaml/getbuildblockdata/userview.yaml b/module/build/test/model/yaml/getbuildblockdata/userview.yaml new file mode 100644 index 0000000000..a7a985410b --- /dev/null +++ b/module/build/test/model/yaml/getbuildblockdata/userview.yaml @@ -0,0 +1,32 @@ +title: table zt_userview +desc: "可访问权限" +author: Hu Fangzhou +version: "1.0" +fields: + - field: account + note: "用户名" + range: admin,dev1 + - field: programs + note: "项目集" + range: 0 + prefix: "," + postfix: "" + format: "" + - field: products + note: "产品" + range: "`1,3,5,7`,`2,4,6,8`" + prefix: "," + postfix: "" + format: "" + - field: projects + note: "项目" + range: "`1,3,5,7`,`2,4,6,8`" + prefix: "," + postfix: "" + format: "" + - field: sprints + note: "迭代" + range: "`11,13,15,17`,`12,14,16,18`" + prefix: "," + postfix: "" + format: "" diff --git a/test/data/build.yaml b/test/data/build.yaml index 22ec785fa2..17a53d3f7d 100644 --- a/test/data/build.yaml +++ b/test/data/build.yaml @@ -1,4 +1,5 @@ title: table zt_build +author: system desc: "" version: "1.0" fields: @@ -34,16 +35,16 @@ fields: - field: scmPath fields: - field: scmPath1 - range: [gitlab.zcorp.cc/easycorp/,svn.zcorp.cc/easysoft/trunk/zentaoext/]{3},[]{2} + range: "[gitlab.zcorp.cc/easycorp/,svn.zcorp.cc/easysoft/trunk/zentaoext/]{3},[]{2}" - field: scmPath2 range: zentaopms,xuanxuan,zdoo,zentaopro,zentaobiz,zentaomax,[]{2} - field: scmPath3 - range: [.git]{3},[]{5} + range: "[.git]{3},[]{5}" - field: filePath - range: [www.csdn.net/,www.baidu.com/,www.juejin.cn/]{2},[]{2} + range: "[www.csdn.net/,www.baidu.com/,www.juejin.cn/]{2},[]{2}" - field: date range: "(-1M)-(+1w):60"