From 1a4d88f3293090175276c9b81cfe6727483f7ae8 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sun, 10 Sep 2006 09:20:24 +0000 Subject: Bug 351332: Move Group validation into Bugzilla::Bug from post_bug.cgi Patch By Max Kanat-Alexander r=LpSolit, a=justdave --- Bugzilla/Bug.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 6e8079d27..46b247425 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -521,6 +521,52 @@ sub _check_estimated_time { return $_[0]->_check_time($_[1], 'estimated_time'); } +sub _check_groups { + my ($invocant, $product, $group_ids) = @_; + + my $user = Bugzilla->user; + + my %add_groups; + my $controls = $product->group_controls; + + foreach my $id (@$group_ids) { + my $group = new Bugzilla::Group($id) + || ThrowUserError("invalid_group_ID"); + + # This can only happen if somebody hacked the enter_bug form. + ThrowCodeError("inactive_group", { name => $group->name }) + unless $group->is_active; + + my $membercontrol = $controls->{$id} + && $controls->{$id}->{membercontrol}; + my $othercontrol = $controls->{$id} + && $controls->{$id}->{othercontrol}; + + my $permit = ($membercontrol && $user->in_group($group->name)) + || $othercontrol; + + $add_groups{$id} = 1 if $permit; + } + + foreach my $id (keys %$controls) { + next unless $controls->{$id}->{isactive}; + my $membercontrol = $controls->{$id}->{membercontrol} || 0; + my $othercontrol = $controls->{$id}->{othercontrol} || 0; + + # Add groups required + if ($membercontrol == CONTROLMAPMANDATORY + || ($othercontrol == CONTROLMAPMANDATORY + && !$user->in_group_id($id))) + { + # User had no option, bug needs to be in this group. + $add_groups{$id} = 1; + } + } + + my @add_groups = keys %add_groups; + return \@add_groups; +} + sub _check_keywords { my ($invocant, $keyword_string) = @_; $keyword_string = trim($keyword_string); -- cgit v1.2.3-24-g4f1b