From 7a63b3f6d82045baba30d8599eb807c5d70c36eb Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 11 Apr 2023 09:59:20 +0800 Subject: [PATCH] * Fix bug of show relation privs. --- module/group/control.php | 3 ++- module/group/css/managepriv.css | 2 +- module/group/js/managepriv.js | 2 +- module/group/model.php | 35 +++++++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/module/group/control.php b/module/group/control.php index 230671d90f..ac8ed1a384 100644 --- a/module/group/control.php +++ b/module/group/control.php @@ -293,7 +293,8 @@ class group extends control } } - $relatedPrivData = $this->group->getRelatedPrivs($selectedPrivIdList); + $groupPrivsIdList = $this->group->getPrivsIdListByGroup($groupID); + $relatedPrivData = $this->group->getRelatedPrivs($selectedPrivIdList, '', array_keys($groupPrivsIdList)); $this->view->privList = $privList; $this->view->privMethods = $privMethods; diff --git a/module/group/css/managepriv.css b/module/group/css/managepriv.css index 3d665bd4e0..7f420eda41 100644 --- a/module/group/css/managepriv.css +++ b/module/group/css/managepriv.css @@ -7,7 +7,7 @@ .priv-panel .table-empty-tip {padding: calc(20% - 20px) 10px;} .priv-panel + .priv-panel .table-empty-tip {padding: calc(30% - 20px) 10px;} .priv-panel + .priv-panel {margin-top: 16px; height: calc(60% - 16px);} -.priv-panel > .panel-content {height: calc(100% - 16px); overflow-y: auto; min-height: 140px; padding-left: 4px; padding-top: 5px;} +.priv-panel > .panel-content {height: calc(100% - 25px); overflow-y: auto; min-height: 110px; padding-left: 4px; margin-top: 10px;} .priv-panel > .panel-bottom {padding-top: 20px;} .priv-panel > .panel-title {position: relative;} .priv-panel > .panel-title > .icon-help {position: absolute; top: 3px; margin-left: 8px;} diff --git a/module/group/js/managepriv.js b/module/group/js/managepriv.js index 5fad6bc47f..537dbf1501 100644 --- a/module/group/js/managepriv.js +++ b/module/group/js/managepriv.js @@ -285,7 +285,7 @@ function recommendChange($item, checked) $parentItem.closest('.checkbox-primary').find('label').addClass('checkbox-indeterminate-block'); } - var privID = $actionItem.closest('.group-item').attr('data-id'); + var privID = $item.attr('data-relationpriv'); if(privID != 0) { var index = selectedPrivIdList.indexOf(privID); diff --git a/module/group/model.php b/module/group/model.php index f86997f4b8..0431d6bf48 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -465,6 +465,20 @@ class groupModel extends model $data->method = $priv->method; $this->dao->replace(TABLE_GROUPPRIV)->data($data)->exec(); } + $recommendPrivs = $this->getPrivByIdList(zget($_POST, 'recommendPrivs')); + foreach($recommendPrivs as $privID => $priv) + { + if(in_array($priv->method, zget($_POST['actions'], $priv->module, array()))) + { + unset($recommendPrivs[$privID]); + continue; + } + $data = new stdclass(); + $data->group = $groupID; + $data->module = $priv->module; + $data->method = $priv->method; + $this->dao->replace(TABLE_GROUPPRIV)->data($data)->exec(); + } } return !empty($depentedPrivs) ? true : false; } @@ -2066,13 +2080,15 @@ class groupModel extends model * @access public * @return array */ - public function getRelatedPrivs($privIdList, $type = '') + public function getRelatedPrivs($privIdList, $type = '', $excludePrivs = array(), $appendIdList = '') { $relatedPrivs = $this->dao->select('t1.relationPriv,t1.type,t2.parent,t2.module,t2.method,t3.`key`,t3.value')->from(TABLE_PRIVRELATION)->alias('t1') ->leftJoin(TABLE_PRIV)->alias('t2')->on('t1.relationPriv=t2.id') ->leftJoin(TABLE_PRIVLANG)->alias('t3')->on('t1.relationPriv=t3.objectID') - ->where('t1.priv')->in($privIdList) + ->where('(t1.priv')->in($privIdList) + ->orWhere('t1.relationPriv')->in($appendIdList)->markRight(1) ->andWhere('t1.relationPriv')->notin($privIdList) + ->beginIF(!empty($excludePrivs))->andWhere('t1.relationPriv')->notin($excludePrivs)->fi() ->beginIF(!empty($type))->andWhere('t1.type')->eq($type)->fi() ->andWhere('t3.objectType')->eq('priv') ->andWhere('t2.edition')->like("%,{$this->config->edition},%") @@ -2118,4 +2134,19 @@ class groupModel extends model ->orderBy('order_asc') ->fetchAll('id'); } + + /** + * Get privs id list by group. + * + * @param int $groupID + * @access public + * @return void + */ + public function getPrivsIdListByGroup($groupID) + { + $actions = $this->dao->select("CONCAT(module, '-', method) AS action")->from(TABLE_GROUPPRIV)->where('`group`')->eq($groupID)->fetchPairs(); + $actions = implode("','", $actions); + $privIdList = $this->dao->select("*")->from(TABLE_PRIV)->where("CONCAT(module, '-', method) IN ('$actions')")->fetchAll('id'); + return $privIdList; + } }