From 497c70791868264ddb0499970ea0323988bdcdb0 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Mon, 13 Apr 2015 12:38:14 +0800 Subject: Bug 1152818: changing an assignee to nobody@mozilla.org or any .bugs address should automatically reset the status to NEW --- Bugzilla/Object.pm | 6 +++- extensions/BMO/Extension.pm | 37 ++++++++++++++++++++++ .../hook/global/user-error-errors.html.tmpl | 5 +++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index 8a7bba1c5..2349b57e6 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -520,7 +520,11 @@ sub update { $dbh->bz_start_transaction(); my $old_self = $self->new($self->id); - + + # BMO - allow altering values in a sane way + Bugzilla::Hook::process('object_start_of_update', + { object => $self, old_object => $old_self }); + my @all_columns = $self->UPDATE_COLUMNS; my @hook_columns; Bugzilla::Hook::process('object_update_columns', diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 52bdd53bc..5472006ed 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -735,6 +735,43 @@ sub bug_end_of_create { } } +# bugs in an ASSIGNED state must be assigned to a real person +# reset bugs to NEW if the assignee is nobody/.bugs$ +sub object_start_of_update { + my ($self, $args) = @_; + my ($new_bug, $old_bug) = @$args{qw( object old_object )}; + return unless $new_bug->isa('Bugzilla::Bug'); + + # if either the assignee or status has changed + return unless + $old_bug->assigned_to->id != $new_bug->assigned_to->id + || $old_bug->bug_status ne $new_bug->bug_status; + + # and the bug is now ASSIGNED + return unless + $new_bug->bug_status eq 'ASSIGNED'; + + # and the assignee isn't a real person + return unless + $new_bug->assigned_to->login eq 'nobody@mozilla.org' + || $new_bug->assigned_to->login =~ /\.bugs$/; + + # and the user can set the status to NEW + return unless + $old_bug->check_can_change_field('bug_status', $old_bug->bug_status, 'NEW'); + + # if the user is changing the assignee, silently change the bug's status to new + if ($old_bug->assigned_to->id != $new_bug->assigned_to->id) { + $new_bug->set_bug_status('NEW'); + } + + # otherwise the user is trying to set the bug's status to ASSIGNED without + # assigning a real person. throw an error. + else { + ThrowUserError('bug_status_unassigned'); + } +} + # detect github pull requests and reviewboard reviews, set the content-type sub attachment_process_data { my ($self, $args) = @_; diff --git a/extensions/BMO/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/BMO/template/en/default/hook/global/user-error-errors.html.tmpl index 9caf9bd29..a8be3663f 100644 --- a/extensions/BMO/template/en/default/hook/global/user-error-errors.html.tmpl +++ b/extensions/BMO/template/en/default/hook/global/user-error-errors.html.tmpl @@ -41,4 +41,9 @@ [% title = "Missing Reporter" %] You must provide an email address for a bounty attachment. +[% ELSIF error == "bug_status_unassigned" %] + [% title = "Invalid Bug Status" %] + You cannot set this [% terms.bug %]'s status to ASSIGNED because the + [%+ terms.bug %] is not assigned to a person. + [% END %] -- cgit v1.2.3-24-g4f1b