Commit 80c5b6fa authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 344964: enter_bug.cgi should look at the custom status workflow to get the…

Bug 344964: enter_bug.cgi should look at the custom status workflow to get the valid initial bug statuses - Patch by Fré©ric Buclin <LpSolit@gmail.com> r=gerv a=justdave
parent 836b976e
...@@ -170,14 +170,6 @@ use constant MAX_LINE_LENGTH => 254; ...@@ -170,14 +170,6 @@ use constant MAX_LINE_LENGTH => 254;
# Used in ValidateComment(). Gives the max length allowed for a comment. # Used in ValidateComment(). Gives the max length allowed for a comment.
use constant MAX_COMMENT_LENGTH => 65535; use constant MAX_COMMENT_LENGTH => 65535;
# The statuses that are valid on enter_bug.cgi and post_bug.cgi.
# The order is important--see _check_bug_status
use constant VALID_ENTRY_STATUS => qw(
UNCONFIRMED
NEW
ASSIGNED
);
use constant SPECIAL_STATUS_WORKFLOW_ACTIONS => qw( use constant SPECIAL_STATUS_WORKFLOW_ACTIONS => qw(
none none
duplicate duplicate
...@@ -593,38 +585,38 @@ sub _check_bug_status { ...@@ -593,38 +585,38 @@ sub _check_bug_status {
my ($invocant, $status, $product) = @_; my ($invocant, $status, $product) = @_;
my $user = Bugzilla->user; my $user = Bugzilla->user;
my %valid_statuses; my @valid_statuses;
if (ref $invocant) { if (ref $invocant) {
$invocant->{'prod_obj'} ||= $invocant->{'prod_obj'} ||=
new Bugzilla::Product({name => $invocant->product}); new Bugzilla::Product({name => $invocant->product});
$product = $invocant->{'prod_obj'}; $product = $invocant->{'prod_obj'};
my $field = new Bugzilla::Field({ name => 'bug_status' }); @valid_statuses = map { $_->name } @{$invocant->status->can_change_to};
%valid_statuses = map { $_ => 1 } @{$field->legal_values};
} }
else { else {
%valid_statuses = map { $_ => 1 } VALID_ENTRY_STATUS; @valid_statuses = map { $_->name } @{Bugzilla::Status->can_change_to()};
}
if (!$product->votes_to_confirm) {
# UNCONFIRMED becomes an invalid status if votes_to_confirm is 0,
# even if you are in editbugs.
@valid_statuses = grep {$_ ne 'UNCONFIRMED'} @valid_statuses;
}
if (!ref($invocant)) {
if ($user->in_group('editbugs', $product->id) if ($user->in_group('editbugs', $product->id)
|| $user->in_group('canconfirm', $product->id)) { || $user->in_group('canconfirm', $product->id)) {
# Default to NEW if the user with privs hasn't selected another # If the user with privs hasn't selected another status,
# status. # select the first one of the list.
$status ||= 'NEW'; $status ||= $valid_statuses[0];
}
elsif (!$product->votes_to_confirm) {
# Without privs, products that don't support UNCONFIRMED default
# to NEW.
$status = 'NEW';
} }
else { else {
$status = 'UNCONFIRMED'; # A user with no privs cannot choose the initial status.
$status = $valid_statuses[0];
} }
} }
# UNCONFIRMED becomes an invalid status if votes_to_confirm is 0, # This check already takes the workflow into account.
# even if you are in editbugs. check_field('bug_status', $status, \@valid_statuses);
delete $valid_statuses{'UNCONFIRMED'} if !$product->votes_to_confirm;
check_field('bug_status', $status, [keys %valid_statuses]);
return $status if ref $invocant; return $status if ref $invocant;
return ($status, $status eq 'UNCONFIRMED' ? 0 : 1); return ($status, $status eq 'UNCONFIRMED' ? 0 : 1);
......
...@@ -58,14 +58,25 @@ sub can_change_to { ...@@ -58,14 +58,25 @@ sub can_change_to {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
if (!defined $self->{'can_change_to'}) { if (!ref($self) || !defined $self->{'can_change_to'}) {
my $new_status_ids = $dbh->selectcol_arrayref('SELECT new_status my ($cond, @args);
if (ref($self)) {
$cond = '= ?';
push(@args, $self->id);
}
else {
$cond = 'IS NULL';
# Let's do it so that the code below works in all cases.
$self = {};
}
my $new_status_ids = $dbh->selectcol_arrayref("SELECT new_status
FROM status_workflow FROM status_workflow
INNER JOIN bug_status INNER JOIN bug_status
ON id = new_status ON id = new_status
WHERE isactive = 1 WHERE isactive = 1
AND old_status = ?', AND old_status $cond",
undef, $self->id); undef, @args);
$self->{'can_change_to'} = Bugzilla::Status->new_from_list($new_status_ids); $self->{'can_change_to'} = Bugzilla::Status->new_from_list($new_status_ids);
} }
......
...@@ -49,6 +49,7 @@ use Bugzilla::Classification; ...@@ -49,6 +49,7 @@ use Bugzilla::Classification;
use Bugzilla::Keyword; use Bugzilla::Keyword;
use Bugzilla::Token; use Bugzilla::Token;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Status;
my $user = Bugzilla->login(LOGIN_REQUIRED); my $user = Bugzilla->login(LOGIN_REQUIRED);
...@@ -494,29 +495,24 @@ if ( Bugzilla->params->{'usetargetmilestone'} ) { ...@@ -494,29 +495,24 @@ if ( Bugzilla->params->{'usetargetmilestone'} ) {
} }
# Construct the list of allowable statuses. # Construct the list of allowable statuses.
# my $initial_statuses = Bugzilla::Status->can_change_to();
# * If the product requires votes to confirm: # Exclude closed states from the UI, even if the workflow allows them.
# users with privs : NEW + ASSI + UNCO # The back-end code will still accept them, though.
# users with no privs: UNCO @$initial_statuses = grep { $_->is_open } @$initial_statuses;
#
# * If the product doesn't require votes to confirm: my @status = map { $_->name } @$initial_statuses;
# users with privs : NEW + ASSI # UNCONFIRMED is illegal if votes_to_confirm = 0.
# users with no privs: NEW (as these users cannot reassign @status = grep {$_ ne 'UNCONFIRMED'} @status unless $product->votes_to_confirm;
# bugs to them, it doesn't make sense scalar(@status) || ThrowUserError('no_initial_bug_status');
# to let them mark bugs as ASSIGNED)
# If the user has no privs...
my @status; unless ($has_editbugs || $has_canconfirm) {
if ($has_editbugs || $has_canconfirm) { # ... use UNCONFIRMED if available, else use the first status of the list.
@status = ('NEW', 'ASSIGNED'); my $bug_status = (grep {$_ eq 'UNCONFIRMED'} @status) ? 'UNCONFIRMED' : $status[0];
} @status = ($bug_status);
elsif (!$product->votes_to_confirm) {
@status = ('NEW');
}
if ($product->votes_to_confirm) {
push(@status, 'UNCONFIRMED');
} }
$vars->{'bug_status'} = \@status; $vars->{'bug_status'} = \@status;
# Get the default from a template value if it is legitimate. # Get the default from a template value if it is legitimate.
# Otherwise, set the default to the first item on the list. # Otherwise, set the default to the first item on the list.
......
...@@ -1084,6 +1084,11 @@ ...@@ -1084,6 +1084,11 @@
and an error and an error
occurred opening yesterday's dupes file: [% error_msg FILTER html %]. occurred opening yesterday's dupes file: [% error_msg FILTER html %].
[% ELSIF error == "no_initial_bug_status" %]
[% title = "No Initial $terms.Bug Status" %]
No [% terms.bug %] status is available on [% terms.bug %] creation.
Please report the problem to [% Param("maintainer") %].
[% ELSIF error == "no_new_quips" %] [% ELSIF error == "no_new_quips" %]
[% title = "No New Quips" %] [% title = "No New Quips" %]
[% admindocslinks = {'quips.html' => 'Controlling quip usage'} %] [% admindocslinks = {'quips.html' => 'Controlling quip usage'} %]
......
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