From 0909592ea14a351d9cdb920f7af1e187ded4a622 Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Wed, 28 Oct 2020 09:14:38 +0800 Subject: [PATCH] * Adjust whitelist setting logic. --- module/group/model.php | 12 +++++++++++ module/personnel/model.php | 10 ++++----- module/product/js/common.js | 6 ++++++ module/product/view/create.html.php | 4 ++-- module/product/view/edit.html.php | 2 +- module/program/js/common.js | 5 +++++ module/program/model.php | 4 +++- module/program/view/pgmcreate.html.php | 8 ++++---- module/program/view/pgmedit.html.php | 6 +++--- module/program/view/prjcreate.html.php | 8 ++++---- module/program/view/prjedit.html.php | 8 ++++---- module/project/js/common.js | 10 ++++----- module/project/view/create.html.php | 4 ++-- module/project/view/edit.html.php | 2 +- module/upgrade/model.php | 28 ++++++++++++++++++-------- module/user/model.php | 26 ++++++++++++++---------- 16 files changed, 92 insertions(+), 51 deletions(-) diff --git a/module/group/model.php b/module/group/model.php index 77957ec4e1..b43ca08b6a 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -153,6 +153,18 @@ class groupModel extends model ->fetchAll('id'); } + /** + * Get the account number in the group. + * + * @param int $groupID + * @access public + * @return array + */ + public function getGroupAccounts($groupID = 0) + { + return $this->dao->select('account')->from(TABLE_USERGROUP)->where('group')->eq($groupIdList)->fetchPairs('account'); + } + /** * Get privileges of a groups. * diff --git a/module/personnel/model.php b/module/personnel/model.php index 5c565ca449..4751dc8232 100644 --- a/module/personnel/model.php +++ b/module/personnel/model.php @@ -237,11 +237,10 @@ class personnelModel extends model * @param int $objectID * @param string $type whitelist|blacklist * @param string $source upgrade|add|sync - * @param string $desc * @access public * @return void */ - public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add', $desc = '') + public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add') { $oldWhitelist = $this->dao->select('account,objectType,objectID,type,source,`desc`')->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->fetchAll('account'); $this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->exec(); @@ -265,7 +264,6 @@ class personnelModel extends model $acl->objectID = $objectID; $acl->type = $type; $acl->source = $source; - $acl->desc = $desc; $this->dao->insert(TABLE_ACL)->data($acl)->autoCheck()->exec(); $accounts[$account] = $account; } @@ -286,7 +284,8 @@ class personnelModel extends model $product = $this->loadModel('product')->getById($objectID); $programWhitelist = $this->getWhitelistAccount($product->program, 'program'); $newWhitelist = array_merge($programWhitelist, $accounts); - $this->updateWhitelist($newWhitelist, 'program', $product->program, 'whitelist', 'sync', 'From product synchronization to program set.'); + $source = $source == 'upgrade' ? 'upgrade' : 'sync'; + $this->updateWhitelist($newWhitelist, 'program', $product->program, 'whitelist', $source); /* Removal of persons from centralized program whitelisting. */ foreach($deletedAccouns as $account) $this->deleteProgramWhitelist($objectID, $account); @@ -298,7 +297,8 @@ class personnelModel extends model $project = $this->dao->select('project')->from(TABLE_PROJECT)->where('id')->eq($objectID)->fetch('project', ''); $projectWhitelist = $this->getWhitelistAccount($project, 'project'); $newWhitelist = array_merge($projectWhitelist, $accounts); - $this->updateWhitelist($newWhitelist, 'project', $project, 'whitelist', 'sync', 'From sprint synchronization to project.'); + $source = $source == 'upgrade' ? 'upgrade' : 'sync'; + $this->updateWhitelist($newWhitelist, 'project', $project, 'whitelist', $source); /* Removal of whitelisted persons from projects. */ foreach($deletedAccouns as $account) $this->deleteProjectWhitelist($objectID, $account); diff --git a/module/product/js/common.js b/module/product/js/common.js index f00761711c..42308b3fae 100644 --- a/module/product/js/common.js +++ b/module/product/js/common.js @@ -2,3 +2,9 @@ $(document).ready(function() { if(window.noProject) $('#aclprivate').parents('.radio').remove(); }) + +function setWhite(acl) +{ + acl != 'open' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); +} + diff --git a/module/product/view/create.html.php b/module/product/view/create.html.php index 841f691f3c..77c4bbadea 100644 --- a/module/product/view/create.html.php +++ b/module/product/view/create.html.php @@ -67,12 +67,12 @@ fetch('user', 'ajaxPrintTemplates', "type=product&link=desc");?> - + product->acl;?> product->aclList, 'open', "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> diff --git a/module/product/view/edit.html.php b/module/product/view/edit.html.php index 4ad146bc52..e9faf3d97c 100644 --- a/module/product/view/edit.html.php +++ b/module/product/view/edit.html.php @@ -66,7 +66,7 @@ product->acl;?> product->aclList, $product->acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> whitelist, 'class="form-control chosen" multiple');?> diff --git a/module/program/js/common.js b/module/program/js/common.js index dd40c69c0a..92f22064b6 100644 --- a/module/program/js/common.js +++ b/module/program/js/common.js @@ -4,6 +4,11 @@ function setProgramType(type) location.href = location.href; } +function setWhite(acl) +{ + acl != 'open' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); +} + /** * Convert a date string like 2011-11-11 to date object in js. * diff --git a/module/program/model.php b/module/program/model.php index 56fdc2ca05..9a3d07fd57 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -244,11 +244,13 @@ class programModel extends model ->setDefault('end', '') ->setDefault('parent', 0) ->setDefault('openedDate', helper::now()) + ->setIF($this->post->acl == 'open', 'whitelist', '') ->add('type', 'program') ->join('whitelist', ',') ->cleanInt('budget') ->stripTags($this->config->program->editor->pgmcreate['id'], $this->config->allowedTags) ->get(); + $whitelist = explode(',', $program->whitelist); if($program->parent) { @@ -281,7 +283,7 @@ class programModel extends model $programID = $this->dao->lastInsertId(); $this->dao->update(TABLE_PROGRAM)->set('`order`')->eq($programID * 5)->where('id')->eq($programID)->exec(); // Save order. - $this->loadModel('personnel')->updateWhitelist($this->post->whitelist, 'program', $programID); + $this->loadModel('personnel')->updateWhitelist($whitelist, 'program', $programID); if($program->acl != 'open') $this->loadModel('user')->updateUserView($programID, 'program'); $this->file->updateObjectID($this->post->uid, $programID, 'project'); diff --git a/module/program/view/pgmcreate.html.php b/module/program/view/pgmcreate.html.php index b9c8f38d70..61c233b5c5 100644 --- a/module/program/view/pgmcreate.html.php +++ b/module/program/view/pgmcreate.html.php @@ -101,9 +101,9 @@ project->acl;?> - program->PGMAclList, 'open', '', 'block'));?> + program->PGMAclList, 'open', "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> @@ -148,10 +148,10 @@ id) ? $parentProgram->id : 0);?> diff --git a/module/program/view/pgmedit.html.php b/module/program/view/pgmedit.html.php index cf1d8a6442..42165525f2 100644 --- a/module/program/view/pgmedit.html.php +++ b/module/program/view/pgmedit.html.php @@ -73,7 +73,7 @@ project->acl;?> acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> whitelist, 'class="form-control chosen" multiple');?> @@ -90,9 +90,9 @@ diff --git a/module/program/view/prjcreate.html.php b/module/program/view/prjcreate.html.php index 5cc62a90ff..b8b327b7bc 100644 --- a/module/program/view/prjcreate.html.php +++ b/module/program/view/prjcreate.html.php @@ -117,9 +117,9 @@ project->acl;?> - program->PRJAclList, $acl, '', 'block'));?> + program->PRJAclList, $acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> @@ -167,9 +167,9 @@ diff --git a/module/program/view/prjedit.html.php b/module/program/view/prjedit.html.php index 580e7ae750..4472701e29 100644 --- a/module/program/view/prjedit.html.php +++ b/module/program/view/prjedit.html.php @@ -116,9 +116,9 @@ project->acl;?> - acl, '', 'block'));?> + acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> whitelist, 'class="form-control chosen" multiple');?> @@ -138,9 +138,9 @@ diff --git a/module/project/js/common.js b/module/project/js/common.js index 2d953b531c..1b773fe56f 100644 --- a/module/project/js/common.js +++ b/module/project/js/common.js @@ -1,13 +1,13 @@ -function setWhite(acl) -{ - acl == 'custom' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); -} - function switchStatus(projectID, status) { if(status) location.href = createLink('project', 'task', 'project=' + projectID + '&type=' + status); } +function setWhite(acl) +{ + acl != 'open' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); +} + function switchGroup(projectID, groupBy) { link = createLink('project', 'groupTask', 'project=' + projectID + '&groupBy=' + groupBy); diff --git a/module/project/view/create.html.php b/module/project/view/create.html.php index 7fa068e9ed..8715cb8e25 100644 --- a/module/project/view/create.html.php +++ b/module/project/view/create.html.php @@ -147,9 +147,9 @@ project->acl;?> - project->aclList, $acl, '', 'block'));?> + project->aclList, $acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> diff --git a/module/project/view/edit.html.php b/module/project/view/edit.html.php index adbbd66fc9..a528248d0c 100644 --- a/module/project/view/edit.html.php +++ b/module/project/view/edit.html.php @@ -150,7 +150,7 @@ project->acl;?> project->aclList, $project->acl, "onclick='setWhite(this.value);'", 'block'));?> - + whitelist;?> whitelist, 'class="form-control chosen" multiple');?> diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 08b73f46f9..b55c5f1888 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -4051,24 +4051,36 @@ class upgradeModel extends model $whiteList = array_diff($whiteList, $teams); /* Get all white list in sprint and product. */ - $groups = array(); + $this->loadModel('group'); + $this->loadModel('personnel'); foreach($products as $product) { if($product->acl != 'custom' || $product->whitelist) return; - $groups += explode(',', $product->whitelist); + $groups = explode(',', $product->whitelist); + $whitelist = $this->group->getGroupAccounts($groups); + $this->personnel->updateWhitelist($whitelist, 'product', $product->id, 'whitelist', 'upgrade'); + $this->personnel->updateWhitelist($whitelist, 'project', $projectID, 'whitelist', 'upgrade'); } foreach($sprints as $sprint) { if($sprint->acl != 'custom' || $sprint->whitelist) return; - $groups += explode(',', $sprint->whitelist); + $groups = explode(',', $sprint->whitelist); + $whitelist = $this->group->getGroupAccounts($groups); + $this->personnel->updateWhitelist($whitelist, 'sprint', $sprint->id, 'whitelist', 'upgrade'); } + } - $users = $groups ? $this->dao->select('account')->from(TABLE_USERGROUP)->where('`group`')->in($groups)->fetchPairs() : array(); - foreach($users as $account) $whiteList[$account] = $account; - - /* Insert whiteList into program and projec. */ - if($whiteList) $this->loadModel('personnel')->updateWhitelist($whiteList, 'project', $projectiD, 'whitelist', 'upgrade', 'Upgrade synced accounts.'); + /** + * Set program default priv. + * + * @param string $fromVersion + * @access public + * @return void + */ + public function setDefaultPriv() + { + } /** diff --git a/module/user/model.php b/module/user/model.php index 48f2c2fb9f..92711ab6f6 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2032,6 +2032,11 @@ class userModel extends model } } + /* Get white list accounts. */ + $objectType = $project->type == 'project' ? 'project' : 'sprint'; + $accounts = $this->loadModel('personnel')->getWhitelistAccount($project->id, $objectType); + $users += $accounts ? $accounts : array(); + return $users; } @@ -2043,9 +2048,9 @@ class userModel extends model * @access public * @return array */ - public function getProgramAuthedUsers($program, $stakeholders) + public function getProgramAuthedUsers($program, $stakeholders) { - $users = array(); + $users = array(); foreach(explode(',', trim($this->app->company->admins, ',')) as $admin) $users[$admin] = $admin; @@ -2054,6 +2059,10 @@ class userModel extends model $users += $stakeholders ? $stakeholders : array(); + /* Get white list accounts. */ + $accounts = $this->loadModel('personnel')->getWhitelistAccount($program->id, 'program'); + $users += $accounts ? $accounts : array(); + return $users; } @@ -2093,18 +2102,13 @@ class userModel extends model $users[$product->createdBy] = $product->createdBy; if(isset($product->feedback)) $users[$product->feedback] = $product->feedback; - if($product->acl == 'custom') - { - foreach(explode(',', $product->whitelist) as $whitelist) - { - if(empty($whitelist)) continue; - $users += zget($groupUsers, $whitelist, array()); - } - } - $users += $teams ? $teams : array(); $users += $stakeholders ? $stakeholders : array(); + /* Get white list accounts. */ + $accounts = $this->loadModel('personnel')->getWhitelistAccount($product->id, 'product'); + $users += $accounts ? $accounts : array(); + return $users; }