From 7d308032e344edec643ab1a1345ac7af7b0962fe Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Sat, 22 May 2010 22:11:23 -0700 Subject: Bug 556403: Move adding/removing of CCs from process_bug.cgi into Bugzilla::Bug::set_all --- Bugzilla/Bug.pm | 29 ++++++++++++++---------- process_bug.cgi | 68 +++++++++++++++++++++++++++------------------------------ 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index c1f4dc12f..939829cc5 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -1892,12 +1892,7 @@ sub set_all { # strict_isolation checks mean that we should set the groups # immediately after changing the product. - foreach my $group (@{ $params->{groups}->{add} || [] }) { - $self->add_group($group); - } - foreach my $group (@{ $params->{groups}->{remove} || [] }) { - $self->remove_group($group); - } + $self->_add_remove($params, 'groups'); if (exists $params->{'dependson'} or exists $params->{'blocked'}) { my %set_deps; @@ -1953,12 +1948,7 @@ sub set_all { $self->reset_assigned_to if $params->{'reset_assigned_to'}; $self->reset_qa_contact if $params->{'reset_qa_contact'}; - foreach my $url (@{ $params->{see_also}->{add} || [] }) { - $self->add_see_also($url); - } - foreach my $url (@{ $params->{see_also}->{remove} || [] }) { - $self->remove_see_also($url); - } + $self->_add_remove($params, 'see_also'); # And set custom fields. my @custom_fields = Bugzilla->active_custom_fields; @@ -1968,6 +1958,21 @@ sub set_all { $self->set_custom_field($field, $params->{$fname}); } } + + $self->_add_remove($params, 'cc'); +} + +# Helper for set_all that helps with fields that have an "add/remove" +# pattern instead of a "set_" pattern. +sub _add_remove { + my ($self, $params, $name) = @_; + my @add = @{ $params->{$name}->{add} || [] }; + my @remove = @{ $params->{$name}->{remove} || [] }; + $name =~ s/s$//; + my $add_method = "add_$name"; + my $remove_method = "remove_$name"; + $self->$add_method($_) foreach @add; + $self->$remove_method($_) foreach @remove; } sub set_alias { $_[0]->set('alias', $_[1]); } diff --git a/process_bug.cgi b/process_bug.cgi index 3330a6803..d2ba976a8 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -309,6 +309,38 @@ foreach my $dep_field (qw(dependson blocked)) { } } } +# Formulate the CC data into two arrays of users involved in this CC change. +my (@cc_add, @cc_remove); +if (defined $cgi->param('newcc') + or defined $cgi->param('addselfcc') + or defined $cgi->param('removecc') + or defined $cgi->param('masscc')) +{ + + # If masscc is defined, then we came from buglist and need to either add or + # remove cc's... otherwise, we came from show_bug and may need to do both. + my ($cc_add, $cc_remove) = ""; + if (defined $cgi->param('masscc')) { + if ($cgi->param('ccaction') eq 'add') { + $cc_add = $cgi->param('masscc'); + } elsif ($cgi->param('ccaction') eq 'remove') { + $cc_remove = $cgi->param('masscc'); + } + } else { + $cc_add = $cgi->param('newcc'); + # We came from bug_form which uses a select box to determine what cc's + # need to be removed... + if ($cgi->param('removecc') && $cgi->param('cc')) { + $cc_remove = join(",", $cgi->param('cc')); + } + } + + push(@cc_add, split(/[\s,]+/, $cc_add)) if $cc_add; + push(@cc_add, Bugzilla->user) if $cgi->param('addselfcc'); + + push(@cc_remove, split(/[\s,]+/, $cc_remove)) if $cc_remove; +} +$set_all_fields{cc} = { add => \@cc_add, remove => \@cc_remove }; # Fields that can only be set on one bug at a time. if (defined $cgi->param('id')) { @@ -370,43 +402,7 @@ if (defined $cgi->param('id')) { $first_bug->set_flags($flags, $new_flags); } -# We need to check the addresses involved in a CC change before we touch -# any bugs. What we'll do here is formulate the CC data into two arrays of -# users involved in this CC change. Then those arrays can be used later -# on for the actual change. -my (@cc_add, @cc_remove); -if (defined $cgi->param('newcc') - || defined $cgi->param('addselfcc') - || defined $cgi->param('removecc') - || defined $cgi->param('masscc')) { - - # If masscc is defined, then we came from buglist and need to either add or - # remove cc's... otherwise, we came from bugform and may need to do both. - my ($cc_add, $cc_remove) = ""; - if (defined $cgi->param('masscc')) { - if ($cgi->param('ccaction') eq 'add') { - $cc_add = join(' ',$cgi->param('masscc')); - } elsif ($cgi->param('ccaction') eq 'remove') { - $cc_remove = join(' ',$cgi->param('masscc')); - } - } else { - $cc_add = join(' ',$cgi->param('newcc')); - # We came from bug_form which uses a select box to determine what cc's - # need to be removed... - if (defined $cgi->param('removecc') && $cgi->param('cc')) { - $cc_remove = join (",", $cgi->param('cc')); - } - } - - push(@cc_add, split(/[\s,]+/, $cc_add)) if $cc_add; - push(@cc_add, Bugzilla->user) if $cgi->param('addselfcc'); - - push(@cc_remove, split(/[\s,]+/, $cc_remove)) if $cc_remove; -} - foreach my $b (@bug_objects) { - $b->remove_cc($_) foreach @cc_remove; - $b->add_cc($_) foreach @cc_add; # Theoretically you could move a product without ever specifying # a new assignee or qa_contact, or adding/removing any CCs. So, # we have to check that the current assignee, qa, and CCs are still -- cgit v1.2.3-24-g4f1b