From 6359266cf95d4399ff8ee033731e455dc8de1907 Mon Sep 17 00:00:00 2001 From: liyuchun Date: Wed, 13 Oct 2021 16:37:24 +0800 Subject: [PATCH] * Adjust logic of update whitelist when update user view. --- module/personnel/control.php | 6 +++++- module/personnel/model.php | 38 ++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/module/personnel/control.php b/module/personnel/control.php index 3b2b74da9b..012c907c8e 100644 --- a/module/personnel/control.php +++ b/module/personnel/control.php @@ -243,7 +243,11 @@ class personnel extends control $this->dao->update($objectTable)->set('whitelist')->eq($newWhitelist)->where('id')->eq($acl->objectID)->exec(); $this->dao->delete()->from(TABLE_ACL)->where('id')->eq($id)->exec(); - if($acl->objectType == 'product') $this->personnel->deleteProgramWhitelist($acl->objectID, $acl->account); + if($acl->objectType == 'product') + { + $product = $this->loadModel('product')->getByID($acl->objectID); + if($product->program) $this->personnel->deleteProgramWhitelist($product->program, $acl->account); + } if($acl->objectType == 'sprint') $this->personnel->deleteProjectWhitelist($acl->objectID, $acl->account); $this->loadModel('user')->updateUserView($acl->objectID, $acl->objectType, array($acl->account)); diff --git a/module/personnel/model.php b/module/personnel/model.php index 868544616a..49588ab711 100644 --- a/module/personnel/model.php +++ b/module/personnel/model.php @@ -670,18 +670,24 @@ class personnelModel extends model /** * Delete product whitelist. * - * @param int $objectID + * @param int $productID * @param string $account * @access public * @return void */ - public function deleteProductWhitelist($objectID, $account = '') + public function deleteProductWhitelist($productID, $account = '') { - $product = $this->dao->select('id,whitelist')->from(TABLE_PRODUCT)->where('id')->eq($objectID)->fetch('whitelist'); + $product = $this->dao->select('id,whitelist')->from(TABLE_PRODUCT)->where('id')->eq($productID)->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(); + $this->dao->update(TABLE_PRODUCT)->set('whitelist')->eq($newWhitelist)->where('id')->eq($productID)->exec(); + $this->dao->delete()->from(TABLE_ACL) + ->where('objectID')->eq($productID) + ->andWhere('account')->eq($account) + ->andWhere('objectType')->eq('product') + ->andWhere('source')->eq('sync') + ->exec(); } /** @@ -694,7 +700,9 @@ class personnelModel extends model */ public function deleteProgramWhitelist($programID = 0, $account = '') { - $program = $this->loadModel('program')->getByID($programID); + $program = $this->loadModel('program')->getByID($programID); + if(empty($program)) return false; + $products = $this->dao->select('id')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq('0')->fetchPairs('id'); $whitelist = $this->dao->select('*')->from(TABLE_ACL)->where('objectID')->in($products)->andWhere('account')->eq($account)->andWhere('objectType')->eq('product')->fetch(); @@ -703,7 +711,12 @@ class personnelModel extends model { $newWhitelist = str_replace(',' . $account, '', $program->whitelist); $this->dao->update(TABLE_PROGRAM)->set('whitelist')->eq($newWhitelist)->where('id')->eq($programID)->exec(); - $this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($programID)->andWhere('account')->eq($account)->andWhere('objectType')->eq('program')->exec(); + $this->dao->delete()->from(TABLE_ACL) + ->where('objectID')->eq($programID) + ->andWhere('account')->eq($account) + ->andWhere('objectType')->eq('program') + ->andWhere('source')->eq('sync') + ->exec(); } $this->loadModel('user')->updateUserView($programID, 'program', array($account)); } @@ -730,7 +743,12 @@ class personnelModel extends model { $newWhitelist = str_replace(',' . $account, '', $project->whitelist); $this->dao->update(TABLE_PROJECT)->set('whitelist')->eq($newWhitelist)->where('id')->eq($projectID)->exec(); - $this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($projectID)->andWhere('account')->eq($account)->andWhere('objectType')->eq('project')->exec(); + $this->dao->delete()->from(TABLE_ACL) + ->where('objectID')->eq($projectID) + ->andWhere('account')->eq($account) + ->andWhere('objectType')->eq('project') + ->andWhere('source')->eq('sync') + ->exec(); } $this->loadModel('user')->updateUserView($projectID, 'project', array($account)); } @@ -746,12 +764,6 @@ class personnelModel extends model */ public function deleteWhitelist($users = array(), $objectType = 'program', $objectID = 0) { - $this->dao->delete()->from(TABLE_ACL) - ->where('objectID')->eq($objectID) - ->andWhere('account')->in($users) - ->andWhere('source')->eq('sync') - ->exec(); - foreach($users as $account) { if($objectType == 'program') $this->deleteProgramWhitelist($objectID, $account);