From c61115283fe5f491acbbcc8660ac882d1f490cdf Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 18 Mar 2007 18:35:18 +0000 Subject: [PATCH] r1502: Making fetch_on_bits() work with multiple user groups --- includes/functions.php | 46 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index dc8088c..cfe70a4 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -470,33 +470,55 @@ function fetch_on_bits($mask, $userinfo = null) $onbits = array(); $usergroupid = $userinfo['usergroupid']; + FetchUserPermissions($userinfo); // get the groups + $groups = $userinfo['groupids']; + $groups[] = $usergroupid; - if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions["$mask"] AND is_array($bugsys->datastore['product'])) + // product-inspecific work + if (is_array($bugsys->datastore['product'])) { - foreach ($bugsys->datastore['product'] AS $id => $product) + foreach ($groups AS $groupid) { - $onbits["$id"] = $id; + // we only need to do this so long as there's no onbits array because this isn't product specific + if (sizeof($onbits) == 0 AND $bugsys->datastore['usergroup']["$groupid"]['permissions'] & $bugsys->permissions["$mask"]) + { + foreach ($bugsys->datastore['product'] AS $id => $product) + { + $onbits["$id"] = $id; + } + } } } - if (is_array($bugsys->datastore['permission']["$usergroupid"])) + // bits set explicitly by products + $explicit = array(); + + // product specific work + foreach ($groups AS $groupid) { - foreach ($bugsys->datastore['permission']["$usergroupid"] AS $productid => $bit) + if (is_array($bugsys->datastore['permission']["$groupid"])) { - if ($bit & $bugsys->permissions["$mask"]) + foreach ($bugsys->datastore['permission']["$groupid"] AS $productid => $bit) { - $onbits["$productid"] = $productid; - } - else - { - if ($onbits["$productid"]) + if ($bit & $bugsys->permissions["$mask"]) + { + $explicit["$productid"] = $productid; + $onbits["$productid"] = $productid; + } + else { - unset($onbits["$productid"]); + // only unset if the bit was set in the first place by blanket and not product-specific permissions + // if it was set by product permissions then the highest level takes precedence + if ($onbits["$productid"] AND !isset($explicit["$productid"])) + { + unset($onbits["$productid"]); + } } } } } + // SQL queries would become very unhappy if we didn't do this if (sizeof($onbits) < 1) { $onbits = array(0); -- 2.43.5