From e01946ce916050d74d7c74911c2f55879811e06d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 24 Dec 2004 01:03:32 +0000 Subject: [PATCH] r21: Changed all bitwise operations to use can_perform() (new: includes/functions.php) as it saves room. Removed redundant checking of $vars[bugid] and $vars[commentid] in newcomment.php and newreport.php. Added descriptions to all bitmasks in includes/init.php. --- admin/global.php | 2 +- admin/options.php | 2 +- admin/priority.php | 2 +- admin/product.php | 2 +- admin/resolution.php | 2 +- admin/severity.php | 2 +- admin/status.php | 2 +- admin/usergroup.php | 2 +- includes/functions.php | 13 +++++++++++++ includes/init.php | 42 +++++++++++++++++++++--------------------- newcomment.php | 8 +------- newreport.php | 10 +++++----- showreport.php | 16 +++++----------- 13 files changed, 53 insertions(+), 52 deletions(-) diff --git a/admin/global.php b/admin/global.php index 8a338d9..6e04f80 100755 --- a/admin/global.php +++ b/admin/global.php @@ -42,7 +42,7 @@ function admin_login() if ($_COOKIE[COOKIE_PREFIX . 'adminsession']) { - if ($bugsys->userinfo['permissions'] & CANADMINPANEL) + if (can_perform('canadminpanel')) { if (md5(md5($bugsys->userinfo['authkey']) . md5($bugsys->userinfo['email']) . md5($bugsys->userinfo['userid'])) != $_COOKIE[COOKIE_PREFIX . 'adminsession']) { diff --git a/admin/options.php b/admin/options.php index caaf87c..62691d6 100755 --- a/admin/options.php +++ b/admin/options.php @@ -14,7 +14,7 @@ require_once('./global.php'); require_once('./includes/settings.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINTOOLS)) +if (!can_perform('canadmintools')) { admin_login(); } diff --git a/admin/priority.php b/admin/priority.php index 6b5cf98..7d8c013 100755 --- a/admin/priority.php +++ b/admin/priority.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINFIELDS)) +if (!can_perform('canadminfields')) { admin_login(); } diff --git a/admin/product.php b/admin/product.php index a094b10..c8b200f 100755 --- a/admin/product.php +++ b/admin/product.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINVERSIONS)) +if (!can_perform('canadminversions')) { admin_login(); } diff --git a/admin/resolution.php b/admin/resolution.php index c3e7680..8fc7c60 100755 --- a/admin/resolution.php +++ b/admin/resolution.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINFIELDS)) +if (!can_perform('canadminfields')) { admin_login(); } diff --git a/admin/severity.php b/admin/severity.php index 212eac0..0f79719 100755 --- a/admin/severity.php +++ b/admin/severity.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINFIELDS)) +if (!can_perform('canadminfields')) { admin_login(); } diff --git a/admin/status.php b/admin/status.php index 6de2c14..5a2bd2d 100755 --- a/admin/status.php +++ b/admin/status.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINFIELDS)) +if (!can_perform('canadminfields')) { admin_login(); } diff --git a/admin/usergroup.php b/admin/usergroup.php index 20e4d26..65573b3 100755 --- a/admin/usergroup.php +++ b/admin/usergroup.php @@ -13,7 +13,7 @@ require_once('./global.php'); require_once('./includes/functions_datastore.php'); -if (!($bugsys->userinfo['permissions'] & CANADMINGROUPS)) +if (!can_perform('canadmingroups')) { admin_login(); } diff --git a/includes/functions.php b/includes/functions.php index ae0d7c5..7adf980 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -259,6 +259,19 @@ function construct_user_display($userinfo) return "$userinfo[displayname]" . iff($userinfo['showemail'], " <$userinfo[email]>") . " (userid: $userinfo[userid])"; } +// ######################## Start can_perform ######################## +// short-hand for bitwise & +function can_perform($bitmask, $userinfo = null) +{ + global $_PERMISSION; + if (!$userinfo) + { + global $bugsys; + return ($bugsys->userinfo['permissions'] & $_PERMISSION["$bitmask"]); + } + return ($userinfo['permissions'] & $_PERMISSION["bitmask"]); +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/init.php b/includes/init.php index f78d047..012c889 100755 --- a/includes/init.php +++ b/includes/init.php @@ -168,27 +168,27 @@ $bugsys = new BugTracker(); // ################################################################### // Initialize usergroup system $_PERMISSION = array( - 'canviewbugs' => 1, - 'cansearch' => 2, - 'cansubscribe' => 4, - 'canvote' => 8, - 'cansubmitbugs' => 16, // 5 - 'canpostcomments' => 32, - 'cangetattach' => 64, - 'canputattach' => 128, - 'caneditown' => 256, - 'caneditothers' => 512, // 10 - 'caneditinfo' => 1024, - 'canassign' => 2048, - 'canchangestatus' => 4096, - 'canadminpanel' => 8192, - 'canadminbugs' => 16384, // 15 - 'canadminversions' => 32768, - 'canadminusers' => 65536, - 'canadmingroups' => 131072, - 'canadmintools' => 262144, - 'canadminfields' => 524288, // 20 - 'canbeassignedto' => 1048576 + 'canviewbugs' => 1, // can view bugs + 'cansearch' => 2, // can use the search + 'cansubscribe' => 4, // can email subscribe + 'canvote' => 8, // can vote on bugs + 'cansubmitbugs' => 16, // can submit new bugs + 'canpostcomments' => 32, // can post new comments + 'cangetattach' => 64, // can dl attachments + 'canputattach' => 128, // can ul attachments + 'caneditown' => 256, // can edit own comments + 'caneditothers' => 512, // can edit others' comments + 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others) + 'canassign' => 2048, // can assign bug + 'canchangestatus' => 4096, // can change bug status + 'canadminpanel' => 8192, // can view admin panel + 'canadminbugs' => 16384, // can administrate bug functions + 'canadminversions' => 32768, // can admin version info + 'canadminusers' => 65536, // can admin users + 'canadmingroups' => 131072, // can admin permission masks + 'canadmintools' => 262144, // can use admin tools + 'canadminfields' => 524288, // can admin custom bug fields + 'canbeassignedto' => 1048576 // can be assigned bugs ); foreach ($_PERMISSION AS $name => $maskvalue) diff --git a/newcomment.php b/newcomment.php index 2eb2ba6..b9152e8 100644 --- a/newcomment.php +++ b/newcomment.php @@ -12,7 +12,7 @@ require_once('./global.php'); -if (!($bugsys->userinfo['permissions'] & CANPOSTCOMMENTS)) +if (!can_perform('canpostcomments')) { echo 'no permission'; exit; @@ -57,12 +57,6 @@ if ($_REQUEST['do'] == 'add') { sanitize(array('bugid' => INT)); - if (!$vars['bugid']) - { - echo 'alert: bad bug'; - exit; - } - $bug = $DB_sql->query_first("SELECT bug.*, comment.comment FROM " . TABLE_PREFIX . "bug LEFT JOIN " . TABLE_PREFIX . "comment AS comment ON (bug.bugid = comment.bugid) WHERE bug.bugid = $vars[bugid]"); if (!$bug) { diff --git a/newreport.php b/newreport.php index cb89ae0..3beb566 100755 --- a/newreport.php +++ b/newreport.php @@ -12,7 +12,7 @@ require_once('./global.php'); -if (!($bugsys->userinfo['permissions'] & CANSUBMITBUGS)) +if (!can_perform('cansubmitbugs')) { echo 'NO permission'; exit; @@ -43,7 +43,7 @@ if ($_POST['do'] == 'insert') ); // check permissions on various input values - if (!($bugsys->userinfo['permissions'] & CANCHANGESTATUS)) + if (!can_perform('canchangestatus')) { $vars['priority'] = $bugsys->options['defaultpriority']; $vars['status'] = $bugsys->options['defaultstatus']; @@ -64,7 +64,7 @@ if ($_POST['do'] == 'insert') $vars['resolution'] = $bugsys->options['defaultresolve']; } } - if (!($bugsys->userinfo['permissions'] & CANASSIGN)) + if (!can_perform('canassign')) { $vars['assignedto'] = $bugsys->options['defaultassign']; } @@ -273,7 +273,7 @@ if ($_REQUEST['do'] == 'add') } echo ''; - if ($bugsys->userinfo['permissions'] & CANCHANGESTATUS) + if (can_perform('canchangestatus')) { echo '
Priority:
'; } - if ($bugsys->userinfo['permissions'] & CANASSIGN) + if (can_perform('canassign')) { echo '
Assigned to: