diff --git a/module/execution/control.php b/module/execution/control.php index 4407eec27e..55536cf8a6 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -2963,6 +2963,7 @@ class execution extends control } /** + * 移除团队成员。 * Unlink a memeber. * * @param int $executionID @@ -2970,27 +2971,15 @@ class execution extends control * @access public * @return void */ - public function unlinkMember($executionID, $userID) + public function unlinkMember(int $executionID, int $userID) { - $user = $this->loadModel('user')->getById($userID, 'id'); - $account = $user->account; + $user = $this->loadModel('user')->getById($userID, 'id'); + $this->execution->unlinkMember($executionID, $user->account); - $this->execution->unlinkMember($executionID, $account); - if(!dao::isError()) $this->loadModel('action')->create('team', $executionID, 'managedTeam'); + if(dao::isError()) return $this->sendError(dao::getError()); - /* if ajax request, send result. */ - if(dao::isError()) - { - $response['result'] = 'fail'; - $response['message'] = dao::getError(); - } - else - { - $response['result'] = 'success'; - $response['message'] = ''; - $response['load'] = helper::createLink('execution', 'team', "executionID={$executionID}"); - } - return $this->send($response); + $this->loadModel('action')->create('team', $executionID, 'managedTeam'); + return $this->sendSuccess(array('message' => '', 'load' => helper::createLink('execution', 'team', "executionID={$executionID}"))); } /** diff --git a/module/execution/model.php b/module/execution/model.php index 4a2a631627..4a1fd8bada 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3725,35 +3725,41 @@ class executionModel extends model } /** - * Unlink a member. + * 移除执行团队成员。 + * Remove the user from the execution team members. * - * @param int $sprintID + * @param int $executionID * @param string $account * @access public * @return void */ - public function unlinkMember($sprintID, $account) + public function unlinkMember(int $executionID, string $account) { - $sprint = $this->getByID($sprintID); - $type = strpos(',stage,sprint,kanban,', ",$sprint->type,") !== false ? 'execution' : $sprint->type; + /* Remove the user from the execution team members. */ + $execution = $this->getByID($executionID); + $type = strpos(',stage,sprint,kanban,', ",$execution->type,") !== false ? 'execution' : $execution->type; + $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($type)->andWhere('account')->eq($account)->exec(); - $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq((int)$sprintID)->andWhere('type')->eq($type)->andWhere('account')->eq($account)->exec(); - $this->updateUserView($sprintID, 'sprint', array($account)); + /* Update the user's execution permission. */ + $this->updateUserView($executionID, 'sprint', array($account)); - /* Remove team members from the sprint or stage, and determine whether to remove team members from the execution. */ - if(strpos(',stage,sprint,kanban,', ",$sprint->type,") !== false) + /* Remove team members from the sprint or stage, and determine whether to remove team members from the project. */ + if(strpos(',stage,sprint,kanban,', ",$execution->type,") !== false) { $teamMember = $this->dao->select('t1.id, t2.account')->from(TABLE_EXECUTION)->alias('t1') ->leftJoin(TABLE_TEAM)->alias('t2')->on('t1.id = t2.root') - ->where('t1.project')->eq($sprint->project) - ->andWhere('t1.type')->eq($sprint->type) + ->where('t1.project')->eq($execution->project) + ->andWhere('t1.type')->eq($execution->type) ->andWhere('t2.account')->eq($account) ->fetch(); + + /* Remove the user from the project team members and update the user's product permission. */ if(empty($teamMember)) { - $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($sprint->project)->andWhere('type')->eq('project')->andWhere('account')->eq($account)->exec(); - $this->loadModel('user')->updateUserView($sprint->project, 'project', array($account)); - $linkedProducts = $this->loadModel('product')->getProductPairsByProject($sprint->project); + $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($execution->project)->andWhere('type')->eq('project')->andWhere('account')->eq($account)->exec(); + $this->loadModel('user')->updateUserView($execution->project, 'project', array($account)); + + $linkedProducts = $this->loadModel('product')->getProductPairsByProject($execution->project); if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', array($account)); } } diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index 28d3df49df..ff32927a3a 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -1799,29 +1799,30 @@ class executionTest } /** - * function unlinkMember test by execution + * 移除执行团队成员。 + * Remove the user from the execution team members. * - * @param string $sprintID - * @param string $account - * @param string $count + * @param int $executionID + * @param string $account + * @param int $count * @access public - * @return array + * @return array|object|int */ - public function unlinkMemberTest($sprintID, $account, $count) + public function unlinkMemberTest(int $executionID, string $account, int $count): array|object|int { global $tester; - $oldObject = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($sprintID)->fetchAll(); + $oldObject = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll(); - $this->executionModel->unlinkMember($sprintID, $account); + $this->executionModel->unlinkMember($executionID, $account); - $object = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($sprintID)->fetchAll(); + $object = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll(); if(dao::isError()) { $error = dao::getError(); return $error; } - elseif($count == "1") + elseif($count == 1) { return count($oldObject); } diff --git a/module/execution/test/model/unlinkmember.php b/module/execution/test/model/unlinkmember.php index bd469417ce..1c61b10318 100755 --- a/module/execution/test/model/unlinkmember.php +++ b/module/execution/test/model/unlinkmember.php @@ -29,20 +29,14 @@ su('admin'); /** title=测试executionModel->unlinkMember(); +timeout=0 cid=1 -pid=1 - -敏捷执行解除团队成员 >> user4,测试 -敏捷执行解除团队成员后统计 >> 1 -瀑布执行解除团队成员 >> user2,研发 -看板执行解除团队成员 >> 0 -看板执行解除团队成员后统计 >> 0 */ $accountList = array('user1', 'user2', 'user3'); $executionIDList = array('3', '4', '5'); -$count = array('0','1'); +$count = array(0, 1); $execution = new executionTest(); r($execution->unlinkMemberTest($executionIDList[0], $accountList[0], $count[0])) && p('0:account,role') && e('user4,测试'); // 敏捷执行解除团队成员