From 001fc1f20b4812ad6dfb246ea6427dd45786e401 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 18 Mar 2007 22:45:31 +0000 Subject: [PATCH] r1507: Adding the ability to clone usergroups --- admin/usergroup.php | 46 +++++++++++++++++++++++++++++++++++---------- docs/changes.txt | 1 + 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/admin/usergroup.php b/admin/usergroup.php index 2cffefc..26fdb35 100755 --- a/admin/usergroup.php +++ b/admin/usergroup.php @@ -109,10 +109,11 @@ if ($_REQUEST['do'] == 'delete') // ################################################################### -if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') +if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'clone') { - $add = (($_REQUEST['do'] == 'add') ? true : false); - $edit = (($_REQUEST['do'] == 'edit') ? true : false); + $clone = ($_REQUEST['do'] == 'clone'); + $add = ($_REQUEST['do'] == 'add' OR $clone); + $edit = !$add; if ($edit) { @@ -129,14 +130,21 @@ if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') $admin->form_start('usergroup.php', ($add ? 'insert' : 'update')); - if ($edit) + if ($edit OR $clone) { $usergroup = new UsergroupAPI($bugsys); $usergroup->set('usergroupid', $bugsys->in['usergroupid']); $usergroup->set_condition(); $usergroup->fetch(); - $admin->form_hidden_field('usergroupid', $usergroup->objdata['usergroupid']); + if ($clone) + { + $admin->form_hidden_field('cloneid', $usergroup->objdata['usergroupid']); + } + else + { + $admin->form_hidden_field('usergroupid', $usergroup->objdata['usergroupid']); + } } else { @@ -146,8 +154,8 @@ if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') // Details $admin->table_start(); $admin->table_head(_('Usergroup Details')); - $admin->row_input(_('Usergroup Title'), 'title', $bugsys->sanitize($usergroup->objdata['title'])); - $admin->row_input(_('Display Title
This is the title that others will be able to see when comments are posted.
'), 'displaytitle', $bugsys->sanitize($usergroup->objdata['displaytitle'])); + $admin->row_input(_('Usergroup Title'), 'title', (($add AND $clone) ? '' : $bugsys->sanitize($usergroup->objdata['title']))); + $admin->row_input(_('Display Title
This is the title that others will be able to see when comments are posted.
'), 'displaytitle', (($add AND $clone) ? '' : $bugsys->sanitize($usergroup->objdata['displaytitle']))); $admin->table_end(); // Permission @@ -170,7 +178,7 @@ if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') $admin->table_start(); $admin->table_head(_('Custom Field Permissions')); - if ($edit) + if ($edit OR $clone) { $perms = $db->query("SELECT fieldid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid = " . $usergroup->objdata['usergroupid']); while ($perm = $db->fetch_array($perms)) @@ -237,6 +245,17 @@ if ($_POST['do'] == 'insert') ); } + // copy product permissions from cloning + if ($bugsys->input_clean('cloneid', TYPE_UINT)) + { + $prodperms = $db->query("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . $bugsys->in['cloneid']); + while ($prod = $db->fetch_array($prodperms)) + { + $db->query("INSERT INTO " . TABLE_PREFIX . "permission (usergroupid, productid, mask) VALUES (" . $usergroup->insertid . ", $prod[productid], $prod[mask])"); + } + build_permissions(); + } + $admin->redirect('usergroup.php?do=modify'); } @@ -398,7 +417,14 @@ if ($_REQUEST['do'] == 'modify') $admin->table_column_head(array(_('Usergroup'), _('Number of Users'), _('Action'))); foreach ($usergroups AS $group) { - $admin->row_multi_item(array("$group[title]" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "[" . _('Edit') . "]" . (($group['usergroupid'] > 6) ? " [" . _('Delete') . "]" : '') => 'c')); + $admin->row_multi_item(array( + "$group[title]" => 'l', + (!$group['total'] ? '-' : $group['total']) => 'c', + + "[" . _('Edit') . "] " . + "[" . _('Clone') . "]" . + ($group['usergroupid'] > 6 ? " [" . _('Delete') . "]" : '') => 'c' + )); } $admin->table_end(); @@ -413,4 +439,4 @@ if ($_REQUEST['do'] == 'modify') || # $Id$ || ################################################################### \*=====================================================================*/ -?> \ No newline at end of file +?> diff --git a/docs/changes.txt b/docs/changes.txt index 7440f56..a50f061 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -15,6 +15,7 @@ - Fixed: If any fields had invalid data in editreport.php no errors would be thrown - Fixed: The Logging system would add extra empty logs that would pollute the database; fixed this and then added queries in showhistory.php to clean it up - Enhancement: Users can now belong to a single primary usergroup and multiple secondary groups, greatly increasing permission flexibility +- Enahncement: Usergroups can be cloned to allow fast duplication of permissions 1.2.0 Beta 1 =============================== -- 2.22.5