]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 494403: "Default" groups don't get set on bug creation using email_in.pl
authorFrédéric Buclin <LpSolit@gmail.com>
Wed, 17 Feb 2010 21:39:28 +0000 (22:39 +0100)
committerFrédéric Buclin <LpSolit@gmail.com>
Wed, 17 Feb 2010 21:39:28 +0000 (22:39 +0100)
r/a=mkanat

email_in.pl

index c7b11d8a720a6db855382919cda5906d086ccbb1..7f2b2f6e4d8c64cbbd004189944615c01f10a862 100755 (executable)
@@ -47,7 +47,7 @@ use Bugzilla;
 use Bugzilla::Attachment;
 use Bugzilla::Bug;
 use Bugzilla::BugMail;
-use Bugzilla::Constants qw(USAGE_MODE_EMAIL CMT_ATTACHMENT_CREATED);
+use Bugzilla::Constants;
 use Bugzilla::Error;
 use Bugzilla::Mailer;
 use Bugzilla::Token;
@@ -145,6 +145,8 @@ sub post_bug {
     my ($fields) = @_;
     debug_print('Posting a new bug...');
 
+    my $user = Bugzilla->user;
+
     # Bugzilla::Bug->create throws a confusing CodeError if
     # the REQUIRED_CREATE_FIELDS are missing, but much more
     # sensible errors if the fields exist but are just undef.
@@ -152,6 +154,25 @@ sub post_bug {
         $fields->{$field} = undef if !exists $fields->{$field};
     }
 
+    # Restrict the bug to groups marked as Default.
+    # We let Bug->create throw an error if the product is
+    # not accessible, to throw the correct message.
+    my $product = new Bugzilla::Product({ name => $fields->{product} });
+    if ($product) {
+        my @gids;
+        my $controls = $product->group_controls;
+        foreach my $gid (keys %$controls) {
+            if (($controls->{$gid}->{membercontrol} == CONTROLMAPDEFAULT
+                 && $user->in_group_id($gid))
+                || ($controls->{$gid}->{othercontrol} == CONTROLMAPDEFAULT
+                    && !$user->in_group_id($gid)))
+            {
+                push(@gids, $gid);
+            }
+        }
+        $fields->{groups} = \@gids;
+    }
+
     my ($retval, $non_conclusive_fields) =
       Bugzilla::User::match_field({
         'assigned_to'   => { 'type' => 'single' },