From 0c7d3bd60aea513476e36aaa140511e41de2686b Mon Sep 17 00:00:00 2001 From: Jeff Fearn Date: Jul 16 2020 23:27:46 +0000 Subject: Bug 1816873 - Allow flag change by flag group Added flag group to page 3, restricted to changing existing flags. Change-Id: Ib227e1a60b50cc44e9f4734d7efb3e1b8eca5e8e --- diff --git a/extensions/RuleEngine/Extension.pm b/extensions/RuleEngine/Extension.pm index 7372f15..01333b2 100644 --- a/extensions/RuleEngine/Extension.pm +++ b/extensions/RuleEngine/Extension.pm @@ -43,6 +43,7 @@ BEGIN { *Bugzilla::_check_rule_group = \&_check_rule_group; *Bugzilla::User::can_admin_any_product = \&_user_can_admin_any_product; *Bugzilla::User::can_see_rule = \&_user_can_see_rule; + *Bugzilla::Flag::is_in_flaggroup = \&_flag_is_in_flaggroup; } #################### @@ -1287,7 +1288,7 @@ sub email_before_template { if (any { $_ eq 'rh_rule' } @{$vars->{changedfields}}) { foreach my $diff (@{$vars->{diffs}}) { if ($diff->{field_name} eq 'rh_rule') { - my @ids = split ' ', $diff->{new}; + my @ids = split ' ', $diff->{new}; foreach my $rid (@ids) { my $rule_id = int $rid; last unless $rule_id; @@ -1424,6 +1425,19 @@ sub bug_filter_change { return; } + +sub _flag_is_in_flaggroup { + my ($flag, $flag_group) = @_; + + my $match_regexp = $flag_group->current->theregexp; + my $match_flag_types = $flag_group->current->flag_types; + + my $is = (($match_regexp && $flag->name =~ qr{$match_regexp}) + || any { $_->name eq $flag->name } @$match_flag_types); + + return $is; +} + __PACKAGE__->NAME; __END__ diff --git a/extensions/RuleEngine/lib/Job.pm b/extensions/RuleEngine/lib/Job.pm index a55ae47..26b0758 100644 --- a/extensions/RuleEngine/lib/Job.pm +++ b/extensions/RuleEngine/lib/Job.pm @@ -1268,6 +1268,24 @@ sub _rule_do_action { } } } + elsif ($field eq 'flag_groups') { + my $flaggroup_changes = clone($value); + my $flags = $bug->flags; + + foreach my $flag (@$flags) { + foreach my $fg_id (keys %$flaggroup_changes) { + my $flag_group = Bugzilla::Extension::RuleEngine::FlagGroup->check({id => $fg_id}); + next unless $flag->is_in_flaggroup($flag_group); + + my $condition = $flaggroup_changes->{$fg_id}->{condition}; + my $status = $flaggroup_changes->{$fg_id}->{status}; + + if ( index($condition, $flag->status) != -1) { + push @set_flags, {id => $flag->id, status => $status}; + } + } + } + } elsif ($field eq 'target_release') { # $value is an arrayref diff --git a/extensions/RuleEngine/lib/Pages.pm b/extensions/RuleEngine/lib/Pages.pm index b67fcdd..746b51a 100644 --- a/extensions/RuleEngine/lib/Pages.pm +++ b/extensions/RuleEngine/lib/Pages.pm @@ -640,6 +640,18 @@ sub _page_rule_edit_set_vars { $vars->{flag_group_list} = [Bugzilla::Extension::RuleEngine::FlagGroup->get_all]; } + else { + # REDHAT EXTENSION START 1816873 + $vars->{flag_group_list} + = [Bugzilla::Extension::RuleEngine::FlagGroup->get_all]; + + $vars->{flag_group_map} = {}; + foreach my $flag_group (Bugzilla::Extension::RuleEngine::FlagGroup->get_all) { + $vars->{flag_group_map}{$flag_group->id} = $flag_group->name; + } + + # REDHAT EXTENSION END 1816873 + } # For all of these, we just want to get the name $vars->{bug_status_list} @@ -1056,6 +1068,21 @@ sub _rule_to_cgi { } } } + elsif ($key eq 'flag_groups') { + while (my ($flaggroup, $v) = each %$value) { + my $status = $v->{status} eq 'X' ? '(unset)' : $v->{status}; + $cgi{"p3_flaggroup_$flaggroup"} = $status; + if (defined $v->{condition}) { + $cgi{"p3_word_flaggroup_$flaggroup"} = FLAG_COND_TO_TEXT->{$v->{condition}}; + } + if (defined $v->{requestee}) { + $cgi{"p3_flaggroup_${flaggroup}_requestee"} = $v->{requestee}; + } + if (defined $v->{ignore}) { + $cgi{"p3_flaggroup_${flaggroup}_ignore"} = 1; + } + } + } elsif ($key eq 'comment') { $cgi{'p3_comment'} = $value->{text}; $cgi{'p3_word_comment'} = $value->{private} ? 'Private' : 'Public'; @@ -1192,8 +1219,8 @@ sub _rule_cgi_to_array { # Page three my $action = $rule{action}; foreach my $field ( - apply {s/^p3_(?!flag|comment)//} - grep {/^p3_(?!flag|comment)/} $cgi->param + apply {s/^p3_(?!flag|flaggroup|comment)//} + grep {/^p3_(?!flag|flaggroup|comment)/} $cgi->param ) { if ($field =~ /^word_(.+)$/) { @@ -1430,6 +1457,40 @@ sub _rule_cgi_to_array { } } + # REDHAT EXTENSION START 1816873 + foreach my $flag_group_id ( + apply {s/^p3_word_flaggroup_(.+)$/$1/} + grep {/^p3_word_flaggroup_(.+)$/} $cgi->param + ) + { + my $value = $cgi->param("p3_flaggroup_$flag_group_id"); + my $cond = $cgi->param("p3_word_flaggroup_$flag_group_id"); + if ($cond and $cond ne 'Do not change' and $value) { + $value = 'X' if $value eq '(unset)'; + $action->{flag_groups}{$flag_group_id} + = {condition => FLAG_TEXT_TO_COND->{$cond}, status => $value}; + if ($value eq '?' + and my $requestee = $cgi->param("p3_flag_${flag_group_id}_requestee")) + { + $action->{flag_groups}{$flag_group_id}{requestee} = $requestee; + } + if ($cgi->param("p3_flag_${flag_group_id}_ignore")) { + $action->{flag_groups}{$flag_group_id}{ignore} = 1; + } + + if ($this_page >= 3) { + foreach my $hash (@{($match->{flag_groups})}) { + if ($hash->{id} == $flag_group_id) { + $num_matches++; + last; + } + } + } + } + } + + # REDHAT EXTENSION END 1816873 + if ($num_messages && !$num_matches) { ThrowUserError('messages_without_action_detected', {errors => \@errors}); } diff --git a/extensions/RuleEngine/template/en/default/pages/ruleengine/edit.html.tmpl b/extensions/RuleEngine/template/en/default/pages/ruleengine/edit.html.tmpl index ed796e7..82bfb75 100644 --- a/extensions/RuleEngine/template/en/default/pages/ruleengine/edit.html.tmpl +++ b/extensions/RuleEngine/template/en/default/pages/ruleengine/edit.html.tmpl @@ -192,20 +192,23 @@ [% IF type == 'static' %] [% cgi.param(field).join(', ') FILTER html %] - + [% ELSIF type == 'text' %] + [% PROCESS reset_button show_button = noreset field_name = field %] [% ELSIF type == 'textarea' %] + [% PROCESS reset_button show_button = noreset field_name = field %] [% ELSIF type == 'checkbox' %] + [% PROCESS reset_button show_button = noreset field_name = field %] [% ELSIF type == 'flag' %] - + [% PROCESS reset_button show_button = noreset field_name = field %] [% ELSIF type == 'flags_order' %] [% field_after = field _ '_after' %] @@ -229,6 +233,7 @@ + [% PROCESS reset_button show_button = noreset field_name = field %] [% ELSIF type == 'select' %] diff --git a/extensions/RuleEngine/template/en/default/ruleengine/explain.html.tmpl b/extensions/RuleEngine/template/en/default/ruleengine/explain.html.tmpl index 7ce8b09..e4ecac8 100644 --- a/extensions/RuleEngine/template/en/default/ruleengine/explain.html.tmpl +++ b/extensions/RuleEngine/template/en/default/ruleengine/explain.html.tmpl @@ -53,13 +53,15 @@ [% END %] [% END %] - [% action_order.push('flag_types', 'comment', 'notify') %] + [% action_order.push('flag_types', 'flag_groups', 'comment', 'notify') %] [% FOREACH field IN action_order %] [% IF json.action.$field %]
  • [% PROCESS explain_row_action %]
  • [% ELSIF field == 'flag_types' %]
  • No changes to flags.
  • + [% ELSIF field == 'flag_groups' %] +
  • No changes to flags in flag groups.
  • [% ELSIF field == 'comment' %]
  • No comment will be made.
  • [% ELSIF field == 'notify' %] @@ -151,6 +153,34 @@ [% END %] [% UNLESS loop.last %]
  • [% END %] [% END %] + [% ELSIF field == 'flag_groups' %] + [% FOREACH flag_group IN value.keys %] + [% condition = value.${flag_group}.condition %] + [% status = value.${flag_group}.status %] + [% requestee = value.${flag_group}.requestee %] + [% ignore = value.${flag_group}.ignore.defined && value.${flag_group}.ignore %] + [% IF status == 'X' %] + Unset falgs in the '[% flag_group_map.${flag_group} FILTER html %]' flag group + [% ELSE %] + Change the flags in the '[% flag_group_map.${flag_group} FILTER html %]' flag group to + '[% status FILTER html %]' + [% END %] + [% IF status == '?' AND requestee %] + with a requestee of '[% requestee FILTER html %]' + [% END %] + [% IF condition %] + [% IF condition == 'Exists' %] + if it exists. + [% ELSE %] + if it is currently + [%+ PROCESS explain_row_comma_status list = condition.split(''), join_word = 'or' %] + [% END %] + [% IF ignore %] + (ignored if not present) + [% END %] + [% END %] + [% UNLESS loop.last %]
  • [% END %] + [% END %] [% ELSIF field == 'comment' %] Add a [% value.private ? "Private" : "Public" %] comment '[% value.text FILTER html %]'