Skip to content

Commit

Permalink
Bug 1195952 - Please add the following choices to the CAB review drop…
Browse files Browse the repository at this point in the history
… down area of bugzilla
  • Loading branch information
dklawren committed Oct 14, 2015
1 parent 9c79219 commit 0e11b4a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 6 deletions.
12 changes: 11 additions & 1 deletion extensions/BMO/Extension.pm
Expand Up @@ -549,8 +549,18 @@ sub bug_check_can_change_field {
my $user = Bugzilla->user;

if ($field =~ /^cf/ && !@$priv_results && $new_value ne '---') {
# Cannot use the standard %cf_setter mapping as we want anyone
# to be able to set ?, just not the other values.
if ($field eq 'cf_cab_review') {
if ($new_value ne '1'
&& $new_value ne '?'
&& !$user->in_group('infra', $bug->product_id))
{
push (@$priv_results, PRIVILEGES_REQUIRED_EMPOWERED);
}
}
# "other" custom field setters restrictions
if (exists $cf_setters->{$field}) {
elsif (exists $cf_setters->{$field}) {
my $in_group = 0;
foreach my $group (@{$cf_setters->{$field}}) {
if ($user->in_group($group, $bug->product_id)) {
Expand Down
5 changes: 5 additions & 0 deletions extensions/BMO/lib/Data.pm
Expand Up @@ -144,6 +144,11 @@ tie(%$cf_visible_in_products, "Tie::IxHash",
"Firefox" => [],
"Toolkit" => [],
},
qr/^cf_cab_review$/ => {
"Developer Services" => [],
"Infrastructure & Operations Graveyard" => [],
"Infrastructure & Operations" => [],
}
);

# Who to CC on particular bugmails when certain groups are added or removed.
Expand Down
11 changes: 6 additions & 5 deletions extensions/BugModal/lib/WebService.pm
Expand Up @@ -91,11 +91,12 @@ sub edit {
Bugzilla->active_custom_fields({ product => $bug->product_obj, component => $bug->component_obj });
foreach my $field (@custom_fields) {
my $field_name = $field->name;
$options{$field_name} = [
map { { name => $_->name } }
grep { $bug->$field_name eq $_->name || $_->is_active }
@{ $field->legal_values }
];
my @values = map { { name => $_->name } }
grep { $bug->$field_name eq $_->name
|| ($_->is_active
&& $bug->check_can_change_field($field_name, $bug->$field_name, $_->name)) }
@{ $field->legal_values };
$options{$field_name} = \@values;
}

# keywords
Expand Down
Expand Up @@ -736,6 +736,15 @@
%]
[% END %]

[% UNLESS cf_hidden_in_product('cf_cab_review', bug.product, bug.component, bug) %]
[% rendered_custom_fields.push('cf_cab_review') %]
[% INCLUDE bug_modal/field.html.tmpl
field = bug_fields.cf_cab_review
field_type = bug_fields.cf_cab_review.type
hide_on_view = bug.cf_cab_review == "---"
%]
[% END %]

[% END %]
[% WRAPPER fields_rhs %]

Expand Down
Expand Up @@ -173,6 +173,7 @@ END;
[% IF values.defined %]
[% FOREACH v IN values %]
[% NEXT IF NOT v.is_active AND NOT value.contains(v.name).size %]
[% NEXT IF NOT bug.check_can_change_field(name, bug.${name}, v.name) %]
<option value="[% v.name FILTER html %]"
id="v[% v.id FILTER html %]_[% name FILTER html %]"
[% " selected" IF value.contains(v.name).size %]
Expand Down
102 changes: 102 additions & 0 deletions scripts/migrate-cab-review.pl
@@ -0,0 +1,102 @@
#!/usr/bin/perl

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

use strict;
use warnings;

use FindBin qw($RealBin);
use lib "$RealBin/../../..";

use Bugzilla;
use Bugzilla::Bug;
use Bugzilla::Constants;
use Bugzilla::Field;
use Bugzilla::Group;
use Bugzilla::Install::Util qw(indicate_progress);
use Bugzilla::User;

Bugzilla->usage_mode(USAGE_MODE_CMDLINE);

my $dbh = Bugzilla->dbh;

# Make all changes as the automation user
my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' });
$auto_user->{groups} = [ Bugzilla::Group->get_all ];
$auto_user->{bless_groups} = [ Bugzilla::Group->get_all ];
Bugzilla->set_user($auto_user);

# cab-review flag values to custom field values mapping
my %map = (
'?' => '?',
'+' => 'approved',
'-' => 'denied'
);

# Verify that all of the custom field values in the mapping data are present
my $cab_field = Bugzilla::Field->check({ name => 'cf_cab_review' });
foreach my $value (values %map) {
unless (grep($_ eq $value, map { $_->name } @{ $cab_field->legal_values })) {
die "Value '$value' does not exist. Please add to 'cf_cab_review.\n";
}
}

# Grab list of bugs with cab-review flag set
my $sql = <<EOF;
SELECT bugs.bug_id
FROM bugs JOIN flags ON bugs.bug_id = flags.bug_id
JOIN flagtypes ON flags.type_id = flagtypes.id
WHERE flagtypes.name = 'cab-review' AND flags.status IN ('?','+', '-')
ORDER BY bug_id
EOF

print "Searching for matching bugs..\n";
my $bugs = $dbh->selectcol_arrayref($sql);
my ($current, $total, $updated) = (1, scalar(@$bugs), 0);

die "No matching bugs found\n" unless $total;
print "About to update $total bugs with cab-review flags set and migrate to the cf_cab_review custom field.\n";
print "Press <enter> to start, or ^C to cancel...\n";
<>;

foreach my $bug_id (@$bugs) {
indicate_progress({ current => $current++, total => $total, every => 5 });

# Load bug object
my $bug = Bugzilla::Bug->new($bug_id);

# Find the current cab-review status
my $cab_flag;
foreach my $flag (@{ $bug->flags }) {
next if $flag->type->name ne 'cab-review';
$cab_flag = $flag;
last;
}

my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');

$dbh->bz_start_transaction;

# Set the cab-review custom field to the right status based on the mapped values
$bug->set_custom_field($cab_field, $map{$cab_flag->status});

# Clear the old cab-review flag
$bug->set_flags([{ id => $cab_flag->id, status => 'X' }], []);

# Update the bug
$bug->update($timestamp);

# Do not send email about this change
$dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?",
undef, $timestamp, $timestamp, $bug_id);

$dbh->bz_commit_transaction;
$updated++;
}

print "Bugs updated: $updated\n";
1 change: 1 addition & 0 deletions template/en/default/bug/field.html.tmpl
Expand Up @@ -130,6 +130,7 @@
[% IF field.name.match("^cf_blocking_") OR
field.name.match("^cf_status_") OR
field.name.match("^cf_tracking_") OR
field.name == "cf_cab_review" OR
field.name == "resolution" %]
[% NEXT UNLESS bug.check_can_change_field(field.name, '---', legal_value.name) OR
value.contains(legal_value.name).size %]
Expand Down

0 comments on commit 0e11b4a

Please sign in to comment.