From 2c06f5c3faf3a07d7e418a3561a147e0258a05c9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 10 Oct 2005 18:39:43 +0000 Subject: [PATCH] r525: Got base of new per-product permissions --- admin/global.php | 3 +- admin/permission.php | 210 +++++++++++++++++++++++++++++++ docs/schema_changes.sql | 10 +- includes/functions_datastore.php | 8 ++ 4 files changed, 229 insertions(+), 2 deletions(-) create mode 100755 admin/permission.php diff --git a/admin/global.php b/admin/global.php index 687f9b8..aa671ba 100755 --- a/admin/global.php +++ b/admin/global.php @@ -41,7 +41,8 @@ $globalnav = array( $lang->string('User Management') => array( $lang->string('Users') => 'user.php', - $lang->string('Usergroups') => 'usergroup.php' + $lang->string('Usergroups') => 'usergroup.php', + $lang->string('Usergroup Permissions') => 'permission.php' ) ); diff --git a/admin/permission.php b/admin/permission.php new file mode 100755 index 0000000..9847f8f --- /dev/null +++ b/admin/permission.php @@ -0,0 +1,210 @@ +string('General Permissions') => array( + 'canviewbugs' => $lang->string('Can View Bugs'), + 'canviewhidden' => $lang->string('Can View Hidden Bugs and Comments'), + 'cansubscribe' => $lang->string('Can Subscribe to Bugs'), + ), + + $lang->string('Posting/Submitting Permissions') => array( + 'canvote' => $lang->string('Can Vote on Polls'), + 'cansubmitbugs' => $lang->string('Can Submit Bugs'), + 'canpostcomments' => $lang->string('Can Post Comments'), + 'cangetattach' => $lang->string('Can View Attachments'), + 'canputattach' => $lang->string('Can Upload/Edit Own Attachments'), + 'caneditattach' => $lang->string('Can Manage All Attachments') + ), + + $lang->string('Moderation/Managment Permissions') => array( + 'caneditown' => $lang->string('Can Edit Own Bugs'), + 'caneditothers' => $lang->string('Can Edit Others\' Bugs'), + 'caneditinfo' => $lang->string('Can Edit Bug Information'), + 'canassign' => $lang->string('Can Assign Bugs'), + 'canchangestatus' => $lang->string('Can Change Status') + ) +); + +// ################################################################### + +if (empty($_REQUEST['do'])) +{ + $_REQUEST['do'] = 'modify'; +} + +// ################################################################### + +if ($_REQUEST['do'] == 'kill') +{ + $db->query("DELETE FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . intval($bugsys->in['usergroupid']) . " AND productid = " . intval($bugsys->in['productid'])); + + build_permissions(); + + $admin->redirect('permission.php?do=modify&usergroupid=' . intval($bugsys->in['usergroupid'])); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'delete') +{ + $admin->page_confirm($lang->string('Are you sure you want to revert this permission mask?'), 'permission.php?do=kill&usergroupid=' . intval($bugsys->in['usergroupid']) . '&productid=' . intval($bugsys->in['productid'])); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'edit') +{ + $perm = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . intval($bugsys->in['usergroupid']) . " AND productid = " . intval($bugsys->in['productid'])); + $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . intval($bugsys->in['usergroupid'])); + $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid'])); + + if (!$usergroup OR !$product) + { + $admin->error($lang->getlex('error_invalid_id')); + } + + $admin->page_start($lang->string('Edit Permissions')); + + $admin->form_start('permission.php', 'update'); + $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']); + $admin->form_hidden_field('productid', $product['productid']); + + // determine the value to work off of + if ($perm) + { + $mask = $perm['mask']; + } + else + { + $mask = $usergroup['permissions']; + } + + // Permission + $admin->table_start(); + $admin->table_head(sprintf($lang->string('Permissions: %1$s - %2$s'), $usergroup['title'], $product['title'])); + + foreach ($permissions AS $group => $settings) + { + $admin->row_span($group, 'thead', 'center'); + foreach ($settings AS $setting => $name) + { + $admin->row_yesno($name, "perm[$setting]", ($mask & $_PERMISSION["$setting"])); + } + } + + $admin->row_submit(); + $admin->table_end(); + $admin->form_end(); + $admin->page_end(); +} + +// ################################################################### + +if ($_POST['do'] == 'update') +{ + foreach ($_POST['perm'] AS $permtitle => $binaryswitch) + { + $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch; + } + + $db->query(" + REPLACE INTO " . TABLE_PREFIX . "permission + (usergroupid, productid, mask) + VALUES + (" . intval($bugsys->in['usergroupid']) . ", + " . intval($bugsys->in['productid']) . ", + $permissionvalue + )" + ); + + build_permissions(); + + $ugroupid = intval($bugsys->in['usergroupid']); + + $admin->redirect('permission.php?do=modify&usergroupid=' . $ugroupid); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'modify') +{ + $admin->page_start($lang->string('Permission Manager')); + + $admin->table_start(); + $admin->table_head($lang->string('Permission Manager')); + + $groups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC"); + while ($group = $db->fetch_array($groups)) + { + $usergroups["$group[usergroupid]"] = $group; + } + $db->free_result($groups); + + foreach ($usergroups AS $group) + { + $admin->row_text($group['title'], ($bugsys->in['usergroupid'] != $group['usergroupid'] ? "[" . $lang->string('Expand') . "]" : ''), 'top', 2, 'alt3'); + + if ($bugsys->in['usergroupid'] == $group['usergroupid']) + { + $permissions_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = $group[usergroupid]"); + while ($permission = $db->fetch_array($permissions_fetch)) + { + $permissions["$permission[productid]"] = $permission['mask']; + } + + $products_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC"); + while ($product = $db->fetch_array($products_fetch)) + { + $groupid = $group['usergroupid']; + $prodid = $product['productid']; + + if (!isset($permissions["$product[productid]"])) + { + $statuslink = $lang->string('Inherited From Usergroup Settings: '); + $statuslink .= "[" . $lang->string('Customize') . ']'; + } + else + { + $statuslink = $lang->string('Customized: '); + $statuslink .= "[" . $lang->string('Edit') . ']'; + $statuslink .= " [" . $lang->string('Revert') . ']'; + } + + $admin->row_text($product['title'], $statuslink); + } + } + } + + $admin->table_end(); + + $admin->page_end(); +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 0211ede..1353d91 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -58,4 +58,12 @@ ALTER TABLE `user` ADD `showcolours` INT(2) UNSIGNED NOT NULL AFTER `showemail`; ALTER TABLE `history` ADD `attachmentid` INT(10) UNSIGNED NOT NULL AFTER `bugid`; -ALTER TABLE `history` ADD `commentid` INT(10) UNSIGNED NOT NULL AFTER `attachmentid`; \ No newline at end of file +ALTER TABLE `history` ADD `commentid` INT(10) UNSIGNED NOT NULL AFTER `attachmentid`; + +CREATE TABLE `permission` ( + `usergroupid` INT(10) UNSIGNED NOT NULL, + `productid` INT(10) UNSIGNED NOT NULL, + `mask` INT(5) NOT NULL +); + +ALTER TABLE `permission` ADD PRIMARY KEY (`usergroupid`,`productid`); \ No newline at end of file diff --git a/includes/functions_datastore.php b/includes/functions_datastore.php index 82e51f6..8f99b82 100755 --- a/includes/functions_datastore.php +++ b/includes/functions_datastore.php @@ -216,6 +216,14 @@ function build_products() $bugsys->datastore['product'] = $tempstore; } +// ##################### Start build_permissions ##################### +function build_permissions() +{ + global $bugsys; + + // first cache all the global permissions +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ -- 2.22.5