From: Max Kanat-Alexander Date: Fri, 25 Jun 2010 21:16:27 +0000 (-0700) Subject: Bug 573173: Make Bugzilla::Bug's add_group and remove_group take group X-Git-Tag: bugzilla-3.7.2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d39e7b417190ad672219768eab41d627cc68bb9;p=thirdparty%2Fbugzilla.git Bug 573173: Make Bugzilla::Bug's add_group and remove_group take group names instead of ids r=dkl, a=mkanat --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 58901c57ec..ea8e4bc3d1 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -2682,8 +2682,7 @@ sub add_group { my ($self, $group) = @_; # Invalid ids are silently ignored. (We can't tell people whether # or not a group exists.) - $group = new Bugzilla::Group($group) unless ref $group; - return unless $group; + $group = Bugzilla::Group->check($group) if !blessed $group; return if !$group->is_active or !$group->is_bug_group; @@ -2691,7 +2690,7 @@ sub add_group { # to this group by the current user. $self->product_obj->group_is_settable($group) || ThrowUserError('group_invalid_restriction', - { product => $self->product, group_id => $group->id, + { product => $self->product, group => $group, bug => $self }); # OtherControl people can add groups only during a product change, @@ -2702,7 +2701,7 @@ sub add_group { || $controls->{othercontrol} == CONTROLMAPNA) { ThrowUserError('group_change_denied', - { bug => $self, group_id => $group->id }); + { bug => $self, group => $group }); } } @@ -2714,8 +2713,7 @@ sub add_group { sub remove_group { my ($self, $group) = @_; - $group = new Bugzilla::Group($group) unless ref $group; - return unless $group; + $group = Bugzilla::Group->check($group) if !blessed $group; # First, check if this is a valid group for this product. # You can *always* remove a group that is not valid for this product @@ -2731,7 +2729,7 @@ sub remove_group { # Nobody can ever remove a Mandatory group. if ($controls->{membercontrol} == CONTROLMAPMANDATORY) { ThrowUserError('group_invalid_removal', - { product => $self->product, group_id => $group->id, + { product => $self->product, group => $group, bug => $self }); } @@ -2743,7 +2741,7 @@ sub remove_group { || $controls->{othercontrol} == CONTROLMAPNA) { ThrowUserError('group_change_denied', - { bug => $self, group_id => $group->id }); + { bug => $self, group => $group }); } } } diff --git a/process_bug.cgi b/process_bug.cgi index 7759d03dcf..f6da2af611 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -337,27 +337,10 @@ foreach my $field (grep(/^defined_isprivate/, $cgi->param())) { } $set_all_fields{comment_is_private} = \%is_private; -my %groups = ( add => [], remove => [] ); -my %checked_bit; # Used to avoid adding groups twice (defined_ + actual bit-) -foreach my $param_name (grep(/bit-\d+$/, $cgi->param())) { - $param_name =~ /bit-(\d+)$/; - my $gid = $1; - next if $checked_bit{$gid}; - my $bit_param = "bit-$gid"; - if (should_set($bit_param, 1)) { - # Check ! first to avoid having to check defined below. - if (!$cgi->param($bit_param)) { - push(@{ $groups{remove} }, $gid); - } - # "== 1" is important because mass-change uses -1 to mean - # "don't change this restriction" - elsif ($cgi->param($bit_param) == 1) { - push(@{ $groups{add} }, $gid); - } - } - $checked_bit{$gid} = 1; -} -$set_all_fields{groups} = \%groups; +my @check_groups = $cgi->param('defined_groups'); +my @set_groups = $cgi->param('groups'); +my ($removed_groups) = diff_arrays(\@check_groups, \@set_groups); +$set_all_fields{groups} = { add => \@set_groups, remove => $removed_groups }; my @custom_fields = Bugzilla->active_custom_fields; foreach my $field (@custom_fields) { diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 479e67c1e8..0ef3cba8f4 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -654,14 +654,15 @@ [% END %] [% IF group.ingroup %] - + [% END %] - -