From 45040819aea1c762af10c41fc4d44ffbb4496e4d Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Mon, 29 Nov 2021 14:00:06 +0800 Subject: [PATCH] * Finish task 45049. --- module/bug/model.php | 27 ++-- "module/group/\\" | 354 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 372 insertions(+), 9 deletions(-) create mode 100644 "module/group/\\" diff --git a/module/bug/model.php b/module/bug/model.php index 25e9413ddf..d40d4f4a75 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1179,7 +1179,21 @@ class bugModel extends model */ public function activate($bugID) { + $bugID = (int)$bugID; $oldBug = $this->getById($bugID); + $builds = $this->dao->select('id,bugs') + ->from(TABLE_BUILD) + ->where('bugs')->like("%$bugID%") + ->fetchPairs('id', 'bugs'); + foreach($builds as $buildID => $buildBugs) + { + $bugList = explode(',', $buildBugs); + if(in_array($bugID, $bugList)) + { + $solveBuild = $buildID; + continue; + } + } $now = helper::now(); $bug = fixer::input('post') ->setDefault('assignedTo', $oldBug->resolvedBy) @@ -1205,17 +1219,12 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); - $openedBuilds = explode(',', $oldBug->openedBuild); - if($openedBuilds) + if($solveBuild) { $this->loadModel('build'); - foreach($openedBuilds as $openedBuild) - { - $build = $this->build->getByID($openedBuild); - if(empty($build)) continue; - $build->bugs = trim(str_replace(",$bugID,", ',', ",$build->bugs,"), ','); - $this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$openedBuild)->exec(); - } + $build = $this->build->getByID($solveBuild); + $build->bugs = trim(str_replace(",$bugID,", ',', ",$build->bugs,"), ','); + $this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$solveBuild)->exec(); } $bug->activatedCount += 1; diff --git "a/module/group/\\" "b/module/group/\\" new file mode 100644 index 0000000000..ebccd3f3ef --- /dev/null +++ "b/module/group/\\" @@ -0,0 +1,354 @@ + + * @package group + * @version $Id: control.php 4648 2013-04-15 02:45:49Z chencongzhi520@gmail.com $ + * @link http://www.zentao.net + */ +class group extends control +{ + /** + * Construct function. + * + * @access public + * @return void + */ + public function __construct($moduleName = '', $methodName = '') + { + parent::__construct($moduleName, $methodName); + $this->loadModel('company')->setMenu(); + $this->loadModel('user'); + } + + /** + * Browse groups. + * + * @access public + * @return void + */ + public function browse() + { + $title = $this->lang->company->orgView . $this->lang->colon . $this->lang->group->browse; + $position[] = $this->lang->group->browse; + + $groups = $this->group->getList(); + $groupUsers = array(); + foreach($groups as $group) $groupUsers[$group->id] = $this->group->getUserPairs($group->id); + + $this->view->title = $title; + $this->view->position = $position; + $this->view->groups = $groups; + $this->view->groupUsers = $groupUsers; + + $this->display(); + } + + /** + * Create a group. + * + * @access public + * @return void + */ + public function create() + { + if(!empty($_POST)) + { + $groupID = $this->group->create(); + if(dao::isError()) die(js::error(dao::getError())); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $groupID)); + if(isonlybody()) die(js::closeModal('parent.parent', 'this')); + die(js::locate($this->createLink('group', 'browse'), 'parent')); + } + + $this->view->title = $this->lang->company->orgView . $this->lang->colon . $this->lang->group->create; + $this->view->position[] = $this->lang->group->create; + $this->display(); + } + + /** + * Edit a group. + * + * @param int $groupID + * @access public + * @return void + */ + public function edit($groupID) + { + if(!empty($_POST)) + { + $this->group->update($groupID); + if(isonlybody()) die(js::closeModal('parent.parent', 'this')); + die(js::locate($this->createLink('group', 'browse'), 'parent')); + } + + $title = $this->lang->company->orgView . $this->lang->colon . $this->lang->group->edit; + $position[] = $this->lang->group->edit; + + $this->view->title = $title; + $this->view->position = $position; + $this->view->group = $this->group->getById($groupID); + + $this->display(); + } + + /** + * Copy a group. + * + * @param int $groupID + * @access public + * @return void + */ + public function copy($groupID) + { + if(!empty($_POST)) + { + $this->group->copy($groupID); + if(dao::isError()) die(js::error(dao::getError())); + if(isonlybody()) die(js::closeModal('parent.parent', 'this')); + die(js::locate($this->createLink('group', 'browse'), 'parent')); + } + + $this->view->title = $this->lang->company->orgView . $this->lang->colon . $this->lang->group->copy; + $this->view->position[] = $this->lang->group->copy; + $this->view->group = $this->group->getById($groupID); + $this->display(); + } + + /** + * Manage view. + * + * @param int $groupID + * @access public + * @return void + */ + public function manageView($groupID) + { + if($_POST) + { + $this->group->updateView($groupID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $link = isonlybody() ? 'parent' : $this->createLink('group', 'browse'); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); + } + + /* Get the group data by id. */ + $group = $this->group->getByID($groupID); + $this->view->title = $this->lang->company->common . $this->lang->colon . $group->name . $this->lang->colon . $this->lang->group->manageView; + + $this->view->group = $group; + $this->view->programs = $this->loadModel('program')->getPairs(true, 'order_desc'); + $this->view->projects = $this->loadModel('project')->getPairsByProgram(0, 'all', true, 'order_desc'); + $this->view->executions = $this->loadModel('execution')->getPairs(0, 'all', 'all'); + $this->view->products = $this->loadModel('product')->getPairs(); + + $navGroup = array(); + foreach($this->lang->navGroup as $moduleName => $groupName) + { + if($groupName == $moduleName) continue; + if($moduleName == 'testcase') $moduleName = 'case'; + + $navGroup[$groupName][$moduleName] = $moduleName; + } + $this->view->navGroup = $navGroup; + + $this->display(); + } + + /** + * Manage privleges of a group. + * + * @param int $groupID + * @access public + * @return void + */ + public function managePriv($type = 'byGroup', $param = 0, $menu = '', $version = '') + { + if($type == 'byGroup') $groupID = $param; + $this->view->type = $type; + foreach($this->lang->resource as $moduleName => $action) + { + if($this->group->checkMenuModule($menu, $moduleName) or $type != 'byGroup') $this->app->loadLang($moduleName); + } + + if(!empty($_POST)) + { + if($type == 'byGroup') $result = $this->group->updatePrivByGroup($groupID, $menu, $version); + if($type == 'byModule') $result = $this->group->updatePrivByModule(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + } + + if($type == 'byGroup') + { + $this->group->sortResource(); + $group = $this->group->getById($groupID); + $groupPrivs = $this->group->getPrivs($groupID); + + if($this->config->systemMode == 'classic') + { + if(isset($groupPrivs['project']['browse'])) + { + $groupPrivs['project']['list'] = 'list'; + } + } + + $this->view->title = $this->lang->company->common . $this->lang->colon . $group->name . $this->lang->colon . $this->lang->group->managePriv; + $this->view->position[] = $group->name; + $this->view->position[] = $this->lang->group->managePriv; + + /* Join changelog when be equal or greater than this version.*/ + $realVersion = str_replace('_', '.', $version); + $changelog = array(); + foreach($this->lang->changelog as $currentVersion => $currentChangeLog) + { + if(version_compare($currentVersion, $realVersion, '>=')) $changelog[] = join(',', $currentChangeLog); + } + + $this->view->group = $group; + $this->view->changelogs = ',' . join(',', $changelog) . ','; + $this->view->groupPrivs = $groupPrivs; + a($groupPrivs); + $this->view->groupID = $groupID; + $this->view->menu = $menu; + $this->view->version = $version; + } + elseif($type == 'byModule') + { + $this->group->sortResource(); + $this->view->title = $this->lang->company->common . $this->lang->colon . $this->lang->group->managePriv; + $this->view->position[] = $this->lang->group->managePriv; + + foreach($this->lang->resource as $module => $moduleActions) + { + $modules[$module] = $this->lang->$module->common; + foreach($moduleActions as $action) + { + $actions[$module][$action] = $this->lang->$module->$action; + } + } + $this->view->groups = $this->group->getPairs(); + $this->view->modules = $modules; + $this->view->actions = $actions; + } + $this->display(); + } + + /** + * Manage members of a group. + * + * @param int $groupID + * @param int $deptID + * @access public + * @return void + */ + public function manageMember($groupID, $deptID = 0) + { + if(!empty($_POST)) + { + $this->group->updateUser($groupID); + if(isonlybody()) die(js::closeModal('parent.parent', 'this')); + die(js::locate($this->createLink('group', 'browse'), 'parent')); + } + $group = $this->group->getById($groupID); + $groupUsers = $this->group->getUserPairs($groupID); + $allUsers = $this->loadModel('dept')->getDeptUserPairs($deptID); + $otherUsers = array_diff_assoc($allUsers, $groupUsers); + + if($this->config->systemMode == 'new') + { + $outsideUsers = $this->user->getPairs('outside|noclosed|noletter|noempty'); + $this->view->outsideUsers = array_diff_assoc($outsideUsers, $groupUsers); + } + + $title = $this->lang->company->common . $this->lang->colon . $group->name . $this->lang->colon . $this->lang->group->manageMember; + $position[] = $group->name; + $position[] = $this->lang->group->manageMember; + + $this->view->title = $title; + $this->view->position = $position; + $this->view->group = $group; + $this->view->deptTree = $this->loadModel('dept')->getTreeMenu($rooteDeptID = 0, array('deptModel', 'createGroupManageMemberLink'), $groupID); + $this->view->groupUsers = $groupUsers; + $this->view->otherUsers = $otherUsers; + $this->display(); + } + + /** + * Manage members of a group. + * + * @param int $groupID + * @param int $deptID + * @access public + * @return void + */ + public function manageProjectAdmin($groupID, $deptID = 0) + { + if(!empty($_POST)) + { + $this->group->updateProjectAdmin($groupID); + die(js::locate(inlink('manageProjectAdmin', "group=$groupID"), 'parent')); + } + $group = $this->group->getById($groupID); + $groupUsers = $this->group->getUserPairs($groupID); + $userPrograms = $this->group->getUserPrograms($groupID); + $allUsers = array('' => '') + $groupUsers + $this->loadModel('dept')->getDeptUserPairs($deptID); + + $title = $this->lang->company->common . $this->lang->colon . $group->name . $this->lang->colon . $this->lang->group->manageMember; + $position[] = $group->name; + $position[] = $this->lang->group->manageMember; + + $this->view->title = $title; + $this->view->position = $position; + $this->view->allUsers = $allUsers; + $this->view->group = $group; + $this->view->programs = $this->dao->select('id, name')->from(TABLE_PROJECT)->where('type')->eq('project')->andWhere('deleted')->eq(0)->fetchPairs(); + $this->view->deptTree = $this->loadModel('dept')->getTreeMenu($rooteDeptID = 0, array('deptModel', 'createManageProjectAdminLink'), $groupID); + $this->view->groupUsers = $groupUsers; + $this->view->userPrograms = $userPrograms; + + $this->display(); + } + + /** + * Delete a group. + * + * @param int $groupID + * @param string $confirm yes|no + * @access public + * @return void + */ + public function delete($groupID, $confirm = 'no') + { + if($confirm == 'no') + { + die(js::confirm($this->lang->group->confirmDelete, $this->createLink('group', 'delete', "groupID=$groupID&confirm=yes"))); + } + else + { + $this->group->delete($groupID); + + /* if ajax request, send result. */ + if($this->server->ajax) + { + if(dao::isError()) + { + $response['result'] = 'fail'; + $response['message'] = dao::getError(); + } + else + { + $response['result'] = 'success'; + $response['message'] = ''; + } + return $this->send($response); + } + die(js::locate($this->createLink('group', 'browse'), 'parent')); + } + } +}