r1507: Adding the ability to clone usergroups
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 18 Mar 2007 22:45:31 +0000 (22:45 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 18 Mar 2007 22:45:31 +0000 (22:45 +0000)
admin/usergroup.php
docs/changes.txt

index 2cffefc32c9522653b2347d6f69099d031c0ee9b..26fdb354cf59f95c18ffe010dbb3c0c8e538d200 100755 (executable)
@@ -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<div><dfn>This is the title that others will be able to see when comments are posted.</dfn></div>'), '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<div><dfn>This is the title that others will be able to see when comments are posted.</dfn></div>'), '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("<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">$group[title]</a>" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">[" . _('Edit') . "]</a>" . (($group['usergroupid'] > 6) ? " <a href=\"usergroup.php?do=delete&amp;usergroupid=$group[usergroupid]\">[" . _('Delete') . "]</a>" : '') => 'c'));
+               $admin->row_multi_item(array(
+                       "<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">$group[title]</a>" => 'l',
+                       (!$group['total'] ? '-' : $group['total']) => 'c',
+
+                       "<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">[" . _('Edit') . "]</a> " .
+                       "<a href=\"usergroup.php?do=clone&amp;usergroupid=$group[usergroupid]\">[" . _('Clone') . "]</a>" .
+                       ($group['usergroupid'] > 6 ? " <a href=\"usergroup.php?do=delete&amp;usergroupid=$group[usergroupid]\">[" . _('Delete') . "]</a>" : '') => 'c'
+               ));
        }
        
        $admin->table_end();
@@ -413,4 +439,4 @@ if ($_REQUEST['do'] == 'modify')
 || # $Id$
 || ###################################################################
 \*=====================================================================*/
-?>
\ No newline at end of file
+?>
index 7440f560de6bf27a80b7fd37517340fe36553761..a50f06171fdc607163fb706c224d45a488d1c98b 100644 (file)
@@ -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
 ===============================