]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 134474: The mass-change form in buglist.cgi offers too many groups - Patch by...
authorlpsolit%gmail.com <>
Mon, 10 Sep 2007 17:53:32 +0000 (17:53 +0000)
committerlpsolit%gmail.com <>
Mon, 10 Sep 2007 17:53:32 +0000 (17:53 +0000)
buglist.cgi
template/en/default/list/edit-multiple.html.tmpl

index ce45dc2c017c883232548265ff9736102fcef3d1..f7da1626c2c50e28748868e33d438ce15eb058a3 100755 (executable)
@@ -345,23 +345,31 @@ sub GetQuip {
     return $quip;
 }
 
+# Return groups available for at least one product of the buglist.
 sub GetGroups {
-    my $dbh = Bugzilla->dbh;
+    my $product_names = shift;
     my $user = Bugzilla->user;
+    my %legal_groups;
+
+    foreach my $product_name (@$product_names) {
+        my $product = new Bugzilla::Product({name => $product_name});
+
+        foreach my $gid (keys %{$product->group_controls}) {
+            # The user can only edit groups he belongs to.
+            next unless $user->in_group_id($gid);
+
+            # The user has no control on groups marked as NA or MANDATORY.
+            my $group = $product->group_controls->{$gid};
+            next if ($group->{membercontrol} == CONTROLMAPMANDATORY
+                     || $group->{membercontrol} == CONTROLMAPNA);
 
-    # Create an array where each item is a hash. The hash contains 
-    # as keys the name of the columns, which point to the value of 
-    # the columns for that row.
-    my $grouplist = $user->groups_as_string;
-    my $groups = $dbh->selectall_arrayref(
-                "SELECT  id, name, description, isactive
-                   FROM  groups
-                  WHERE  id IN ($grouplist)
-                    AND  isbuggroup = 1
-               ORDER BY  description "
-               , {Slice => {}});
-
-    return $groups;
+            # It's fine to include inactive groups. Those will be marked
+            # as "remove only" when editing several bugs at once.
+            $legal_groups{$gid} ||= $group->{group};
+        }
+    }
+    # Return a list of group objects.
+    return [values %legal_groups];
 }
 
 
@@ -1166,17 +1174,17 @@ if ($dotweak) {
 
     $vars->{'current_bug_statuses'} = [keys %$bugstatuses];
     $vars->{'new_bug_statuses'} = Bugzilla::Status->new_from_list($bug_status_ids);
-    # The groups to which the user belongs.
-    $vars->{'groups'} = GetGroups();
+
+    # The groups the user belongs to and which are editable for the given buglist.
+    my @products = keys %$bugproducts;
+    $vars->{'groups'} = GetGroups(\@products);
 
     # If all bugs being changed are in the same product, the user can change
     # their version and component, so generate a list of products, a list of
     # versions for the product (if there is only one product on the list of
     # products), and a list of components for the product.
-    $vars->{'bugproducts'} = [ keys %$bugproducts ];
-    if (scalar(@{$vars->{'bugproducts'}}) == 1) {
-        my $product = new Bugzilla::Product(
-            {name => $vars->{'bugproducts'}->[0]});
+    if (scalar(@products) == 1) {
+        my $product = new Bugzilla::Product({name => $products[0]});
         $vars->{'versions'} = [map($_->name ,@{$product->versions})];
         $vars->{'components'} = [map($_->name, @{$product->components})];
         $vars->{'targetmilestones'} = [map($_->name, @{$product->milestones})]
index 91d4bb8526443aca6b497c860cb6b2e44770da36..f19410ab8c1038d22ab4f11e613726a303fdfdc0 100644 (file)
 
 [% IF groups.size > 0 %]
 
-  <b>Groupset:</b><br>
+  <b>Groups:</b><br>
   <table border="1">
     <tr>
       <th>Don't<br>change<br>this group<br>restriction</th>
       <td align="center">
         <input type="radio" name="bit-[% group.id %]" value="0">
       </td>
-      [% IF group.isactive %]
+      [% IF group.is_active %]
         <td align="center">
           <input type="radio" name="bit-[% group.id %]" value="1">
         </td>
       [% END %]
 
       <td>
-        [% SET inactive = !group.isactive %]
+        [% SET inactive = !group.is_active %]
         [% group.description FILTER html_light FILTER inactive(inactive) %]
       </td>