From de82ed6a3f8b4a1a12d25f3be507be0876990de4 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Thu, 30 Nov 2023 09:21:20 +0800 Subject: [PATCH] * Refactor common::haspriv. --- module/common/model.php | 26 +++----------------------- module/common/tao.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/module/common/model.php b/module/common/model.php index 5b32205207..778f02c609 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1169,7 +1169,7 @@ class commonModel extends model */ public static function hasPriv(string $module, string $method, mixed $object = null, string $vars = '') { - global $app, $lang; + global $app; $module = strtolower($module); $method = strtolower($method); parse_str($vars, $params); @@ -1198,10 +1198,7 @@ class commonModel extends model if(in_array("$module.$method", $app->config->openMethods)) return true; /* If is the program/project/product/execution admin, have all program privileges. */ - if($app->config->vision != 'lite') - { - if(commonTao::isProjectAdmin($module)) return true; - } + if($app->config->vision != 'lite' && commonTao::isProjectAdmin($module)) return true; /* If not super admin, check the rights. */ $rights = $app->user->rights['rights']; @@ -1211,24 +1208,7 @@ class commonModel extends model $canImport = isset($rights[$module]['import']) && commonModel::hasDBPriv($object, $module, 'import'); if(in_array($module, $app->config->importWhiteList) && $method == 'showimport' && $canImport) return true; - if(isset($rights[$module][$method])) - { - if(!commonModel::hasDBPriv($object, $module, $method)) return false; - - if(empty($acls['views'])) return true; - $menu = isset($lang->navGroup->$module) ? $lang->navGroup->$module : $module; - if($module == 'my' and $method == 'team') $menu = 'system'; // Fix bug #18642. - $menu = strtolower($menu); - if($menu != 'qa' and !isset($lang->$menu->menu)) return true; - if(($menu == 'my' and $method != 'team') or $menu == 'index' or $module == 'tree') return true; - if($module == 'company' and $method == 'dynamic') return true; - if($module == 'action' and $method == 'editcomment') return true; - if($module == 'action' and $method == 'comment') return true; - if($module == 'report' and $method == 'export') return true; - if(!isset($acls['views'][$menu])) return false; - - return true; - } + if(isset($rights[$module][$method])) return commonTao::checkPrivByRights($module, $method, $acls, $object); return false; } diff --git a/module/common/tao.php b/module/common/tao.php index 520085ba66..934168d8ca 100644 --- a/module/common/tao.php +++ b/module/common/tao.php @@ -200,6 +200,37 @@ class commonTao extends commonModel return array($display, $currentMethod); } + /** + * 根据后台维护分组的视图设置,判断用户是否有权限。 + * According to the view maintained by the background, determine whether the user has permission. + * + * @param string $module + * @param string $method + * @param array $acls + * @param mixed $object + * @access protected + * @return bool + */ + protected static function checkPrivByRights(string $module, string $method, array $acls, mixed $object): bool + { + global $lang; + if(!commonModel::hasDBPriv($object, $module, $method)) return false; + + if(empty($acls['views'])) return true; + $menu = isset($lang->navGroup->$module) ? $lang->navGroup->$module : $module; + if($module == 'my' and $method == 'team') $menu = 'system'; // Fix bug #18642. + $menu = strtolower($menu); + if($menu != 'qa' and !isset($lang->$menu->menu)) return true; + if(($menu == 'my' and $method != 'team') or $menu == 'index' or $module == 'tree') return true; + if($module == 'company' and $method == 'dynamic') return true; + if($module == 'action' and $method == 'editcomment') return true; + if($module == 'action' and $method == 'comment') return true; + if($module == 'report' and $method == 'export') return true; + if(!isset($acls['views'][$menu])) return false; + + return true; + } + /** * 查看当前用户是否有其他个性化设置导航的权限。 * Check if current user has other methods permissions under the preference menu.