From 284ab1de592a128e064601cb38dd0b78ee521578 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 13 Sep 2023 16:38:04 +0800 Subject: [PATCH] * Adjust for unit. --- module/execution/model.php | 4 +- module/group/model.php | 13 +- module/group/test/group.class.php | 21 +++- module/group/test/model/getadmins.php | 47 +++++++ module/kanban/model.php | 119 +++++------------- module/kanban/test/kanban.class.php | 5 +- module/kanban/test/model/addkanbancell.php | 30 +++-- .../test/model/createexecutioncolumns.php | 2 + .../kanban/test/model/createexecutionlane.php | 25 ++-- module/personnel/model.php | 17 ++- .../test/model/deleteprogramwhitelist.php | 6 +- .../test/model/deleteprojectwhitelist.php | 4 +- .../test/model/getwhitelistaccount.php | 15 ++- .../personnel/test/model/updatewhitelist.php | 4 +- module/personnel/test/personnel.class.php | 4 +- module/program/model.php | 4 +- module/program/test/model/getparentpm.php | 2 +- module/stakeholder/model.php | 8 +- .../test/model/getparentstakeholdergroup.php | 18 ++- .../test/model/getstakeholdergroup.php | 8 +- module/user/model.php | 26 ++-- module/user/test/model/checkproductpriv.php | 13 +- module/user/test/model/checkprogrampriv.php | 17 ++- module/user/test/model/checkprojectpriv.php | 18 ++- .../user/test/model/getprogramauthedusers.php | 18 ++- .../user/test/model/getprojectauthedusers.php | 10 +- .../user/test/model/getsprintauthedusers.php | 18 ++- module/user/test/user.class.php | 22 ++-- test/data/acl.yaml | 24 ++++ test/data/projectadmin.yaml | 22 ++++ 30 files changed, 326 insertions(+), 218 deletions(-) create mode 100755 module/group/test/model/getadmins.php create mode 100644 test/data/acl.yaml create mode 100644 test/data/projectadmin.yaml diff --git a/module/execution/model.php b/module/execution/model.php index 73f597b3db..72c57c5e49 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -4654,6 +4654,8 @@ class executionModel extends model $executionData->whitelist = ''; $executionData->plans = array(); $executionData->hasProduct = $project->hasProduct; + $executionData->openedBy = $this->app->user->account; + $executionData->openedDate = helper::now(); if($project->code) $executionData->code = $project->code; $projectProducts = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchAll(); @@ -4671,7 +4673,7 @@ class executionModel extends model $executionID = $this->create($executionData, array($this->app->user->account)); if($project->model == 'kanban') { - $execution = $this->getById($executionID); + $execution = $this->fetchById($executionID); $this->loadModel('kanban')->createRDKanban($execution); } diff --git a/module/group/model.php b/module/group/model.php index 94cdb6e991..35f61f3ff8 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -340,22 +340,21 @@ class groupModel extends model /** * Get admins by object id list. * - * @param int $idList + * @param array $idList * @param string $field * @access public - * @return void + * @return array */ - public function getAdmins($idList, $field = 'programs') + public function getAdmins(array $idList, string $field = 'programs'): array { $objects = array(); foreach($idList as $id) { - $objects[$id] = $this->dao->select('DISTINCT account')->from(TABLE_PROJECTADMIN) - ->where("CONCAT(',', $field, ',')")->like("%$id%") + $objects[$id] = $this->dao->select('account')->from(TABLE_PROJECTADMIN) + ->where("FIND_IN_SET('$id', `$field`)") ->orWhere($field)->eq('all') - ->fetchPairs(); + ->fetchPairs('account', 'account'); } - return $objects; } diff --git a/module/group/test/group.class.php b/module/group/test/group.class.php index 718e0cc7e7..8d42b1c8a2 100755 --- a/module/group/test/group.class.php +++ b/module/group/test/group.class.php @@ -435,13 +435,24 @@ class groupTest * @access public * @return void */ - public function updatePrivTest($privID,$lang) + public function updatePrivTest($privID, $lang) { $this->objectModel->updatePrivLang($privID,$lang); - if(dao::isError()) - { - return false; - } + if(dao::isError()) return false; return true; } + + /** + * 测试getAdmins方法。 + * Test getAdmins method. + * + * @param array $idList + * @param string $field + * @access public + * @return array + */ + public function getAdminsTest(array $idList, string $field = 'programs'): array + { + return $this->objectModel->getAdmins($idList, $field); + } } diff --git a/module/group/test/model/getadmins.php b/module/group/test/model/getadmins.php new file mode 100755 index 0000000000..a5b8ed8610 --- /dev/null +++ b/module/group/test/model/getadmins.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +gen(50); + +/** + +title=测试 groupModel->getAdmins(); +cid=1 +pid=1 + +*/ +$programIdList = array(1, 2, 5); +$projectIdList = array(6, 8, 10, 15); +$productIdList = array(1, 3, 10, 20); +$executionIdList = array(16, 20, 30, 24, 25); + +$group = new groupTest(); + +r($group->getAdminsTest(array())) && p() && e('0'); //测试不传入任何数据 + +$programAdmins = $group->getAdminsTest($programIdList, 'programs'); +r(count($programAdmins[1])) && p() && e('18'); //测试获取 programID = 1 的管理员数 +r(count($programAdmins[2])) && p() && e('17'); //测试获取 programID = 2 的管理员数 +r(count($programAdmins[5])) && p() && e('17'); //测试获取 programID = 5 的管理员数 + +$projectAdmins = $group->getAdminsTest($projectIdList, 'projects'); +r(count($projectAdmins[6])) && p() && e('10'); //测试获取 projectID = 6 的管理员数 +r(count($projectAdmins[8])) && p() && e('10'); //测试获取 projectID = 8 的管理员数 +r(count($projectAdmins[10])) && p() && e('10'); //测试获取 projectID = 10 的管理员数 +r(count($projectAdmins[15])) && p() && e('9'); //测试获取 projectID = 15 的管理员数 + +$productAdmins = $group->getAdminsTest($productIdList, 'products'); +r(count($productAdmins[1])) && p() && e('6'); //测试获取 productID = 1 的管理员数 +r(count($productAdmins[3])) && p() && e('6'); //测试获取 productID = 3 的管理员数 +r(count($productAdmins[10])) && p() && e('5'); //测试获取 productID = 10 的管理员数 +r(count($productAdmins[20])) && p() && e('5'); //测试获取 productID = 20 的管理员数 + +$executionAdmins = $group->getAdminsTest($executionIdList, 'executions'); +r(count($executionAdmins[16])) && p() && e('8'); //测试获取 executionID = 16 的管理员数 +r(count($executionAdmins[20])) && p() && e('7'); //测试获取 executionID = 20 的管理员数 +r(count($executionAdmins[30])) && p() && e('7'); //测试获取 executionID = 30 的管理员数 +r(count($executionAdmins[24])) && p() && e('7'); //测试获取 executionID = 24 的管理员数 +r(count($executionAdmins[25])) && p() && e('7'); //测试获取 executionID = 25 的管理员数 diff --git a/module/kanban/model.php b/module/kanban/model.php index 82fe175415..73625fd0e1 100755 --- a/module/kanban/model.php +++ b/module/kanban/model.php @@ -2536,7 +2536,7 @@ class kanbanModel extends model * @access public * @return void */ - public function createExecutionLane($executionID, $type = 'all') + public function createExecutionLane(int $executionID, string $type = 'all'): void { foreach($this->config->kanban->default as $type => $lane) { @@ -2559,98 +2559,46 @@ class kanbanModel extends model * @param int|array $laneID * @param string $type story|bug|task * @param int $executionID - * @param string $groupBy - * @param string $groupValue * @access public * @return void */ - public function createExecutionColumns($laneID, $type, $executionID) + public function createExecutionColumns(int|array $laneID, string $type, int $executionID): void { $devColumnID = $testColumnID = $resolvingColumnID = 0; - if($type == 'story') + + $columns = array(); + if($type == 'story') $columns = $this->lang->kanban->storyColumn; + if($type == 'bug') $columns = $this->lang->kanban->bugColumn; + if($type == 'task') $columns = $this->lang->kanban->taskColumn; + if(empty($columns)) return; + + foreach($columns as $colType => $name) { - foreach($this->lang->kanban->storyColumn as $colType => $name) + $data = new stdclass(); + $data->name = $name; + $data->color = '#333'; + $data->type = $colType; + $data->region = 0; + + if(str_contains(',developing,developed,', ",{$colType},")) $data->parent = $devColumnID; + if(str_contains(',testing,tested,', ",{$colType},")) $data->parent = $testColumnID; + if(str_contains(',fixing,fixed,', ",{$colType},")) $data->parent = $resolvingColumnID; + if(str_contains(',resolving,develop,test,', ",{$colType},")) $data->parent = -1; + + $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); + + $colID = $this->dao->lastInsertId(); + if($colType == 'develop') $devColumnID = $colID; + if($colType == 'test') $testColumnID = $colID; + if($colType == 'resolving') $resolvingColumnID = $colID; + + if(is_array($laneID)) { - $data = new stdclass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; - $data->region = 0; - - if(strpos(',developing,developed,', $colType) !== false) $data->parent = $devColumnID; - if(strpos(',testing,tested,', $colType) !== false) $data->parent = $testColumnID; - if(strpos(',develop,test,', $colType) !== false) $data->parent = -1; - - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - - $colID = $this->dao->lastInsertId(); - if($colType == 'develop') $devColumnID = $colID; - if($colType == 'test') $testColumnID = $colID; - - if(is_array($laneID)) - { - foreach($laneID as $id) $this->addKanbanCell($executionID, $id, $colID, 'story'); - } - else - { - $this->addKanbanCell($executionID, $laneID, $colID, 'story'); - } + foreach($laneID as $id) $this->addKanbanCell($executionID, $id, $colID, $type); } - } - elseif($type == 'bug') - { - foreach($this->lang->kanban->bugColumn as $colType => $name) + else { - $data = new stdclass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; - $data->region = 0; - if(strpos(',fixing,fixed,', $colType) !== false) $data->parent = $resolvingColumnID; - if(strpos(',testing,tested,', $colType) !== false) $data->parent = $testColumnID; - if(strpos(',resolving,test,', $colType) !== false) $data->parent = -1; - - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - - $colID = $this->dao->lastInsertId(); - if($colType == 'resolving') $resolvingColumnID = $colID; - if($colType == 'test') $testColumnID = $colID; - - if(is_array($laneID)) - { - foreach($laneID as $id) $this->addKanbanCell($executionID, $id, $colID, 'bug'); - } - else - { - $this->addKanbanCell($executionID, $laneID, $colID, 'bug'); - } - } - } - elseif($type == 'task') - { - foreach($this->lang->kanban->taskColumn as $colType => $name) - { - $data = new stdclass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; - $data->region = 0; - if(strpos(',developing,developed,', $colType) !== false) $data->parent = $devColumnID; - if($colType == 'develop') $data->parent = -1; - - $this->dao->insert(TABLE_KANBANCOLUMN)->data($data)->exec(); - - $colID = $this->dao->lastInsertId(); - if($colType == 'develop') $devColumnID = $colID; - - if(is_array($laneID)) - { - foreach($laneID as $id) $this->addKanbanCell($executionID, $id, $colID, 'task'); - } - else - { - $this->addKanbanCell($executionID, $laneID, $colID, 'task'); - } + $this->addKanbanCell($executionID, $laneID, $colID, $type); } } } @@ -2662,10 +2610,11 @@ class kanbanModel extends model * @param int $laneID * @param int $colID * @param string $type story|task|bug|card + * @param int $cardID * @access public * @return void */ - public function addKanbanCell($kanbanID, $laneID, $colID, $type, $cardID = 0) + public function addKanbanCell(int $kanbanID, int $laneID, int $colID, string $type, int $cardID = 0): void { $cell = $this->dao->select('id, cards')->from(TABLE_KANBANCELL) ->where('kanban')->eq($kanbanID) diff --git a/module/kanban/test/kanban.class.php b/module/kanban/test/kanban.class.php index a045f40f82..e4b3c52413 100644 --- a/module/kanban/test/kanban.class.php +++ b/module/kanban/test/kanban.class.php @@ -938,13 +938,12 @@ class kanbanTest * * @param int $executionID * @param string $type - * @param string $groupBy * @access public * @return int */ - public function createExecutionLaneTest($executionID, $type = 'all', $groupBy = 'default') + public function createExecutionLaneTest($executionID, $type = 'all') { - $this->objectModel->createExecutionLane($executionID, $type, $groupBy); + $this->objectModel->createExecutionLane($executionID, $type); if(dao::isError()) return dao::getError(); diff --git a/module/kanban/test/model/addkanbancell.php b/module/kanban/test/model/addkanbancell.php index 5f73f2bc91..0fdc614488 100755 --- a/module/kanban/test/model/addkanbancell.php +++ b/module/kanban/test/model/addkanbancell.php @@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/kanban.class.php'; su('admin'); +zdTable('kanbancell')->gen(0); + /** title=测试 kanbanModel->addKanbanCell(); @@ -37,19 +39,15 @@ $columnIDList = array('1', '408', '412', '421'); $typeList = array('common', 'story', 'bug', 'task'); $cardID = '3'; -r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[0], $columnIDList[0], $typeList[0])) && p('type,cards') && e('common,,0,1,2,'); // 更新类型为common的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[0], $columnIDList[0], $typeList[0], $cardID)) && p('type,cards') && e('common,,3,0,1,2,'); // 更新类型为common的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[1], $columnIDList[0], $typeList[0])) && p('type,cards') && e('common,'); // 插入类型为common的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[1], $columnIDList[0], $typeList[0], $cardID)) && p('type,cards') && e('common,,3,'); // 插入类型为common的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[1], $typeList[1])) && p('type,cards') && e('story,,0,'); // 更新类型为story的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[1], $typeList[1], $cardID)) && p('type,cards') && e('story,,3,0,'); // 更新类型为story的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[2], $typeList[1])) && p('type,cards') && e('story,'); // 插入类型为story的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[2], $typeList[1], $cardID)) && p('type,cards') && e('story,,3,'); // 插入类型为story的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[2], $typeList[2])) && p('type,cards') && e('bug,,0,'); // 更新类型为bug的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[2], $typeList[2], $cardID)) && p('type,cards') && e('bug,,3,0,'); // 更新类型为bug的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[3], $typeList[2])) && p('type,cards') && e('bug,'); // 插入类型为bug的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[3], $typeList[2], $cardID)) && p('type,cards') && e('bug,,3,'); // 插入类型为bug的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[3], $typeList[3])) && p('type,cards') && e('task,,0,'); // 更新类型为task的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[3], $typeList[3], $cardID)) && p('type,cards') && e('task,,3,0,'); // 更新类型为task的kanbancell 有cardID -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[0], $typeList[3])) && p('type,cards') && e('task,'); // 插入类型为task的kanbancell -r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[0], $typeList[3], $cardID)) && p('type,cards') && e('task,,3,'); // 插入类型为task的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[0], $columnIDList[0], $typeList[0], 1)) && p('type|cards', '|') && e('common|,1,'); // 更新类型为common的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[0], $columnIDList[0], $typeList[0], $cardID)) && p('type|cards', '|') && e('common|,3,1,'); // 更新类型为common的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[1], $columnIDList[0], $typeList[0])) && p('type|cards', '|') && e('common|~~'); // 插入类型为common的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[0], $laneIDList[1], $columnIDList[0], $typeList[0], $cardID)) && p('type|cards', '|') && e('common|,3,'); // 插入类型为common的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[1], $typeList[1], 2)) && p('type|cards', '|') && e('story|,2,'); // 更新类型为story的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[1], $typeList[1], $cardID)) && p('type|cards', '|') && e('story|,3,2,'); // 更新类型为story的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[2], $typeList[1])) && p('type|cards', '|') && e('story|~~'); // 插入类型为story的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[1], $columnIDList[2], $typeList[1], $cardID)) && p('type|cards', '|') && e('story|,3,'); // 插入类型为story的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[3], $typeList[2])) && p('type|cards', '|') && e('bug|~~'); // 插入类型为bug的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[2], $columnIDList[3], $typeList[2], $cardID)) && p('type|cards', '|') && e('bug|,3,'); // 插入类型为bug的kanbancell 有cardID +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[0], $typeList[3])) && p('type|cards', '|') && e('task|~~'); // 插入类型为task的kanbancell +r($kanban->addKanbanCellTest($kanbanIDList[1], $laneIDList[3], $columnIDList[0], $typeList[3], $cardID)) && p('type|cards', '|') && e('task|,3,'); // 插入类型为task的kanbancell 有cardID diff --git a/module/kanban/test/model/createexecutioncolumns.php b/module/kanban/test/model/createexecutioncolumns.php index 60692f7c93..6401b073a1 100755 --- a/module/kanban/test/model/createexecutioncolumns.php +++ b/module/kanban/test/model/createexecutioncolumns.php @@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/kanban.class.php'; su('admin'); +zdTable('kanbancell')->gen(0); + /** title=测试 kanbanModel->createExecutionColumns(); diff --git a/module/kanban/test/model/createexecutionlane.php b/module/kanban/test/model/createexecutionlane.php index 8de050276f..2843a58150 100755 --- a/module/kanban/test/model/createexecutionlane.php +++ b/module/kanban/test/model/createexecutionlane.php @@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/kanban.class.php'; su('admin'); +zdTable('kanbanlane')->gen(0); + /** title=测试 kanbanModel->createExecutionLane(); @@ -28,20 +30,15 @@ pid=1 $executionIDList = array('101', '102', '103', '104', '105'); $typeIDList = array('all', 'story', 'task', 'bug'); -$groupByIDList = array('default', 'pri', 'category', 'module', 'source', 'assignedTo', 'story', 'severity'); $kanban = new kanbanTest(); -r($kanban->createExecutionLaneTest($executionIDList[0])) && p() && e('3'); // 创建执行101的泳道 -r($kanban->createExecutionLaneTest($executionIDList[0], $typeIDList[1])) && p() && e('2'); // 创建执行101 需求的泳道 -r($kanban->createExecutionLaneTest($executionIDList[0], $typeIDList[1], $groupByIDList[2])) && p() && e('3'); // 创建执行101 需求 按类别分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[1])) && p() && e('3'); // 创建执行101的泳道 -r($kanban->createExecutionLaneTest($executionIDList[1], $typeIDList[1], $groupByIDList[4])) && p() && e('3'); // 创建执行102 需求 按来源分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[1], $typeIDList[2], $groupByIDList[1])) && p() && e('4'); // 创建执行102 任务 按优先级分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[1], $typeIDList[2], $groupByIDList[6])) && p() && e('7'); // 创建执行102 任务 按需求分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[2])) && p() && e('3'); // 创建执行103的泳道 -r($kanban->createExecutionLaneTest($executionIDList[2], $typeIDList[3], $groupByIDList[7])) && p() && e('4'); // 创建执行103 bug 按严重程度分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[2], $typeIDList[3], $groupByIDList[3])) && p() && e('8'); // 创建执行103 bug 按模块分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[2], $typeIDList[3], $groupByIDList[5])) && p() && e('10'); // 创建执行103 bug 按指派给分组的泳道 -r($kanban->createExecutionLaneTest($executionIDList[3])) && p() && e('3'); // 创建执行104的泳道 -r($kanban->createExecutionLaneTest($executionIDList[4])) && p() && e('3'); // 创建执行105的泳道 +r($kanban->createExecutionLaneTest($executionIDList[0])) && p() && e('3'); // 创建执行101的泳道 +r($kanban->createExecutionLaneTest($executionIDList[0], $typeIDList[1])) && p() && e('2'); // 创建执行101 需求的泳道 +r($kanban->createExecutionLaneTest($executionIDList[1])) && p() && e('3'); // 创建执行101的泳道 +r($kanban->createExecutionLaneTest($executionIDList[1], $typeIDList[1])) && p() && e('2'); // 创建执行102 需求 按来源分组的泳道 +r($kanban->createExecutionLaneTest($executionIDList[1], $typeIDList[2])) && p() && e('3'); // 创建执行102 任务 按优先级分组的泳道 +r($kanban->createExecutionLaneTest($executionIDList[2])) && p() && e('3'); // 创建执行103的泳道 +r($kanban->createExecutionLaneTest($executionIDList[2], $typeIDList[3])) && p() && e('2'); // 创建执行103 bug 按严重程度分组的泳道 +r($kanban->createExecutionLaneTest($executionIDList[3])) && p() && e('3'); // 创建执行104的泳道 +r($kanban->createExecutionLaneTest($executionIDList[4])) && p() && e('3'); // 创建执行105的泳道 diff --git a/module/personnel/model.php b/module/personnel/model.php index ff91056ddd..b8bc5fb42a 100644 --- a/module/personnel/model.php +++ b/module/personnel/model.php @@ -537,7 +537,7 @@ class personnelModel extends model * @access public * @return array */ - public function getWhitelistAccount($objectID = 0, $objectType = '') + public function getWhitelistAccount(int $objectID = 0, string $objectType = '') { return $this->dao->select('account')->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->fetchPairs('account', 'account'); } @@ -554,13 +554,12 @@ class personnelModel extends model * @access public * @return void */ - public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add', $updateType = 'replace') + public function updateWhitelist(array $users = array(), string $objectType = '', int $objectID = 0, string $type = 'whitelist', string $source = 'add', string $updateType = 'replace') { $oldWhitelist = $this->dao->select('account,objectType,objectID,type,source')->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->fetchAll('account'); if($updateType == 'replace') $this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->exec(); - $users = array_filter($users); - $users = array_unique($users); + $users = array_unique(array_filter($users)); $accounts = array(); foreach($users as $account) { @@ -646,8 +645,7 @@ class personnelModel extends model } /* Update user view. */ - $this->loadModel('user'); - foreach($deletedAccounts as $account) $this->user->updateUserView($objectID, $objectType, array($account)); + $this->loadModel('user')->updateUserView($objectID, $objectType, $deletedAccounts); } /** @@ -661,6 +659,7 @@ class personnelModel extends model public function addWhitelist($objectType = '', $objectID = 0) { $users = $this->post->account; + if(empty($users)) $users = array(); $this->updateWhitelist($users, $objectType, $objectID); } @@ -704,7 +703,7 @@ class personnelModel extends model * @access public * @return void */ - public function deleteProgramWhitelist($programID = 0, $account = '') + public function deleteProgramWhitelist(int $programID = 0, string $account = '') { $program = $this->loadModel('program')->getByID($programID); if(empty($program)) return false; @@ -744,10 +743,10 @@ class personnelModel extends model * @access public * @return void */ - public function deleteProjectWhitelist($objectID = 0, $account = '') + public function deleteProjectWhitelist(int $objectID = 0, string $account = ''): void { $project = $this->dao->select('id,project,whitelist')->from(TABLE_PROJECT)->where('id')->eq($objectID)->fetch(); - if(empty($project)) return false; + if(empty($project)) return; $projectID = $project->project ? $project->project : $objectID; $sprints = $this->dao->select('id')->from(TABLE_PROJECT)->where('project')->eq($projectID)->andWhere('deleted')->eq('0')->fetchPairs('id'); diff --git a/module/personnel/test/model/deleteprogramwhitelist.php b/module/personnel/test/model/deleteprogramwhitelist.php index e49da887eb..5e21a86e16 100755 --- a/module/personnel/test/model/deleteprogramwhitelist.php +++ b/module/personnel/test/model/deleteprogramwhitelist.php @@ -3,6 +3,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/personnel.class.php'; +zdTable('acl')->gen(100); + /** title=测试 personnelModel->deleteProgramWhitelist(); @@ -18,7 +20,7 @@ $personnel = new personnelTest('admin'); $programID = array(); $programID[0] = 10; -$programID[1] = ''; +$programID[1] = 0; $account = array(); $account[0] = 'dev10'; @@ -28,4 +30,4 @@ $result1 = $personnel->deleteProgramWhitelistTest($programID[0], $account[0]); $result2 = $personnel->deleteProgramWhitelistTest($programID[1], $account[1]); r($result1) && p() && e('0'); //我这里通过add方法创建了一个id为10的项目集白名单,并修改source为同步,然后删除创建的这条信息 -r($result2) && p() && e('0'); //传入空时这里我删除了一个objectID为0的,program白名单信息,如果没这条数据跳过 \ No newline at end of file +r($result2) && p() && e('0'); //传入空时这里我删除了一个objectID为0的,program白名单信息,如果没这条数据跳过 diff --git a/module/personnel/test/model/deleteprojectwhitelist.php b/module/personnel/test/model/deleteprojectwhitelist.php index 4d369aa07e..c4c558db0a 100755 --- a/module/personnel/test/model/deleteprojectwhitelist.php +++ b/module/personnel/test/model/deleteprojectwhitelist.php @@ -18,7 +18,7 @@ $personnel = new personnelTest('admin'); $projectID = array(); $projectID[0] = 15; -$projectID[1] = ''; +$projectID[1] = 0; $account = array(); $account[0] = 'dev15'; @@ -28,4 +28,4 @@ $result1 = $personnel->deleteProjectWhitelistTest($projectID[0], $account[0]); $result2 = $personnel->deleteProjectWhitelistTest($projectID[1], $account[1]); r($result1) && p() && e('0'); //通过add方法创建一个白名单,这里判断了objectType为sprint的情况,正常传入无法删除 -r($result2) && p() && e('0'); //传入空的情况时,删除为objectID为0的数据,如果空,则跳过 \ No newline at end of file +r($result2) && p() && e('0'); //传入空的情况时,删除为objectID为0的数据,如果空,则跳过 diff --git a/module/personnel/test/model/getwhitelistaccount.php b/module/personnel/test/model/getwhitelistaccount.php index 8777a8a5d4..32c26afaa1 100755 --- a/module/personnel/test/model/getwhitelistaccount.php +++ b/module/personnel/test/model/getwhitelistaccount.php @@ -3,6 +3,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/personnel.class.php'; +zdTable('acl')->gen(100); + /** title=测试 personnelModel->getWhitelistAccount(); @@ -24,7 +26,6 @@ $objectID = array(); $objectID[0] = 1; $objectID[1] = 2; $objectID[2] = 1111; -$objectID[3] = ''; $objectType = array(); $objectType[0] = 'project'; @@ -35,11 +36,9 @@ $objectType[3] = 'sprint'; $result1 = $personnel->getWhitelistAccountTest($objectID[0], $objectType[1]); $result2 = $personnel->getWhitelistAccountTest($objectID[1], $objectType[2]); $result3 = $personnel->getWhitelistAccountTest($objectID[2], $objectType[3]); -$result4 = $personnel->getWhitelistAccountTest($objectID[3], $objectType[0]); -r(count($result1)) && p() && e('3'); //这是一个正常测试,统计关联白名单人员数量 -r($result1) && p('admin') && e('admin'); //取出其中一个数据admin -r($result1) && p('dev10') && e('dev10'); //取出另一个数据dev10 -r(count($result2)) && p() && e('0'); //取出objectid2的白名单数量 -r(count($result3)) && p() && e('0'); //当objectID不存在时,统计匹配数量 -r(count($result4)) && p() && e('0'); //当传入参数为空时,统计匹配人员数量 +r(count($result1)) && p() && e('5'); //这是一个正常测试,统计关联白名单人员数量 +r($result1) && p('admin') && e('admin'); //取出其中一个数据admin +r($result1) && p('user20') && e('user20'); //取出另一个数据dev10 +r(count($result2)) && p() && e('5'); //取出objectid2的白名单数量 +r(count($result3)) && p() && e('0'); //当objectID不存在时,统计匹配数量 diff --git a/module/personnel/test/model/updatewhitelist.php b/module/personnel/test/model/updatewhitelist.php index 0f95d0b696..4a5fe8372b 100755 --- a/module/personnel/test/model/updatewhitelist.php +++ b/module/personnel/test/model/updatewhitelist.php @@ -3,6 +3,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/personnel.class.php'; +zdTable('acl')->gen(0); + /** title=测试 personnelModel->updateWhitelist(); @@ -50,4 +52,4 @@ $result3 = $personnel->updateWhitelistTest($user[1], $objectType[0], $objectID[0 r($result1) && p() && e('0'); //传入已有参数时,数据变更类型source为add r($result2) && p() && e('0'); //传入已有参数时,数据变更type为blacklist -r($result3) && p() && e('0'); //传入没有的参数时,新建一条source为sync的数据 \ No newline at end of file +r($result3) && p() && e('0'); //传入没有的参数时,新建一条source为sync的数据 diff --git a/module/personnel/test/personnel.class.php b/module/personnel/test/personnel.class.php index 6ace3cf88c..22c677348b 100644 --- a/module/personnel/test/personnel.class.php +++ b/module/personnel/test/personnel.class.php @@ -264,12 +264,12 @@ class personnelTest public function deleteProgramWhitelistTest($programID, $account) { global $tester; - $this->addWhitelistTest('program', $programID, array($account)); $tester->dao->update(TABLE_ACL)->set('source')->eq('sync')->where('objectID')->eq($programID)->andWhere('objectType')->eq('program')->exec(); - $objects = $this->objectModel->deleteProgramWhitelist($programID, $account); + $this->objectModel->deleteProgramWhitelist($programID, $account); if(dao::isError()) return dao::getError(); + $tester->dao->update(TABLE_ACL)->set('source')->eq('sync')->where('objectID')->eq($programID)->andWhere('objectType')->eq('program')->exec(); return $objects; } diff --git a/module/program/model.php b/module/program/model.php index 5fce549a19..cf03065421 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1437,9 +1437,9 @@ class programModel extends model * * @param array $programIdList * @access public - * @return void + * @return array */ - public function getParentPM($programIdList) + public function getParentPM(array $programIdList): array { $objects = $this->dao->select('id, path, parent')->from(TABLE_PROGRAM)->where('id')->in($programIdList)->andWhere('acl')->ne('open')->fetchAll('id'); diff --git a/module/program/test/model/getparentpm.php b/module/program/test/model/getparentpm.php index d6260210e7..a3f889405d 100755 --- a/module/program/test/model/getparentpm.php +++ b/module/program/test/model/getparentpm.php @@ -13,7 +13,7 @@ $program->grade->range('1{5},2{5}'); $program->parent->range('0{5},1-5'); $program->status->range('wait,doing,suspended,closed'); $program->openedBy->range('admin,test1'); -$program->pm->range('admin,test1'); +$program->PM->range('admin,test1'); $program->acl->range('private'); $program->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); $program->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); diff --git a/module/stakeholder/model.php b/module/stakeholder/model.php index d4620452f8..2609e04dfe 100644 --- a/module/stakeholder/model.php +++ b/module/stakeholder/model.php @@ -287,7 +287,7 @@ class stakeholderModel extends model * @access public * @return array */ - public function getStakeholderGroup($objectIdList) + public function getStakeholderGroup(array $objectIdList): array { $stakeholders = $this->dao->select('objectID, user')->from(TABLE_STAKEHOLDER)->where('objectID')->in($objectIdList)->andWhere('deleted')->eq('0')->fetchAll(); @@ -307,10 +307,9 @@ class stakeholderModel extends model * @access public * @return array */ - public function getParentStakeholderGroup($objectIdList) + public function getParentStakeholderGroup(array $objectIdList): array { $objects = $this->dao->select('id, path, parent')->from(TABLE_PROJECT)->where('id')->in($objectIdList)->andWhere('acl')->ne('open')->fetchAll('id'); - $parents = array(); foreach($objects as $object) { @@ -326,8 +325,7 @@ class stakeholderModel extends model if(empty($parents)) return array(); /* Get all parent stakeholders.*/ - $parentStakeholders = $this->dao->select('objectID, user')->from(TABLE_STAKEHOLDER)->where('objectID')->in(array_keys($parents))->andWhere('deleted')->eq('0')->fetchAll(); - + $parentStakeholders = $this->dao->select('objectID, user')->from(TABLE_STAKEHOLDER)->where('objectID')->in(array_keys($parents))->andWhere('deleted')->eq('0')->fetchAll(); $parentStakeholderGroup = array(); foreach($parentStakeholders as $parentStakeholder) { diff --git a/module/stakeholder/test/model/getparentstakeholdergroup.php b/module/stakeholder/test/model/getparentstakeholdergroup.php index 34e4b99f91..275b148de1 100755 --- a/module/stakeholder/test/model/getparentstakeholdergroup.php +++ b/module/stakeholder/test/model/getparentstakeholdergroup.php @@ -4,6 +4,16 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/stakeholder.class.php'; su('admin'); +$product = zdTable('project'); +$product->id->range('1-50'); +$product->type->range('project{10},sprint{40}'); +$product->project->range('0{10},1-10{4}'); +$product->parent->range('0{10},1-10{4}'); +$product->acl->range('private'); +$product->gen(50)->fixPath(); + +zdTable('stakeholder')->gen(50); + /** title=测试 stakeholderModel->getParentStakeholderGroup(); @@ -21,6 +31,8 @@ $stakeholder = $tester->loadModel('stakeholder'); $objectIDList = array('11', '31', '100', '1'); $noObjectIDList = array(); -r($stakeholder->getParentStakeholderGroup($objectIDList)) && p('31:user9') && e('user9');//正常输入项目项目集参数查询 -r($stakeholder->getParentStakeholderGroup($noObjectIDList)) && p() && e('0'); //不输入项目集项目参数查询 -r(count($stakeholder->getParentStakeholderGroup($objectIDList))) && p() && e('2'); //正常输入项目项目集参数查询统计 \ No newline at end of file +$stakeholders = ($stakeholder->getParentStakeholderGroup($objectIDList)); +r($stakeholders) && p('11:admin') && e('admin'); //正常输入项目项目集参数查询 +r($stakeholders) && p('31:user5') && e('user5'); //正常输入项目项目集参数查询 +r($stakeholder->getParentStakeholderGroup($noObjectIDList)) && p() && e('0'); //不输入项目集项目参数查询 +r(count($stakeholder->getParentStakeholderGroup($objectIDList))) && p() && e('2'); //正常输入项目项目集参数查询统计 diff --git a/module/stakeholder/test/model/getstakeholdergroup.php b/module/stakeholder/test/model/getstakeholdergroup.php index b2dde18b23..a6b158df3b 100755 --- a/module/stakeholder/test/model/getstakeholdergroup.php +++ b/module/stakeholder/test/model/getstakeholdergroup.php @@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/stakeholder.class.php'; su('admin'); +zdTable('stakeholder')->gen(50); + /** title=测试 stakeholderModel->getStakeholderGroup(); @@ -21,6 +23,6 @@ $stakeholder = $tester->loadModel('stakeholder'); $objectIDList = array('11', '31', '100', '1'); $noObjectIDList = array(); -r($stakeholder->getStakeholderGroup($objectIDList)) && p('11:admin') && e('admin');//正常查询干系人分组 -r(count($stakeholder->getStakeholderGroup($objectIDList))) && p() && e('4'); //正常查询干系人分组统计 -r($stakeholder->getStakeholderGroup($noObjectIDList)) && p() && e('0'); //空数组查询 \ No newline at end of file +r($stakeholder->getStakeholderGroup($objectIDList)) && p('11:user10') && e('user10');//正常查询干系人分组 +r(count($stakeholder->getStakeholderGroup($objectIDList))) && p() && e('3'); //正常查询干系人分组统计 +r($stakeholder->getStakeholderGroup($noObjectIDList)) && p() && e('0'); //空数组查询 diff --git a/module/user/model.php b/module/user/model.php index d1855cb8e8..d0a3c5db33 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2107,7 +2107,7 @@ class userModel extends model * @access public * @return void */ - public function updateUserView($objectIdList, $objectType, $users = array()) + public function updateUserView(int|array $objectIdList, string $objectType, array $users = array()) { if(is_numeric($objectIdList)) $objectIdList = array($objectIdList); if(!is_array($objectIdList)) return false; @@ -2122,11 +2122,11 @@ class userModel extends model * Update program user view. * * @param array $programIdList - * @param array $user + * @param array $users * @access public * @return void */ - public function updateProgramView($programIdList, $users) + public function updateProgramView(array $programIdList, array $users) { $programs = $this->dao->select('id, PM, PO, QD, RD, openedBy, acl, parent, path')->from(TABLE_PROJECT) ->where('id')->in($programIdList) @@ -2215,7 +2215,7 @@ class userModel extends model * @access public * @return void */ - public function updateProjectView($projectIdList, $users) + public function updateProjectView(array $projectIdList, array $users) { $projects = $this->dao->select('id, PM, PO, QD, RD, openedBy, acl, parent, path, type')->from(TABLE_PROJECT) ->where('id')->in($projectIdList) @@ -2303,7 +2303,7 @@ class userModel extends model * @access public * @return void */ - public function updateProductView($productIdList, $users) + public function updateProductView(array $productIdList, array $users) { $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in($productIdList)->andWhere('acl')->ne('open')->fetchAll('id'); if(empty($products)) return true; @@ -2377,7 +2377,7 @@ class userModel extends model * @access public * @return void */ - public function updateSprintView($sprintIdList, $users) + public function updateSprintView(array $sprintIdList, array $users) { $sprints = $this->dao->select('id, project, PM, PO, QD, RD, openedBy, acl, parent, path, grade, type')->from(TABLE_PROJECT) ->where('id')->in($sprintIdList) @@ -2477,7 +2477,7 @@ class userModel extends model * @access public * @return bool */ - public function checkProgramPriv($program, $account, $stakeholders, $whiteList, $admins = array()) + public function checkProgramPriv(object $program, string $account, array $stakeholders = array(), array $whiteList = array(), $admins = array()): bool { if(strpos($this->app->company->admins, ',' . $account . ',') !== false) return true; @@ -2512,7 +2512,7 @@ class userModel extends model * @access public * @return bool */ - public function checkProjectPriv($project, $account, $stakeholders, $teams, $whiteList, $admins = array()) + public function checkProjectPriv(object $project, string $account, array $stakeholders, array $teams, array $whiteList, array $admins = array()): bool { if(strpos($this->app->company->admins, ',' . $account . ',') !== false) return true; if($project->PO == $account OR $project->QD == $account OR $project->RD == $account OR $project->PM == $account) return true; @@ -2572,7 +2572,7 @@ class userModel extends model * @access public * @return bool */ - public function checkProductPriv($product, $account, $groups, $teams, $stakeholders, $whiteList, $admins = array()) + public function checkProductPriv(object $product, string $account, array $groups, array $teams, array $stakeholders, array $whiteList, array $admins = array()): bool { if(strpos($this->app->company->admins, ',' . $account . ',') !== false) return true; if($product->PO == $account OR $product->QD == $account OR $product->RD == $account OR $product->createdBy == $account OR (isset($product->feedback) && $product->feedback == $account)) return true; @@ -2597,7 +2597,7 @@ class userModel extends model * @access public * @return array */ - public function getProjectAuthedUsers($project, $stakeholders, $teams, $whiteList, $admins = array()) + public function getProjectAuthedUsers(object $project, array $stakeholders, array $teams, array $whiteList, array $admins = array()): array { $users = array(); @@ -2647,7 +2647,7 @@ class userModel extends model * @access public * @return array */ - public function getProgramAuthedUsers($program, $stakeholders, $whiteList, $admins) + public function getProgramAuthedUsers(object $program, array $stakeholders, array $whiteList, array $admins): array { $users = array(); @@ -2660,7 +2660,7 @@ class userModel extends model $users += $whiteList ? $whiteList : array(); $users += $admins ? $admins : array(); - return $users; + return array_filter($users); } /** @@ -2674,7 +2674,7 @@ class userModel extends model * @access public * @return array */ - public function getSprintAuthedUsers($sprint, $stakeholders, $teams, $whiteList, $admins) + public function getSprintAuthedUsers(object $sprint, array $stakeholders, array $teams, array $whiteList, array $admins): array { return $this->getProjectAuthedUsers($sprint, $stakeholders, $teams, $whiteList, $admins); } diff --git a/module/user/test/model/checkproductpriv.php b/module/user/test/model/checkproductpriv.php index a014dba75c..35b046156a 100755 --- a/module/user/test/model/checkproductpriv.php +++ b/module/user/test/model/checkproductpriv.php @@ -2,6 +2,7 @@ gen(10); zdTable('user')->gen(200); su('admin'); @@ -26,12 +27,20 @@ $product->id = 1; $product->name = '测试产品'; $product->PO = 'test2'; $product->openedBy = 'pm1'; +$product->acl = 'private'; $stakeholders['user10'] = 'user10'; $whiteList['user60'] = 'user60'; +$admins['test6'] = 'test6'; -r($user->checkProductPrivTest('', 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 +$user->objectModel->app->company->admins = ',admin,'; + +r($user->checkProductPrivTest(new stdclass(), 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 r($user->checkProductPrivTest($product, 'test3')) && p() && e('0'); //传入产品、用户名,判断test3用户是否对此产品有权限 r($user->checkProductPrivTest($product, 'test2')) && p() && e('1'); //传入产品、用户名,判断test2用户是否对此产品有权限 r($user->checkProductPrivTest($product, 'user10', array(), array(), $stakeholders)) && p() && e('1'); //传入产品、用户名、干系人、白名单,判断user10用户是否对此产品有权限 -r($user->checkProductPrivTest($product, 'user60', array(), array(), $stakeholders, array(), $whiteList)) && p() && e('0'); //传入产品、用户名、干系人、白名单,判断user60用户是否对此产品有权限 +r($user->checkProductPrivTest($product, 'user60', array(), array(), $stakeholders, $whiteList)) && p() && e('1'); //传入产品、用户名、干系人、白名单,判断user60用户是否对此产品有权限 +r($user->checkProductPrivTest($product, 'test6', array(), array(), $stakeholders, $whiteList, $admins)) && p() && e('1'); //传入产品、用户名、干系人、白名单, admins,判断test6用户是否对此产品有权限 + +$product->acl = 'open'; +r($user->checkProductPrivTest($product, 'test8')) && p() && e('1'); //传入公开产品,判断test6用户是否对此产品有权限 diff --git a/module/user/test/model/checkprogrampriv.php b/module/user/test/model/checkprogrampriv.php index f1b6aa2c43..b4d47e68d6 100755 --- a/module/user/test/model/checkprogrampriv.php +++ b/module/user/test/model/checkprogrampriv.php @@ -24,12 +24,19 @@ $program->id = 1; $program->name = '测试项目集'; $program->PM = 'test2'; $program->openedBy = 'pm1'; +$program->acl = 'private'; $stakeholders['user10'] = 'user10'; $whiteList['user60'] = 'user60'; +$admins['test6'] = 'test6'; -r($user->checkProgramPrivTest('', 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 -r($user->checkProgramPrivTest($program, 'test3')) && p() && e('0'); //传入项目集、用户名,判断test3用户是否对此项目集有权限 -r($user->checkProgramPrivTest($program, 'test2')) && p() && e('1'); //传入项目集、用户名,判断test2用户是否对此项目集有权限 -r($user->checkProgramPrivTest($program, 'user10', $stakeholders, array())) && p() && e('1'); //传入项目集、用户名、干系人、白名单,判断user10用户是否对此项目集有权限 -r($user->checkProgramPrivTest($program, 'user60', $stakeholders, $whiteList)) && p() && e('1'); //传入项目集、用户名、干系人、白名单,判断user60用户是否对此项目集有权限 \ No newline at end of file +$user->objectModel->app->company->admins = ',admin,'; +r($user->checkProgramPrivTest(new stdclass(), 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 +r($user->checkProgramPrivTest($program, 'test3')) && p() && e('0'); //传入项目集、用户名,判断test3用户是否对此项目集有权限 +r($user->checkProgramPrivTest($program, 'test2')) && p() && e('1'); //传入项目集、用户名,判断test2用户是否对此项目集有权限 +r($user->checkProgramPrivTest($program, 'user10', $stakeholders)) && p() && e('1'); //传入项目集、用户名、干系人、白名单,判断user10用户是否对此项目集有权限 +r($user->checkProgramPrivTest($program, 'user60', $stakeholders, $whiteList)) && p() && e('1'); //传入项目集、用户名、干系人、白名单,判断user60用户是否对此项目集有权限 +r($user->checkProgramPrivTest($program, 'test6', $stakeholders, $whiteList, $admins)) && p() && e('1'); //传入项目集、用户名、干系人、白名单,admins, 判断test6用户是否对此项目集有权限 + +$program->acl = 'open'; +r($user->checkProgramPrivTest($program, 'test10')) && p() && e('1'); //传入公开项目集,判断test10用户是否对此项目集有权限 diff --git a/module/user/test/model/checkprojectpriv.php b/module/user/test/model/checkprojectpriv.php index 4c51b2b621..90ea2bf8a2 100755 --- a/module/user/test/model/checkprojectpriv.php +++ b/module/user/test/model/checkprojectpriv.php @@ -24,12 +24,20 @@ $project->id = 10; $project->name = '测试项目'; $project->PM = 'test2'; $project->openedBy = 'pm1'; +$project->acl = 'private'; $stakeholders['user10'] = 'user10'; $whiteList['user60'] = 'user60'; +$admins['test6'] = 'test6'; -r($user->checkProjectPrivTest('', 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 -r($user->checkProjectPrivTest($project, 'test3')) && p() && e('0'); //传入项目、用户名,判断test3用户是否对此项目有权限 -r($user->checkProjectPrivTest($project, 'test2')) && p() && e('1'); //传入项目、用户名,判断test2用户是否对此项目有权限 -r($user->checkProjectPrivTest($project, 'user10', $stakeholders, array(), array())) && p() && e('1'); //传入项目、用户名、干系人、白名单,判断user10用户是否对此项目有权限 -r($user->checkProjectPrivTest($project, 'user60', $stakeholders, array(), $whiteList)) && p() && e('1'); //传入项目、用户名、干系人、白名单,判断user60用户是否对此项目有权限 \ No newline at end of file +$user->objectModel->app->company->admins = ',admin,'; + +r($user->checkProjectPrivTest(new stdclass(), 'admin')) && p() && e('1'); //传入admin,判断admin用户是否有权限 +r($user->checkProjectPrivTest($project, 'test3')) && p() && e('0'); //传入项目、用户名,判断test3用户是否对此项目有权限 +r($user->checkProjectPrivTest($project, 'test2')) && p() && e('1'); //传入项目、用户名,判断test2用户是否对此项目有权限 +r($user->checkProjectPrivTest($project, 'user10', $stakeholders, array(), array())) && p() && e('1'); //传入项目、用户名、干系人、白名单,判断user10用户是否对此项目有权限 +r($user->checkProjectPrivTest($project, 'user60', $stakeholders, array(), $whiteList)) && p() && e('1'); //传入项目、用户名、干系人、白名单,判断user60用户是否对此项目有权限 +r($user->checkProjectPrivTest($project, 'test6', $stakeholders, array(), array(), $admins)) && p() && e('1'); //传入项目、用户名、admins,判断test6用户是否对此项目有权限 + +$project->acl = 'open'; +r($user->checkProjectPrivTest($project, 'test8')) && p() && e('1'); //传入公开项目,判断test8用户是否对此项目有权限 diff --git a/module/user/test/model/getprogramauthedusers.php b/module/user/test/model/getprogramauthedusers.php index 029fbbef56..5c2ebe223b 100755 --- a/module/user/test/model/getprogramauthedusers.php +++ b/module/user/test/model/getprogramauthedusers.php @@ -2,7 +2,11 @@ gen(10, 'program'); + +$project = zdTable('project'); +$project->type->range('program'); +$project->PM->range('user1'); +$project->gen(10); zdTable('user')->gen(200); su('admin'); @@ -12,7 +16,7 @@ title=测试 userModel->getProgramAuthedUsers(); cid=1 pid=1 -获取对ID为1的项目集有权限的用户数量 >> 7 +获取对ID为1的项目集有权限的用户数量 >> 8 获取对ID为1的项目集有权限的用户 >> test9 获取对ID为1的项目集有权限的用户 >> admin 获取对ID为2的项目集有权限的用户 >> astaw @@ -30,8 +34,10 @@ $whiteList['astaw'] = 'astaw'; $admins['test20'] = 'test20'; $admins['test21'] = 'test21'; -r(count($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array()))) && p() && e('7'); //获取对ID为1的项目集有权限的用户数量 -r($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array())) && p('test9') && e('test9'); //获取对ID为1的项目集有权限的用户 -r($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array())) && p('admin') && e('admin'); //获取对ID为1的项目集有权限的用户 -r($user->getProgramAuthedUsersTest(2, $stakeholders, $whiteList, array())) && p('astaw') && e('astaw'); //获取对ID为2的项目集有权限的用户 +$user->objectModel->app->company->admins = ',admin,'; + +r(count($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array()))) && p() && e('6'); //获取对ID为1的项目集有权限的用户数量 +r($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array())) && p('test9') && e('test9'); //获取对ID为1的项目集有权限的用户 +r($user->getProgramAuthedUsersTest(1, $stakeholders, $whiteList, array())) && p('admin') && e('admin'); //获取对ID为1的项目集有权限的用户 +r($user->getProgramAuthedUsersTest(2, $stakeholders, $whiteList, array())) && p('astaw') && e('astaw'); //获取对ID为2的项目集有权限的用户 r($user->getProgramAuthedUsersTest(2, $stakeholders, $whiteList, $admins)) && p('test21') && e('test21'); //获取对ID为2的项目集有权限的用户 diff --git a/module/user/test/model/getprojectauthedusers.php b/module/user/test/model/getprojectauthedusers.php index 139fab170c..2f8d817dd1 100755 --- a/module/user/test/model/getprojectauthedusers.php +++ b/module/user/test/model/getprojectauthedusers.php @@ -2,8 +2,12 @@ gen(10); -zdTable('user')->gen(200); + +$project = zdTable('project'); +$project->type->range('project'); +$project->PM->range('user1'); +$project->gen(10); +zdTable('user')->gen(100); su('admin'); /** @@ -29,6 +33,8 @@ $whiteList['user35'] = 'user35'; $whiteList['user35'] = 'user35'; $whiteList['astaw'] = 'astaw'; +$user->objectModel->app->company->admins = ',admin,'; + r($user->getProjectAuthedUsersTest(1, $stakeholders, $teams, $whiteList)) && p('test9') && e('test9'); //获取对ID为1的产品有权限的用户 r($user->getProjectAuthedUsersTest(1, $stakeholders, $teams, $whiteList)) && p('admin') && e('admin'); //获取对ID为1的产品有权限的用户 r($user->getProjectAuthedUsersTest(2, $stakeholders, $teams, $whiteList)) && p('astaw') && e('astaw'); //获取对ID为2的产品有权限的用户 diff --git a/module/user/test/model/getsprintauthedusers.php b/module/user/test/model/getsprintauthedusers.php index 37c5d8b528..b1fa916140 100755 --- a/module/user/test/model/getsprintauthedusers.php +++ b/module/user/test/model/getsprintauthedusers.php @@ -2,10 +2,14 @@ gen(300, 'execution'); -zdTable('user')->gen(200); su('admin'); +$project = zdTable('project'); +$project->type->range('sprint'); +$project->PM->range('user1'); +$project->gen(10); +zdTable('user')->gen(100); + /** title=测试 userModel->getSprintAuthedUsers(); @@ -32,7 +36,9 @@ $whiteList['astaw'] = 'astaw'; $admins['test20'] = 'test20'; $admins['test21'] = 'test21'; -r($user->getSprintAuthedUsersTest(101, $stakeholders, $teams, $whiteList, array())) && p('test9') && e('test9'); //获取对ID为101的执行有权限的用户 -r($user->getSprintAuthedUsersTest(101, $stakeholders, $teams, $whiteList, array())) && p('admin') && e('admin'); //获取对ID为101的执行有权限的用户 -r($user->getSprintAuthedUsersTest(201, $stakeholders, $teams, $whiteList, array())) && p('astaw') && e('astaw'); //获取对ID为201的执行有权限的用户 -r($user->getSprintAuthedUsersTest(201, $stakeholders, $teams, $whiteList, $admins)) && p('test21') && e('test21'); //获取对ID为201的执行有权限的用户 \ No newline at end of file +$user->objectModel->app->company->admins = ',admin,'; + +r($user->getSprintAuthedUsersTest(1, $stakeholders, $teams, $whiteList, array())) && p('test9') && e('test9'); //获取对ID为101的执行有权限的用户 +r($user->getSprintAuthedUsersTest(1, $stakeholders, $teams, $whiteList, array())) && p('admin') && e('admin'); //获取对ID为101的执行有权限的用户 +r($user->getSprintAuthedUsersTest(2, $stakeholders, $teams, $whiteList, array())) && p('astaw') && e('astaw'); //获取对ID为201的执行有权限的用户 +r($user->getSprintAuthedUsersTest(2, $stakeholders, $teams, $whiteList, $admins)) && p('test21') && e('test21'); //获取对ID为201的执行有权限的用户 diff --git a/module/user/test/user.class.php b/module/user/test/user.class.php index 2d562ddf00..5dd9af51e9 100755 --- a/module/user/test/user.class.php +++ b/module/user/test/user.class.php @@ -804,12 +804,13 @@ class userTest * @param string $account * @param array $stakeholders * @param array $whiteList + * @param array $admins * @access public - * @return void + * @return bool */ - public function checkProgramPrivTest($program, $account, $stakeholders, $whiteList) + public function checkProgramPrivTest(object $program, string $account, array $stakeholders = array(), array $whiteList = array(), array $admins = array()): bool { - return $this->objectModel->checkProgramPriv($program, $account, $stakeholders, $whiteList); + return $this->objectModel->checkProgramPriv($program, $account, $stakeholders, $whiteList, $admins); } /** @@ -823,9 +824,9 @@ class userTest * @access public * @return void */ - public function checkProjectPrivTest($project, $account, $stakeholders, $teams, $whiteList) + public function checkProjectPrivTest(object $project, string $account, array $stakeholders = array(), array $teams = array(), array $whiteList = array(), array $admins = array()): bool { - return $this->objectModel->checkProjectPriv($project, $account, $stakeholders, $teams, $whiteList); + return $this->objectModel->checkProjectPriv($project, $account, $stakeholders, $teams, $whiteList, $admins); } /** * Test check sprint priv. @@ -851,12 +852,13 @@ class userTest * @param array $teams * @param array $stakeholders * @param array $whiteList + * @param array $admins * @access public - * @return void + * @return bool */ - public function checkProductPrivTest($product, $account, $groups = '', $teams = '', $stakeholders = '', $whiteList = '') + public function checkProductPrivTest(object $product, string $account, array $groups = array(), array $teams = array(), array $stakeholders = array(), array $whiteList = array(), array $admins = array()): bool { - return $this->objectModel->checkProductPriv($product, $account, $groups, $teams, $stakeholders, $whiteList); + return $this->objectModel->checkProductPriv($product, $account, $groups, $teams, $stakeholders, $whiteList, $admins); } /** @@ -884,9 +886,9 @@ class userTest * @param array $whiteList * @param array $admins * @access public - * @return void + * @return array */ - public function getProgramAuthedUsersTest($programID, $stakeholders, $whiteList, $admins) + public function getProgramAuthedUsersTest(int $programID, array $stakeholders, array $whiteList, array $admins): array { global $tester; $program = $tester->loadModel('program')->getByID($programID); diff --git a/test/data/acl.yaml b/test/data/acl.yaml new file mode 100644 index 0000000000..8690ae8cd9 --- /dev/null +++ b/test/data/acl.yaml @@ -0,0 +1,24 @@ +title: table zt_acl +desc: "联系人" +author: automated export +version: "1.0" +fields: + - field: id + range: 1-10000 + - field: account + note: "用户名" + fields: + - field: account1 + range: admin,user{99},test{100},dev{100},pm{100},po{100},td{100},pd{100},qd{100},top{100},outside{100},others{100},a,bb,ccc,qwuiadsd?!2as@#%$aasd~aj1!@#1 + - field: account2 + range: "[],1-99,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,[]{4}" + - field: objectType + note: "对象类型" + range: program,product,project,sprint + - field: objectID + note: "对象ID" + range: "1-10" + - field: type + range: "whitelist" + - field: source + range: upgrade,add,sync diff --git a/test/data/projectadmin.yaml b/test/data/projectadmin.yaml new file mode 100644 index 0000000000..98b0aeb587 --- /dev/null +++ b/test/data/projectadmin.yaml @@ -0,0 +1,22 @@ +title: table zt_projectadmin +desc: "" +author: automated export +version: "1.0" +fields: + - field: group + range: '1-9' + - field: account + note: "用户名" + fields: + - field: account1 + range: admin,user{99},test{100},dev{100},pm{100},po{100},td{100},pd{100},qd{100},top{100},outside{100},others{100},a,bb,ccc,qwuiadsd?!2as@#%$aasd~aj1!@#1 + - field: account2 + range: "[],1-99,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,1-100,[]{4}" + - field: programs + range: 'all,1-5' + - field: projects + range: 'all,6-15' + - field: products + range: 'all,1-20' + - field: executions + range: 'all,16-30'