Move flag reminders to core, make clear_requests_on_close work (it was using a non-existing user pref!)

hinted-selects
Vitaliy Filippov 2014-08-18 18:07:34 +04:00
parent 89a565f437
commit d235711747
9 changed files with 112 additions and 111 deletions

View File

@ -2768,7 +2768,7 @@ sub modify_keywords
{
if ($action eq 'add')
{
push @$keywords, map { $_->name } $self->get_object('keywords');
push @$keywords, map { $_->name } @{$self->get_object('keywords')};
}
$self->set('keywords', {
keywords => join(', ', @$keywords),

View File

@ -86,6 +86,14 @@ sub get_param_list
checker => \&check_bug_status,
},
{
name => 'closed_bug_status',
type => 's',
choices => \@closed_bug_statuses,
default => 'CLOSED',
checker => \&check_bug_status,
},
{
name => 'duplicate_resolution',
type => 's',
@ -142,12 +150,6 @@ sub get_param_list
default => 1,
},
{
name => 'clear_requests_on_close',
type => 'b',
default => 1,
},
{
name => 'unauth_bug_details',
type => 'b',

View File

@ -818,7 +818,7 @@ array of hashes. This array is then passed to Flag::create().
sub extract_flags_from_cgi {
my ($class, $bug, $attachment, $vars, $skip) = @_;
my $cgi = Bugzilla->cgi;
my $ARGS = Bugzilla->input_params;
my $match_status = Bugzilla::User::match_field({
'^requestee(_type)?-(\d+)$' => { 'type' => 'multi' },
@ -833,11 +833,11 @@ sub extract_flags_from_cgi {
}
# Extract a list of flag type IDs from field names.
my @flagtype_ids = map(/^flag_type-(\d+)$/ ? $1 : (), $cgi->param());
@flagtype_ids = grep($cgi->param("flag_type-$_") ne 'X', @flagtype_ids);
my @flagtype_ids = map(/^flag_type-(\d+)$/ ? $1 : (), keys %$ARGS);
@flagtype_ids = grep($ARGS->{"flag_type-$_"} ne 'X', @flagtype_ids);
# Extract a list of existing flag IDs.
my @flag_ids = map(/^flag-(\d+)$/ ? $1 : (), $cgi->param());
my @flag_ids = map(/^flag-(\d+)$/ ? $1 : (), keys %$ARGS);
return () if (!scalar(@flagtype_ids) && !scalar(@flag_ids));
@ -847,13 +847,13 @@ sub extract_flags_from_cgi {
# If the flag no longer exists, ignore it.
next unless $flag;
my $status = $cgi->param("flag-$flag_id");
my $status = $ARGS->{"flag-$flag_id"};
# If the user entered more than one name into the requestee field
# (i.e. they want more than one person to set the flag) we can reuse
# the existing flag for the first person (who may well be the existing
# requestee), but we have to create new flags for each additional requestee.
my @requestees = $cgi->param("requestee-$flag_id");
my @requestees = list $ARGS->{"requestee-$flag_id"};
Bugzilla::Hook::process('flag_check_requestee_list', { flag => $flag, status => $status, requestees => \@requestees, skip => $skip });
@ -877,7 +877,7 @@ sub extract_flags_from_cgi {
# If there are several requestees and the flag type is not multiplicable,
# this will fail. But that's the job of the validator to complain. All
# we do here is to extract and convert data from the CGI.
$requestee_email = trim($cgi->param("requestee-$flag_id") || '');
$requestee_email = join ', ', @requestees;
}
push(@flags, { id => $flag_id,
@ -921,10 +921,10 @@ sub extract_flags_from_cgi {
# not multiplicable and already has a flag set.
next if (!$flag_type->is_multiplicable && $has_flags);
my $status = $cgi->param("flag_type-$type_id");
my $status = $ARGS->{"flag_type-$type_id"};
trick_taint($status);
my @logins = $cgi->param("requestee_type-$type_id");
my @logins = list $ARGS->{"requestee_type-$type_id"};
Bugzilla::Hook::process('flag_check_requestee_list', {
flag_type => $flag_type,
@ -952,6 +952,89 @@ sub extract_flags_from_cgi {
return (\@flags, \@new_flags);
}
# Remind about flag requests during process_bug.cgi
sub show_flag_reminders
{
my ($bug_objects) = @_;
my $ARGS = Bugzilla->input_params;
my $single = @$bug_objects == 1;
my $CLOSED = Bugzilla->params->{closed_bug_status};
my $clear_on_close = $ARGS->{bug_status} eq $CLOSED &&
Bugzilla->user->settings->{clear_requests_on_close}->{value} eq 'on';
my $verify_flags = $single &&
Bugzilla->usage_mode != USAGE_MODE_EMAIL &&
Bugzilla->user->wants_request_reminder;
my $reset_own_flags = $verify_flags && $ARGS->{comment} !~ /^\s*$/so;
if (($clear_on_close || $reset_own_flags) && !$ARGS->{force_flags})
{
my $flags;
my @requery_flags;
my $flag;
my $login;
# 1) Check flag requests and remind user about resetting his own incoming requests.
# 2) When closing bugs, clear all flag requests (CustIS Bug 68430).
for my $bug (@$bug_objects)
{
my $clear_this = $clear_on_close && $bug->{_old_self}->bug_status_obj->name ne $CLOSED;
next if !$clear_this && !$reset_own_flags;
if ($single)
{
for (keys %$ARGS)
{
if (/^(flag-(\d+))$/)
{
$flag = Bugzilla::Flag->new({ id => $2 });
$flag->{status} = $ARGS->{$_};
if (($login = trim($ARGS->{"requestee-".$flag->{id}})) &&
($login = login_to_id($login)))
{
$flag->{requestee_id} = $login;
}
push @$flags, $flag;
}
}
}
else
{
$flags = Bugzilla::Flag->match({ bug_id => $bug->id });
}
foreach $flag (@$flags)
{
if ($flag->{status} eq '?' &&
($clear_this || $flag->{requestee_id} eq Bugzilla->user->id))
{
if ($clear_this)
{
$flag->{status} = 'X';
}
if ($verify_flags)
{
push @requery_flags, $flag;
delete $ARGS->{'flag-'.$flag->{id}};
}
elsif ($single)
{
$ARGS->{'flag-'.$flag->{id}} = 'X';
}
else
{
Bugzilla::Flag->set_flag($bug, $flag);
}
}
}
if ($verify_flags && @requery_flags)
{
my $vars = { verify_flags => [ @requery_flags ] };
Bugzilla->template->process("bug/process/verify-flags.html.tmpl", $vars)
|| ThrowTemplateError(Bugzilla->template->error());
exit;
}
}
}
}
=pod
=over

View File

@ -80,6 +80,8 @@ use constant SETTINGS => {
comment_width => { options => ['off', 'on'], default => 'off' },
# CustIS Bug 138596 - Choose whether to hide long comments by default
preview_long_comments => { options => ['off', 'on'], default => 'off' },
# Clear all flag requests when changing bug status to 'closed_bug_status' parameter
clear_requests_on_close => { options => ['off', 'on'], default => 'off' },
};
# Initial system groups.

View File

@ -211,6 +211,7 @@ $Bugzilla::messages->{en} = {
'all' => 'All',
'comment_width' => 'Show comments in the full screen width',
'preview_long_comments' => 'Fold long comments',
'clear_requests_on_close' => 'Clear flag requests when closing bugs',
},
system_groups => {
admin => 'Administrator group. Usually allows to access <b>all</b> administrative functions.',

View File

@ -19,11 +19,10 @@ optional_modules('custis', $OPTIONAL_MODULES);
clear_hooks('custis');
# Other hooks
set_hook('custis', 'flag_check_requestee_list', 'CustisMiscHooks::flag_check_requestee_list');
set_hook('custis', 'process_bug_after_move', 'CustisMiscHooks::process_bug_after_move');
set_hook('custis', 'enter_bug_cloned_bug', 'CustisMiscHooks::enter_bug_cloned_bug');
set_hook('custis', 'post_bug_cloned_bug', 'CustisMiscHooks::post_bug_cloned_bug');
set_hook('custis', 'emailin_filter_body', 'CustisMiscHooks::emailin_filter_body');
set_hook('custis', 'flag_check_requestee_list', 'CustisMiscHooks::flag_check_requestee_list');
set_hook('custis', 'enter_bug_cloned_bug', 'CustisMiscHooks::enter_bug_cloned_bug');
set_hook('custis', 'post_bug_cloned_bug', 'CustisMiscHooks::post_bug_cloned_bug');
set_hook('custis', 'emailin_filter_body', 'CustisMiscHooks::emailin_filter_body');
1;
__END__

View File

@ -1,8 +1,8 @@
#!/usr/bin/perl
# Misc hooks:
# - Expand "group" users in flag requestee
# - Remember about nonanswered flag requests
# - Automatic settings of cf_extbug
# - Set cf_extbug automatically during bug cloning
# - Filter text body of input messages to remove Outlook link URLs
package CustisMiscHooks;
@ -30,91 +30,6 @@ sub flag_check_requestee_list
return 1;
}
# Remind about flag requests during bug changes
sub process_bug_after_move
{
my ($args) = @_;
my $ARGS = Bugzilla->input_params;
my $bug_objects = $args->{bug_objects};
my $vars = $args->{vars};
my $single = @$bug_objects == 1;
my $clear_on_close =
$ARGS->{bug_status} eq 'CLOSED' &&
Bugzilla->user->settings->{clear_requests_on_close}->{value} eq 'on';
my $verify_flags = $single &&
Bugzilla->usage_mode != USAGE_MODE_EMAIL &&
Bugzilla->user->wants_request_reminder;
my $reset_own_flags = $verify_flags && $ARGS->{comment} !~ /^\s*$/so;
if (($clear_on_close || $reset_own_flags) && !$ARGS->{force_flags})
{
my $flags;
my @requery_flags;
my $flag;
my $login;
# 1) Check flag requests and remind user about resetting his own incoming requests.
# 2) When closing bugs, clear all flag requests (CustIS Bug 68430).
for my $bug (@$bug_objects)
{
if ($single)
{
for (keys %$ARGS)
{
if (/^(flag-(\d+))$/)
{
$flag = Bugzilla::Flag->new({ id => $2 });
$flag->{status} = $ARGS->{$_};
if (($login = trim($ARGS->{"requestee-".$flag->{id}})) &&
($login = login_to_id($login)))
{
$flag->{requestee_id} = $login;
}
push @$flags, $flag;
}
}
}
else
{
$flags = Bugzilla::Flag->match({ bug_id => $bug->id });
}
foreach $flag (@$flags)
{
if ($flag->{status} eq '?' &&
($clear_on_close || $flag->{requestee_id} eq Bugzilla->user->id))
{
if ($clear_on_close)
{
$flag->{status} = 'X';
}
if ($verify_flags)
{
push @requery_flags, $flag;
delete $ARGS->{'flag-'.$flag->{id}};
}
elsif ($single)
{
$ARGS->{'flag-'.$flag->{id}} = 'X';
}
else
{
Bugzilla::Flag->set_flag($bug, $flag);
}
}
}
if ($verify_flags && @requery_flags)
{
push @{$vars->{verify_flags}}, @requery_flags;
Bugzilla->template->process("bug/process/verify-flags.html.tmpl", $vars)
|| ThrowTemplateError(Bugzilla->template->error());
exit;
}
}
}
return 1;
}
# Bug 69514 - Automatic setting of cf_extbug during clone to internal/external product
sub enter_bug_cloned_bug
{

View File

@ -346,6 +346,8 @@ foreach my $b (@bug_objects)
$b->set(groups => [ keys %$g ]) if $g;
}
Bugzilla::Flag::show_flag_reminders(\@bug_objects);
if ($ARGS->{id})
{
my ($flags, $new_flags) = Bugzilla::Flag->extract_flags_from_cgi($first_bug, undef, $vars);

View File

@ -69,9 +69,6 @@
"to grant them the rights to view/change the bug if they " _
"aren't in product groups."
clear_requests_on_close =>
"Clear all unanswered flag requests when changing bug status to CLOSED."
unauth_bug_details =>
"Show product name to the user in Unauthorized message if he doesn't have access to bug."