-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1508201 - Allow bulk edits to happen in the background, asynchronously #973
Open
dylanwh
wants to merge
10
commits into
mozilla-bteam:master
Choose a base branch
from
dylanwh:bg-bulk-edits
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f6ed3e5
Bug 1508201 - Allow bulk edits to happen in the background, asynchron…
dylanwh 1ab3e65
only show for bulk edit users
dylanwh 376fdaa
skip this
dylanwh 34b9ffa
nit
dylanwh 03907c0
fix sanity tests
dylanwh b78e8d9
handle other_bugs logic
dylanwh 49a449f
nit: case
dylanwh 6454d92
cleanup markup
dylanwh f2f8ef6
fix shebang
dylanwh 66a2199
fixes from review
dylanwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 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. | ||
|
||
package Bugzilla::Object::Lazy; | ||
use 5.10.1; | ||
use Moo; | ||
|
||
has 'id' => (is => 'ro', required => 1); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# 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. | ||
|
||
package Bugzilla::Task::BulkEdit; | ||
use 5.10.1; | ||
use Moo; | ||
|
||
use Bugzilla::Error; | ||
use DateTime::Duration; | ||
use List::Util qw(any); | ||
use Try::Tiny; | ||
use Type::Utils qw(duck_type); | ||
use Types::Standard -types; | ||
|
||
with 'Bugzilla::Task'; | ||
|
||
has 'ids' => (is => 'ro', isa => ArrayRef [Int], required => 1); | ||
has 'set_all' => (is => 'ro', isa => HashRef, required => 1); | ||
has 'ids_with_ts' => (is => 'lazy', isa => ArrayRef [Tuple [Int, Str]]); | ||
|
||
sub subject { | ||
my ($self) = @_; | ||
my @ids = @{$self->ids}; | ||
|
||
if (@ids > 100) { | ||
return "Bulk Edit " . scalar(@ids) . " bugs"; | ||
} | ||
else { | ||
return "Bulk Edit " . join(", ", @ids); | ||
} | ||
} | ||
|
||
sub _build_estimated_duration { | ||
my ($self) = @_; | ||
|
||
return DateTime::Duration->new(seconds => 0 + @{$self->ids}); | ||
} | ||
|
||
sub prepare { | ||
my ($self) = @_; | ||
|
||
# pickup timestamps | ||
$self->ids_with_ts; | ||
} | ||
|
||
sub _build_ids_with_ts { | ||
my ($self) = @_; | ||
my $dbh = Bugzilla->dbh; | ||
|
||
return [] if @{$self->ids} == 0; | ||
return $dbh->selectall_arrayref( | ||
"SELECT bug_id, delta_ts FROM bugs WHERE @{[$dbh->sql_in('bug_id', $self->ids)]}" | ||
); | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
|
||
return {async_bulk_edit => 1, all_sent_changes => [map { $self->edit_bug(@$_) } @{$self->ids_with_ts}]}; | ||
} | ||
|
||
sub edit_bug { | ||
my ($self, $bug_id, $delta_ts) = @_; | ||
my $result; | ||
try { | ||
my $bug = Bugzilla::Bug->check($bug_id); | ||
ThrowUserError('bulk_edit_stale', {bug => $bug, expected_delta_ts => $delta_ts}) | ||
unless $bug->delta_ts eq $delta_ts; | ||
ThrowUserError('product_edit_denied', {product => $bug->product}) | ||
unless $self->user->can_edit_product($bug->product_obj->id); | ||
|
||
my $set_all_fields = $self->set_all; | ||
|
||
# Don't blindly ask to remove unchecked groups available in the UI. | ||
# A group can be already unchecked, and the user didn't try to remove it. | ||
# In this case, we don't want remove_group() to complain. | ||
my @remove_groups; | ||
my @unchecked_groups = @{$set_all_fields->{groups}{remove} // []}; | ||
|
||
foreach my $group (@{$bug->groups_in}) { | ||
push(@remove_groups, $group->name) | ||
if any { $_ eq $group->name } @unchecked_groups; | ||
} | ||
|
||
local $set_all_fields->{groups}->{remove} = \@remove_groups; | ||
$bug->set_all($set_all_fields); | ||
my $changes = $bug->update(); | ||
$result = $bug->send_changes($changes); | ||
} | ||
catch { | ||
$result = { bug_id => $bug_id, error => $_ }; | ||
} | ||
finally { | ||
Bugzilla::Bug->CLEANUP(); | ||
}; | ||
|
||
return $result; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env 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 5.10.1; | ||
use lib qw( . lib local/lib/perl5 ); | ||
use Storable qw(freeze); | ||
|
||
# this provides a default urlbase. | ||
# Most localconfig options the other Bugzilla::Test::Mock* modules take care for us. | ||
use Bugzilla::Test::MockLocalconfig (urlbase => 'http://bmo-web.vm'); | ||
|
||
use Bugzilla::Test::MockParams ( antispam_multi_user_limit_age => 0); | ||
|
||
# This configures an in-memory sqlite database. | ||
use Bugzilla::Test::MockDB; | ||
|
||
# Util provides a few functions more making mock data in the DB. | ||
use Bugzilla::Test::Util qw(create_user create_bug ); | ||
|
||
use Test2::V0; | ||
use Test2::Tools::Mock; | ||
|
||
use ok 'Bugzilla::Task::BulkEdit'; | ||
|
||
my $user = create_user('[email protected]', '*'); | ||
Bugzilla->set_user($user); | ||
|
||
my @bug_ids; | ||
foreach (1..100) { | ||
my $bug = create_bug( | ||
short_desc => "a bug", | ||
comment => "this is a bug", | ||
assigned_to => scalar $user->login, | ||
); | ||
push @bug_ids, $bug->id; | ||
} | ||
|
||
is(0+@bug_ids, 100, "made 100 bugs"); | ||
|
||
my $task = Bugzilla::Task::BulkEdit->new( | ||
user => $user, | ||
ids => \@bug_ids, | ||
set_all => { | ||
comment => { | ||
body => "bunnies", | ||
is_private => 0, | ||
}, | ||
} | ||
); | ||
$task->prepare; | ||
|
||
try_ok { | ||
local $Storable::Deparse = 0; | ||
freeze($task); | ||
} "Can we store the bulk edit task?"; | ||
|
||
my $results = $task->run; | ||
if (my $edits = $results->{edits}) { | ||
is(0 + @$edits, 100); | ||
} | ||
|
||
my $comments = Bugzilla::Bug->check($bug_ids[-1])->comments; | ||
is(0 + @$comments, 2); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this. Seems that even if the user does not check the bulk edit checkbox on buglist.cgi, it will still enable it if @bug_ids > 10 which negates the need for a checkbox altogether.
Maybe this should be instead:
$async_bulk_edit = 0 if @bug_ids < 10;
Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now, doing > 10 edits is likely to fail, so it's meant to make them more likely to succeed. Eventually bz_async_bulk_edit should be the same as editbugs. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine. But is still sort of misleading from a user standpoint. Maybe we should add some text or tooltip that states it is automatic if more than 10 bugs?