From 206dea63bdcd4bd374796b9c4d34bdb7e446dc88 Mon Sep 17 00:00:00 2001 From: holan20180123 <56391770@qq.com> Date: Mon, 7 Jun 2021 08:56:57 +0800 Subject: [PATCH 1/2] * Add comments. --- lib/spliter/spliter.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/spliter/spliter.class.php b/lib/spliter/spliter.class.php index f1ad87b7b8..295b45df52 100644 --- a/lib/spliter/spliter.class.php +++ b/lib/spliter/spliter.class.php @@ -39,6 +39,7 @@ class spliter { $i ++; + /* Stitching content in the case of words or Spaces. */ if($this->isLetter($letter)) { $word = $letter; @@ -80,6 +81,7 @@ class spliter } else { + /* When the current word has a corresponding number in the dictionary table, concatenate a space before it. */ if(is_numeric(substr($words, strlen($words) - 1, 1))) { $words .= ' ' . $letter; From af0a85083b6e7c6af4b9569ae9d27679ba3e2667 Mon Sep 17 00:00:00 2001 From: holan20180123 <56391770@qq.com> Date: Mon, 7 Jun 2021 09:15:44 +0800 Subject: [PATCH 2/2] * Fix bug #12627. --- module/group/config.php | 5 +++ module/group/control.php | 3 +- module/group/model.php | 17 ++++++++- module/personnel/model.php | 77 ++++++++++++++++++++++++++++++++------ 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/module/group/config.php b/module/group/config.php index dda03629bd..6b75d3807b 100644 --- a/module/group/config.php +++ b/module/group/config.php @@ -4,3 +4,8 @@ $config->group->create = new stdclass(); $config->group->edit = new stdclass(); $config->group->create->requiredFields = 'name'; $config->group->edit->requiredFields = 'name'; + +$config->group->acl = new stdclass(); +$config->group->acl->objectTypes['programs'] = 'program'; +$config->group->acl->objectTypes['projects'] = 'project'; +$config->group->acl->objectTypes['products'] = 'product'; diff --git a/module/group/control.php b/module/group/control.php index afabc0c35e..89139a8a4a 100644 --- a/module/group/control.php +++ b/module/group/control.php @@ -132,7 +132,8 @@ class group extends control $this->group->updateView($groupID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); + $link = isonlybody() ? 'parent' : $this->createLink('group', 'browse'); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); } /* Get the group data by id. */ diff --git a/module/group/model.php b/module/group/model.php index 902e84727a..39f4be6265 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -345,7 +345,8 @@ class groupModel extends model */ public function updateView($groupID) { - $actions = $this->post->actions; + $actions = $this->post->actions; + $oldGroup = $this->getByID($groupID); if(isset($_POST['allchecker']))$actions['views'] = array(); if(!isset($actions['actions']))$actions['actions'] = array(); @@ -362,6 +363,20 @@ class groupModel extends model } $actions['actions'] = $dynamic; + /* Update whitelist. */ + $users = $this->getUserPairs($groupID); + $users = array_keys($users); + foreach($this->config->group->acl->objectTypes as $key => $objectType) + { + $oldAcls = isset($oldGroup->acl[$key]) ? $oldGroup->acl[$key] : array(); + $newAcls = isset($actions[$key]) ? $actions[$key] : array(); + $needRemoveAcls = array_diff($oldAcls, $newAcls); + $needAddAcls = array_diff($newAcls, $oldAcls); + foreach($needAddAcls as $objectID) $this->loadModel('personnel')->updateWhitelist($users, $objectType, $objectID, 'whitelist', 'add', 'increase'); + foreach($needRemoveAcls as $objectID) $this->loadModel('personnel')->deleteWhitelist($users, $objectType, $objectID); + } + + $actions = empty($actions) ? '' : json_encode($actions); $this->dao->update(TABLE_GROUP)->set('acl')->eq($actions)->where('id')->eq($groupID)->exec(); return dao::isError() ? false : true; diff --git a/module/personnel/model.php b/module/personnel/model.php index df8b2e6463..74233e628d 100644 --- a/module/personnel/model.php +++ b/module/personnel/model.php @@ -497,25 +497,27 @@ class personnelModel extends model * @param array $users * @param string $objectType program|project|product|sprint * @param int $objectID - * @param string $type whitelist|blacklist - * @param string $source upgrade|add|sync + * @param string $type whitelist|blacklist + * @param string $source upgrade|add|sync + * @param string $updateType increase|replace * @access public * @return void */ - public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add') + public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add', $updateType = 'replace') { $oldWhitelist = $this->dao->select('account,objectType,objectID,type,source')->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(); + 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); $accounts = array(); foreach($users as $account) { + $accounts[$account] = $account; + if(isset($oldWhitelist[$account])) { - $this->dao->insert(TABLE_ACL)->data($oldWhitelist[$account])->exec(); - $accounts[$account] = $account; + if($updateType == 'replace') $this->dao->insert(TABLE_ACL)->data($oldWhitelist[$account])->exec(); continue; } @@ -527,11 +529,17 @@ class personnelModel extends model $acl->source = $source; $this->dao->insert(TABLE_ACL)->data($acl)->autoCheck()->exec(); if(!dao::isError()) $this->loadModel('user')->updateUserView($acl->objectID, $acl->objectType, $acl->account); - $accounts[$account] = $account; } - $whitelist = ',' . implode(',', $accounts); + /* Update whitelist field. */ $objectTable = $objectType == 'product' ? TABLE_PRODUCT : TABLE_PROJECT; + if($updateType == 'increase') + { + $oldWhitelist = $this->dao->select('whitelist')->from($objectTable)->where('id')->eq($objectID)->fetch('whitelist'); + $oldWhitelist = explode(',', $oldWhitelist); + $accounts = array_unique(array_merge($accounts, $oldWhitelist)); + } + $whitelist = ',' . implode(',', $accounts); $this->dao->update($objectTable)->set('whitelist')->eq($whitelist)->where('id')->eq($objectID)->exec(); $deletedAccounts = array(); @@ -549,10 +557,13 @@ class personnelModel extends model $programWhitelist = $this->getWhitelistAccount($product->program, 'program'); $newWhitelist = array_merge($programWhitelist, $accounts); $source = $source == 'upgrade' ? 'upgrade' : 'sync'; - $this->updateWhitelist($newWhitelist, 'program', $product->program, 'whitelist', $source); + $this->updateWhitelist($newWhitelist, 'program', $product->program, 'whitelist', $source, $updateType); /* Removal of persons from centralized program whitelisting. */ - foreach($deletedAccounts as $account) $this->deleteProgramWhitelist($objectID, $account); + if($updateType == 'replace') + { + foreach($deletedAccounts as $account) $this->deleteProgramWhitelist($objectID, $account); + } } /* Synchronization of people from the sprint white list to the project. */ @@ -567,7 +578,10 @@ class personnelModel extends model $this->updateWhitelist($newWhitelist, 'project', $sprint->project, 'whitelist', $source); /* Removal of whitelisted persons from projects. */ - foreach($deletedAccounts as $account) $this->deleteProjectWhitelist($objectID, $account); + if($updateType == 'replace') + { + foreach($deletedAccounts as $account) $this->deleteProjectWhitelist($objectID, $account); + } } } @@ -585,6 +599,23 @@ class personnelModel extends model $this->updateWhitelist($users, $objectType, $objectID); } + /** + * Delete product whitelist. + * + * @param int $objectID + * @param string $account + * @access public + * @return void + */ + public function deleteProductWhitelist($objectID, $account = '') + { + $product = $this->dao->select('id,whitelist')->from(TABLE_PRODUCT)->where('id')->eq($objectID)->fetch('whitelist'); + if(empty($product)) return false; + + $newWhitelist = str_replace(',' . $acl->account, '', $product->whitelist); + $this->dao->update(TABLE_PRODUCT)->set('whitelist')->eq($newWhitelist)->where('id')->eq($objectID)->exec(); + } + /** * Determine whether the user exists in the white list of multiple products. * @@ -635,6 +666,30 @@ class personnelModel extends model } } + /** + * Delete users in whitelist. + * + * @param array $users + * @param string $objectType + * @param int $objectID + * @access public + * @return void + */ + public function deleteWhitelist($users = array(), $objectType = 'program', $objectID = 0) + { + $this->dao->delete()->from(TABLE_ACL) + ->where('objectID')->eq($objectID) + ->andWhere('account')->in($users) + ->exec(); + + foreach($users as $account) + { + if($objectType == 'program') $this->deleteProgramWhitelist($objectID, $account); + if($objectType == 'project') $this->deleteProjectWhitelist($objectID, $account); + if($objectType == 'product') $this->deleteProductWhitelist($objectID, $account); + } + } + /** * Create access links by department. *