]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 303183: Bugzilla fails to warn when a product change would force the removal...
authorlpsolit%gmail.com <>
Thu, 26 Jul 2007 19:00:42 +0000 (19:00 +0000)
committerlpsolit%gmail.com <>
Thu, 26 Jul 2007 19:00:42 +0000 (19:00 +0000)
process_bug.cgi
template/en/default/bug/process/verify-new-product.html.tmpl

index bedda92d4a2a531ed7ecc37386a9513891939474..fa79b5edf56e43151e23cbd87bf78f7155607256 100755 (executable)
@@ -92,16 +92,25 @@ sub BugInGroupId {
 # If so, then groups may have to be changed when bugs move from
 # one bug to another.
 sub AnyDefaultGroups {
+    my $product_id = shift;
     my $dbh = Bugzilla->dbh;
+    my $grouplist = Bugzilla->user->groups_as_string;
+
+    my $and_product = $product_id ? ' AND product_id = ? ' : '';
+    my @args = (CONTROLMAPDEFAULT);
+    unshift(@args, $product_id) if $product_id;
+
     my $any_default =
-        $dbh->selectrow_array('SELECT 1
+        $dbh->selectrow_array("SELECT 1
                                  FROM group_control_map
                            INNER JOIN groups
                                    ON groups.id = group_control_map.group_id
                                 WHERE isactive != 0
-                                  AND (membercontrol = ? OR othercontrol = ?) ' .
+                                 $and_product
+                                  AND membercontrol = ?
+                                  AND group_id IN ($grouplist) " .
                                  $dbh->sql_limit(1),
-                                 undef, (CONTROLMAPDEFAULT, CONTROLMAPDEFAULT));
+                                undef, @args);
     return $any_default;
 }
 
@@ -385,8 +394,10 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
     # shown. Also show the verification form if the product-specific fields
     # somehow still need to be verified, or if we need to verify whether or not
     # to add the bugs to their new product's group.
+    my $has_default_groups = AnyDefaultGroups($prod_obj->id);
+
     if (!$vok || !$cok || !$mok || !defined $cgi->param('confirm_product_change')
-        || (AnyDefaultGroups() && !defined $cgi->param('addtonewgroup'))) {
+        || ($has_default_groups && !defined $cgi->param('addtonewgroup'))) {
 
         if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
             if (!$vok) {
@@ -449,10 +460,27 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
         else {
             $vars->{'verify_fields'} = 0;
         }
-        
-        $vars->{'verify_bug_group'} = (AnyDefaultGroups() 
+
+        $vars->{'verify_bug_group'} = ($has_default_groups
                                        && !defined $cgi->param('addtonewgroup'));
-        
+
+        # Get the ID of groups which are no longer valid in the new product.
+        # If the bug was restricted to some group which still exists in the new
+        # product, leave it alone, independently of your privileges.
+        my $gids =
+          $dbh->selectcol_arrayref("SELECT bgm.group_id
+                                      FROM bug_group_map AS bgm
+                                     WHERE bgm.bug_id IN (" . join(', ', @idlist) . ")
+                                       AND bgm.group_id NOT IN
+                                           (SELECT gcm.group_id
+                                              FROM group_control_map AS gcm
+                                             WHERE gcm.product_id = ?
+                                               AND gcm.membercontrol IN (?, ?, ?))",
+                                     undef, ($prod_obj->id, CONTROLMAPSHOWN,
+                                             CONTROLMAPDEFAULT, CONTROLMAPMANDATORY));
+
+        $vars->{'old_groups'} = Bugzilla::Group->new_from_list($gids);
+
         $template->process("bug/process/verify-new-product.html.tmpl", $vars)
           || ThrowTemplateError($template->error());
         exit;
@@ -1900,11 +1928,9 @@ foreach my $id (@idlist) {
             undef, $oldhash{'product_id'}, $product->id, $id);
         my @groupstoremove = ();
         my @groupstoadd = ();
-        my @defaultstoremove = ();
         my @defaultstoadd = ();
         my @allgroups = ();
         my $buginanydefault = 0;
-        my $buginanychangingdefault = 0;
         foreach my $group (@$groups) {
             my ($groupid, $isactive, $oldcontrol, $newcontrol,
                    $useringroup, $bugingroup) = @$group;
@@ -1916,12 +1942,6 @@ foreach my $id (@idlist) {
                 && ($oldcontrol == CONTROLMAPDEFAULT)) {
                 # Bug was in a default group.
                 $buginanydefault = 1;
-                if (($newcontrol != CONTROLMAPDEFAULT)
-                    && ($newcontrol != CONTROLMAPMANDATORY)) {
-                    # Bug was in a default group that no longer is.
-                    $buginanychangingdefault = 1;
-                    push (@defaultstoremove, $groupid);
-                }
             }
             if (($isactive) && (!$bugingroup)
                 && ($newcontrol == CONTROLMAPDEFAULT)
@@ -1938,14 +1958,11 @@ foreach my $id (@idlist) {
                 push(@groupstoadd, $groupid);
             }
         }
-        # If addtonewgroups = "yes", old default groups will be removed
-        # and new default groups will be added.
-        # If addtonewgroups = "yesifinold", old default groups will be removed
-        # and new default groups will be added only if the bug was in ANY
-        # of the old default groups.
-        # If addtonewgroups = "no", old default groups will be removed and not
-        # replaced.
-        push(@groupstoremove, @defaultstoremove);
+        # If addtonewgroups = "yes", new default groups will be added.
+        # If addtonewgroups = "yesifinold", new default groups will be
+        # added only if the bug was in ANY of the old default groups.
+        # If addtonewgroups = "no", old default groups are left alone
+        # and no new default group will be added.
         if (AnyDefaultGroups()
             && (($cgi->param('addtonewgroup') eq 'yes')
             || (($cgi->param('addtonewgroup') eq 'yesifinold')
index 2355f750631a9fb7b9dedb2536b1ed11ae6ff135..1b622506fa45867c64bf3d71bb5f022d4c87262f 100644 (file)
@@ -17,6 +17,7 @@
   # Rights Reserved.
   #
   # Contributor(s): Myk Melez <myk@mozilla.org>
+  #                 Frédéric Buclin <LpSolit@gmail.com>
   #%]
 
 [%# INTERFACE:
@@ -31,6 +32,8 @@
   #   if they want to add the bug to its new product's group
   # use_target_milestone: boolean; whether or not to use
   #   the target milestone field
+  # old_groups: a list of group objects which are not available
+  #   for the new product.
   #%]
 
 [%# The global Bugzilla->cgi object is used to obtain form variable values. %]
 
 [% END %]
 
-[% IF verify_bug_group %]
+[% IF verify_bug_group || old_groups.size %]
   <h3>Verify [% terms.Bug %] Group</h3>
 
-  <p>
-    Do you want to add the [% terms.bug %] to its new product's default groups (if any)?
-  </p>
+  [% IF old_groups.size %]
+    <p>The following groups are not legal for the <b>[% cgi.param("product") FILTER html %]</b>
+    product or you are not allowed to restrict [% terms.bugs %] to these groups:</p>
+    <ul>
+      [% FOREACH group = old_groups %]
+        <li>[% group.name FILTER html %]: [% group.description FILTER html %]</li>
+      [% END %]
+    </ul>
+    <p><b>[%+ terms.Bugs %] will no longer be restricted to these groups and may become
+    public if no other group applies.</b></p>
+  [% END %]
 
-  <p>
-    <input type="radio" name="addtonewgroup" value="no"><b>no</b><br>
-    <input type="radio" name="addtonewgroup" value="yes"><b>yes</b><br>
-    <input type="radio" name="addtonewgroup" value="yesifinold" checked="checked">
-      <b>yes, but only if the [% terms.bug %] was in any of its old product's default groups</b><br>
-  </p>
+  [% IF verify_bug_group %]
+    <p>
+      This new product has default groups associated to it. Do you want to add the
+      [%+ terms.bug %] to them?<br>
+      <input type="radio" id="add_no" name="addtonewgroup" value="no"><label for="add_no">no</label><br>
+      <input type="radio" id="add_yes" name="addtonewgroup" value="yes"><label for="add_yes">yes</label><br>
+      <input type="radio" id="add_yesifinold" name="addtonewgroup" value="yesifinold" checked="checked">
+        <label for="add_yesifinold">yes, but only if the [% terms.bug %] was in any of
+        its old product's default groups</label>
+    </p>
+  [% END %]
 [% END %]
 
-<input type="submit" id="change_product" value="Commit">
+<p>
+  <input type="submit" id="change_product" value="Commit">
+</p>
 
 </form>
 <hr>