Commit 4671e0ff authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 512618: Make Bugzilla::Bug::choices return Field::Choice objects, not just values

Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit
parent 6e282d38
...@@ -2108,6 +2108,7 @@ sub set_resolution { ...@@ -2108,6 +2108,7 @@ sub set_resolution {
my $old_res = $self->resolution; my $old_res = $self->resolution;
$self->set('resolution', $value); $self->set('resolution', $value);
delete $self->{choices};
my $new_res = $self->resolution; my $new_res = $self->resolution;
if ($new_res ne $old_res) { if ($new_res ne $old_res) {
...@@ -2899,38 +2900,38 @@ sub user { ...@@ -2899,38 +2900,38 @@ sub user {
return $self->{'user'}; return $self->{'user'};
} }
# This is intended to get values that can be selected by the user in the
# UI. It should not be used for security or validation purposes.
sub choices { sub choices {
my $self = shift; my $self = shift;
return $self->{'choices'} if exists $self->{'choices'}; return $self->{'choices'} if exists $self->{'choices'};
return {} if $self->{'error'}; return {} if $self->{'error'};
my $user = Bugzilla->user;
$self->{'choices'} = {}; my @products = @{ $user->get_enterable_products };
my @prodlist = map {$_->name} @{Bugzilla->user->get_enterable_products};
# The current product is part of the popup, even if new bugs are no longer # The current product is part of the popup, even if new bugs are no longer
# allowed for that product # allowed for that product
if (lsearch(\@prodlist, $self->product) < 0) { if (!grep($_->name eq $self->product_obj->name, @products)) {
push(@prodlist, $self->product); unshift(@products, $self->product_obj);
@prodlist = sort @prodlist; }
}
my %choices = (
# Hack - this array contains "". See bug 106589. product => \@products,
my @res = grep ($_, @{get_legal_field_values('resolution')}); component => $self->product_obj->components,
version => $self->product_obj->versions,
$self->{'choices'} = target_milestone => $self->product_obj->milestones,
{ );
'product' => \@prodlist,
'rep_platform' => get_legal_field_values('rep_platform'), my $resolution_field = new Bugzilla::Field({ name => 'resolution' });
'priority' => get_legal_field_values('priority'), # Don't include the empty resolution in drop-downs.
'bug_severity' => get_legal_field_values('bug_severity'), my @resolutions = grep($_->name, @{ $resolution_field->legal_values });
'op_sys' => get_legal_field_values('op_sys'), # And don't include MOVED in the list unless the bug is already MOVED.
'bug_status' => get_legal_field_values('bug_status'), if ($self->resolution ne 'MOVED') {
'resolution' => \@res, @resolutions= grep { $_->name ne 'MOVED' } @resolutions;
'component' => [map($_->name, @{$self->product_obj->components})], }
'version' => [map($_->name, @{$self->product_obj->versions})], $choices{'resolution'} = \@resolutions;
'target_milestone' => [map($_->name, @{$self->product_obj->milestones})],
};
$self->{'choices'} = \%choices;
return $self->{'choices'}; return $self->{'choices'};
} }
......
...@@ -375,16 +375,9 @@ ...@@ -375,16 +375,9 @@
[%#############%] [%#############%]
<tr> <tr>
[% IF bug.check_can_change_field('product', 0, 1) %]
[% prod_list = user.get_enterable_products %]
[% IF NOT user.can_enter_product(bug.product) %]
[% prod_list.unshift(bug.product_obj) %]
[% END %]
[% END %]
[% INCLUDE bug/field.html.tmpl [% INCLUDE bug/field.html.tmpl
bug = bug, field = select_fields.product, bug = bug, field = select_fields.product,
override_legal_values = prod_list override_legal_values = bug.choices.product
desc_url = 'describecomponents.cgi', value = bug.product desc_url = 'describecomponents.cgi', value = bug.product
editable = bug.check_can_change_field('product', 0, 1) %] editable = bug.check_can_change_field('product', 0, 1) %]
</tr> </tr>
...@@ -1112,24 +1105,21 @@ ...@@ -1112,24 +1105,21 @@
[%############################################################################%] [%############################################################################%]
[% BLOCK select %] [% BLOCK select %]
[% IF NOT no_td %]
<td> <td>
[% END %] [% IF bug.check_can_change_field(selname, 0, 1)
[% IF bug.check_can_change_field(selname, 0, 1) AND bug.choices.${selname}.size > 1 %] AND bug.choices.${selname}.size > 1 %]
<select id="[% selname %]" name="[% selname %]"> <select id="[% selname %]" name="[% selname %]">
[% FOREACH x = bug.choices.${selname} %] [% FOREACH x = bug.choices.${selname} %]
<option value="[% x FILTER html %]" <option value="[% x.name FILTER html %]"
[% " selected" IF x == bug.${selname} %]>[% x FILTER html %] [% " selected" IF x.name == bug.${selname} %]>
[%- x.name FILTER html %]
</option> </option>
[% END %] [% END %]
</select> </select>
[% ELSE %] [% ELSE %]
[% bug.${selname} FILTER html %] [% bug.${selname} FILTER html %]
[% END %] [% END %]
[% IF NOT no_td %]
</td> </td>
[% END %]
[% no_td = 0 %]
[% END %] [% END %]
[%############################################################################%] [%############################################################################%]
......
...@@ -147,10 +147,9 @@ ...@@ -147,10 +147,9 @@
[% BLOCK select_resolution %] [% BLOCK select_resolution %]
<select name="resolution" id="resolution"> <select name="resolution" id="resolution">
[% FOREACH r = bug.choices.resolution %] [% FOREACH r = bug.choices.resolution %]
[% NEXT IF r == "MOVED" && bug.resolution != "MOVED" %] <option value="[% r.name FILTER html %]"
<option value="[% r FILTER html %]" [% ' selected="selected"' IF r.name == bug.resolution %]>
[% "selected" IF r == bug.resolution %]> [% display_value("resolution", r.name) FILTER html %]</option>
[% display_value("resolution", r) FILTER html %]</option>
[% END %] [% END %]
</select> </select>
[% END %] [% END %]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment