From 7ca399bb298bc7912514231883561190e5660e37 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" Date: Fri, 10 Jun 2005 22:57:16 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20266159:=20It's=20possible=20to=20create?= =?UTF-8?q?=20multiple=20flags=20by=20reloading,=20even=20if=20flag=20is?= =?UTF-8?q?=20not=20multiplicable=20-=20Patch=20by=20Fr=EF=BF=BDd=EF=BF=BD?= =?UTF-8?q?ric=20Buclin=20=20r/a=20=3D=20myk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webtools/bugzilla/Bugzilla/Flag.pm | 47 +++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/webtools/bugzilla/Bugzilla/Flag.pm b/webtools/bugzilla/Bugzilla/Flag.pm index 8e03284d051..10cbcd0d078 100644 --- a/webtools/bugzilla/Bugzilla/Flag.pm +++ b/webtools/bugzilla/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