From 1edaea9bb57e45d543755a235840bd7cf0dcc815 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sat, 11 Jun 2005 05:57:16 +0000 Subject: Bug 266159: It's possible to create multiple flags by reloading, even if flag is not multiplicable - Patch by Frédéric Buclin r/a = myk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Flag.pm | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'Bugzilla/Flag.pm') diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm index 8e03284d0..10cbcd0d0 100644 --- a/Bugzilla/Flag.pm +++ b/Bugzilla/Flag.pm @@ -680,7 +680,8 @@ sub clear { =item Cdbh; + # Extract a list of flag type IDs from field names. my @type_ids = map(/^flag_type-(\d+)$/ ? $1 : (), $cgi->param()); @type_ids = grep($cgi->param("flag_type-$_") ne 'X', @type_ids); - - # Process the form data and create an array of flag objects. + + return () unless (scalar(@type_ids) && $target->{'exists'}); + + # Get information about the setter to add to each flag. + my $setter = new Bugzilla::User($::userid); + + # Get a list of active flag types available for this target. + my $flag_types = Bugzilla::FlagType::match( + { 'target_type' => $target->{'type'}, + 'product_id' => $target->{'product_id'}, + 'component_id' => $target->{'component_id'}, + 'is_active' => 1 }); + my @flags; - foreach my $type_id (@type_ids) { + foreach my $flag_type (@$flag_types) { + my $type_id = $flag_type->{'id'}; + + # We are only interested in flags the user tries to create. + next unless scalar(grep { $_ == $type_id } @type_ids); + + # Get the number of active flags of this type already set for this target. + my $has_flags = count( + { 'type_id' => $type_id, + 'target_type' => $target->{'type'}, + 'bug_id' => $target->{'bug'}->{'id'}, + 'attach_id' => $target->{'attachment'}->{'id'}, + 'is_active' => 1 }); + + # Do not create a new flag of this type if this flag type is + # not multiplicable and already has an active flag set. + next if (!$flag_type->{'is_multiplicable'} && $has_flags); + my $status = $cgi->param("flag_type-$type_id"); - &::trick_taint($status); + trick_taint($status); # Create the flag record and populate it with data from the form. my $flag = { - type => Bugzilla::FlagType::get($type_id) , + type => $flag_type , target => $target , setter => $setter , status => $status -- cgit v1.2.3-24-g4f1b