Skip to content

Commit 1d96fa1

Browse files
ketodylanwh
authored andcommitted
Bug 1062718 - add the ability to disable sending of mail when updating bugs
r=dylan,a=sgreen
1 parent 592e6fd commit 1d96fa1

16 files changed

Lines changed: 151 additions & 24 deletions

File tree

Bugzilla/Bug.pm

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ sub remove_from_db {
12651265
#####################################################################
12661266

12671267
sub send_changes {
1268-
my ($self, $changes, $vars) = @_;
1268+
my ($self, $changes, $vars, $minor_update) = @_;
12691269

12701270
my $user = Bugzilla->user;
12711271

@@ -1283,15 +1283,15 @@ sub send_changes {
12831283
changer => $user,
12841284
);
12851285

1286-
_send_bugmail({ id => $self->id, type => 'bug', forced => \%forced },
1287-
$vars);
1286+
_send_bugmail({ id => $self->id, type => 'bug', forced => \%forced,
1287+
minor_update => $minor_update }, $vars);
12881288

12891289
# If the bug was marked as a duplicate, we need to notify users on the
12901290
# other bug of any changes to that bug.
12911291
my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef;
12921292
if ($new_dup_id) {
12931293
_send_bugmail({ forced => { changer => $user }, type => "dupe",
1294-
id => $new_dup_id }, $vars);
1294+
id => $new_dup_id, minor_update => $minor_update }, $vars);
12951295
}
12961296

12971297
# If there were changes in dependencies, we need to notify those
@@ -1306,7 +1306,8 @@ sub send_changes {
13061306
type => 'dep',
13071307
dep_only => 1,
13081308
blocker => $self,
1309-
changes => $changes };
1309+
changes => $changes,
1310+
minor_update => $minor_update };
13101311

13111312
foreach my $id (@{ $self->blocked }) {
13121313
$params->{id} = $id;
@@ -1329,13 +1330,13 @@ sub send_changes {
13291330

13301331
foreach my $id (sort { $a <=> $b } (keys %changed_deps)) {
13311332
_send_bugmail({ forced => { changer => $user }, type => "dep",
1332-
id => $id }, $vars);
1333+
id => $id, minor_update => $minor_update }, $vars);
13331334
}
13341335

13351336
# Sending emails for the referenced bugs.
13361337
foreach my $ref_bug_id (uniq @{ $self->{see_also_changes} || [] }) {
13371338
_send_bugmail({ forced => { changer => $user },
1338-
id => $ref_bug_id }, $vars);
1339+
id => $ref_bug_id, minor_update => $minor_update }, $vars);
13391340
}
13401341
}
13411342

@@ -4221,6 +4222,12 @@ sub get_activity {
42214222
return(\@operations, $incomplete_data);
42224223
}
42234224

4225+
sub has_unsent_changes {
4226+
my $self = shift;
4227+
return 1 if !defined $self->lastdiffed;
4228+
return datetime_from($self->lastdiffed) < datetime_from($self->delta_ts) ? 1 : 0;
4229+
}
4230+
42244231
# Update the bugs_activity table to reflect changes made in bugs.
42254232
sub LogActivityEntry {
42264233
my ($bug_id, $field, $removed, $added, $user_id, $timestamp, $comment_id,
@@ -4625,6 +4632,10 @@ call L<update> to make the changes permanent.
46254632
Creates or updates a L<Bugzilla::BugUserLastVisit> for this bug and the supplied
46264633
$user, the timestamp given as $last_visit.
46274634
4635+
=item C<has_unsent_changes()>
4636+
4637+
Checks if this bug has changes for which bug mail has not been sent.
4638+
46284639
=back
46294640
46304641
=head1 B<Methods in need of POD>

Bugzilla/BugMail.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ sub Send {
225225
my $date = $params->{dep_only} ? $end : $bug->delta_ts;
226226
$date = format_time($date, '%a, %d %b %Y %T %z', 'UTC');
227227

228+
my $minor_update = $changer->in_group(Bugzilla->params->{minor_update_group})
229+
&& $params->{minor_update};
230+
228231
foreach my $user_id (keys %recipients) {
229232
my %rels_which_want;
230233
my $user = $user_cache{$user_id} ||= new Bugzilla::User($user_id);
@@ -244,7 +247,8 @@ sub Send {
244247
$start ? \@diffs : [],
245248
$comments,
246249
$params->{dep_only},
247-
$changer))
250+
$changer,
251+
$minor_update))
248252
{
249253
$rels_which_want{$relationship} =
250254
$recipients{$user_id}->{$relationship};

Bugzilla/Config/GroupSecurity.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ sub get_param_list {
6666
checker => \&check_comment_taggers_group
6767
},
6868

69+
{
70+
name => 'minor_update_group',
71+
type => 's',
72+
choices => \&_get_all_group_names,
73+
default => '',
74+
checker => \&check_group
75+
},
76+
6977
{
7078
name => 'debug_group',
7179
type => 's',

Bugzilla/Constants.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use Memoize;
9494
EVT_BUG_CREATED EVT_COMPONENT
9595
9696
NEG_EVENTS
97-
EVT_UNCONFIRMED EVT_CHANGED_BY_ME
97+
EVT_UNCONFIRMED EVT_CHANGED_BY_ME EVT_MINOR_UPDATE
9898
9999
GLOBAL_EVENTS
100100
EVT_FLAG_REQUESTED EVT_REQUESTED_FLAG
@@ -384,8 +384,9 @@ use constant POS_EVENTS => EVT_OTHER, EVT_ADDED_REMOVED, EVT_COMMENT,
384384

385385
use constant EVT_UNCONFIRMED => 50;
386386
use constant EVT_CHANGED_BY_ME => 51;
387+
use constant EVT_MINOR_UPDATE => 52;
387388

388-
use constant NEG_EVENTS => EVT_UNCONFIRMED, EVT_CHANGED_BY_ME;
389+
use constant NEG_EVENTS => EVT_UNCONFIRMED, EVT_CHANGED_BY_ME, EVT_MINOR_UPDATE;
389390

390391
# These are the "global" flags, which aren't tied to a particular relationship.
391392
# and so use REL_ANY.

Bugzilla/User.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,8 @@ our %names_to_events = (
20372037
# Note: the "+" signs before the constants suppress bareword quoting.
20382038
sub wants_bug_mail {
20392039
my $self = shift;
2040-
my ($bug, $relationship, $fieldDiffs, $comments, $dep_mail, $changer) = @_;
2040+
my ($bug, $relationship, $fieldDiffs, $comments, $dep_mail, $changer,
2041+
$minor_update) = @_;
20412042

20422043
# Make a list of the events which have happened during this bug change,
20432044
# from the point of view of this user.
@@ -2115,6 +2116,10 @@ sub wants_bug_mail {
21152116
if ($wants_mail && $bug->bug_status eq 'UNCONFIRMED') {
21162117
$wants_mail &= $self->wants_mail([EVT_UNCONFIRMED], $relationship);
21172118
}
2119+
2120+
if ($wants_mail && $minor_update) {
2121+
$wants_mail &= $self->wants_mail([EVT_MINOR_UPDATE], $relationship);
2122+
}
21182123

21192124
return $wants_mail;
21202125
}

Bugzilla/WebService/Bug.pm

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ sub update {
644644

645645
my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @$ids;
646646

647+
my $minor_update = delete $params->{minor_update} ? 1 : 0;
647648
my %values = %$params;
648649
$values{other_bugs} = \@bugs;
649650

@@ -677,14 +678,16 @@ sub update {
677678
}
678679

679680
my %all_changes;
681+
my %minor_updates;
680682
$dbh->bz_start_transaction();
681683
foreach my $bug (@bugs) {
684+
$minor_updates{$bug->id} = $bug->has_unsent_changes ? 0 : $minor_update;
682685
$all_changes{$bug->id} = $bug->update();
683686
}
684687
$dbh->bz_commit_transaction();
685688

686689
foreach my $bug (@bugs) {
687-
$bug->send_changes($all_changes{$bug->id});
690+
$bug->send_changes($all_changes{$bug->id}, undef, $minor_updates{$bug->id});
688691
}
689692

690693
my %api_name = reverse %{ Bugzilla::Bug::FIELD_MAP() };
@@ -820,6 +823,7 @@ sub add_attachment {
820823
|| ThrowCodeError('param_required', { param => 'data' });
821824

822825
my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @{ $params->{ids} };
826+
my $minor_update = delete $params->{minor_update} ? 1 : 0;
823827

824828
my @created;
825829
$dbh->bz_start_transaction();
@@ -863,10 +867,17 @@ sub add_attachment {
863867
extra_data => $attachment->id });
864868
push(@created, $attachment);
865869
}
866-
$_->bug->update($timestamp) foreach @created;
870+
my %minor_updates;
871+
foreach my $attachment (@created) {
872+
my $bug = $attachment->bug;
873+
$minor_updates{$bug->id} = $bug->has_unsent_changes ? 0 : $minor_update;
874+
$bug->update($timestamp);
875+
}
867876
$dbh->bz_commit_transaction();
868877

869-
$_->send_changes() foreach @bugs;
878+
foreach my $bug (@bugs) {
879+
$bug->send_changes(undef, undef, $minor_updates{$bug->id});
880+
}
870881

871882
my @created_ids = map { $_->id } @created;
872883

@@ -882,6 +893,7 @@ sub update_attachment {
882893
my $ids = delete $params->{ids};
883894
defined $ids || ThrowCodeError('param_required', { param => 'ids' });
884895

896+
my $req_minor_update = delete $params->{minor_update} ? 1 : 0;
885897
# Some fields cannot be sent to set_all
886898
foreach my $key (qw(login password token)) {
887899
delete $params->{$key};
@@ -967,8 +979,9 @@ sub update_attachment {
967979

968980
# Email users about the change
969981
foreach my $bug (values %bugs) {
982+
my $minor_update = $bug->has_unsent_changes ? 0 : $req_minor_update;
970983
$bug->update();
971-
$bug->send_changes();
984+
$bug->send_changes(undef, undef, $minor_update);
972985
}
973986

974987
# Return the information to the user
@@ -989,6 +1002,8 @@ sub add_comment {
9891002
|| ThrowCodeError('param_required', { param => 'comment' });
9901003

9911004
my $bug = Bugzilla::Bug->check_for_edit($params->{id});
1005+
my $minor_update = delete $params->{minor_update} ? 1 : 0;
1006+
$minor_update = $bug->has_unsent_changes ? 0 : $minor_update;
9921007

9931008
# Backwards-compatibility for versions before 3.6
9941009
if (defined $params->{private}) {
@@ -1007,7 +1022,8 @@ sub add_comment {
10071022
my $new_comment_id = $bug->{added_comments}[0]->id;
10081023

10091024
# Send mail.
1010-
Bugzilla::BugMail::Send($bug->bug_id, { changer => $user });
1025+
Bugzilla::BugMail::Send($bug->bug_id, { changer => $user },
1026+
{ minor_update => $minor_update });
10111027

10121028
return { id => $self->type('int', $new_comment_id) };
10131029
}
@@ -1023,6 +1039,7 @@ sub update_see_also {
10231039
my ($add, $remove) = @$params{qw(add remove)};
10241040
($add || $remove)
10251041
or ThrowCodeError('params_required', { params => ['add', 'remove'] });
1042+
my $req_minor_update = delete $params->{minor_update} ? 1 : 0;
10261043

10271044
my @bugs;
10281045
foreach my $id (@{ $params->{ids} }) {
@@ -1038,6 +1055,7 @@ sub update_see_also {
10381055

10391056
my %changes;
10401057
foreach my $bug (@bugs) {
1058+
my $minor_update = $bug->has_unsent_changes ? 0 : $req_minor_update;
10411059
my $change = $bug->update();
10421060
if (my $see_also = $change->{see_also}) {
10431061
$changes{$bug->id}->{see_also} = {
@@ -1050,7 +1068,8 @@ sub update_see_also {
10501068
$changes{$bug->id}->{see_also} = { added => [], removed => [] };
10511069
}
10521070

1053-
Bugzilla::BugMail::Send($bug->id, { changer => $user });
1071+
Bugzilla::BugMail::Send($bug->id, { changer => $user },
1072+
{ minor_update => $minor_update });
10541073
}
10551074

10561075
return { changes => \%changes };
@@ -3414,6 +3433,12 @@ C<string> The login of the requestee if the flag type is requestable to a specif
34143433
34153434
=back
34163435
3436+
=item C<minor_update>
3437+
3438+
C<boolean> If set to true, this is considered a minor update and no mail is sent
3439+
to users who do not want minor update emails. If current user is not in the
3440+
minor_update_group, this parameter is simply ignored.
3441+
34173442
=back
34183443
34193444
=item B<Returns>
@@ -3609,6 +3634,14 @@ C<boolean> Set to true if you specifically want a new flag to be created.
36093634
36103635
=back
36113636
3637+
=item C<minor_update>
3638+
3639+
C<boolean> If set to true, this is considered a minor update and no mail is sent
3640+
to users who do not want minor update emails. If current user is not in the
3641+
minor_update_group, this parameter is simply ignored.
3642+
3643+
=back
3644+
36123645
=item B<Returns>
36133646
36143647
A C<hash> with a single field, "attachments". This points to an array of hashes
@@ -3729,8 +3762,6 @@ You did not specify a value for the C<summary> argument.
37293762
37303763
=back
37313764
3732-
=back
3733-
37343765
=head2 add_comment
37353766
37363767
B<STABLE>
@@ -3771,6 +3802,9 @@ structures, otherwise it is a normal text.
37713802
on the bug. If you are not in the time tracking group, this value will
37723803
be ignored.
37733804
3805+
=item C<minor_update> (boolean) - If set to true, this is considered a minor update
3806+
and no mail is sent to users who do not want minor update emails. If current user
3807+
is not in the minor_update_group, this parameter is simply ignored.
37743808
37753809
=back
37763810
@@ -3872,6 +3906,12 @@ pulled from the URL path.
38723906
Array of C<int>s or C<string>s. The ids or aliases of the bugs that
38733907
you want to modify.
38743908
3909+
=item C<minor_update>
3910+
3911+
C<boolean> If set to true, this is considered a minor update and no mail is sent
3912+
to users who do not want minor update emails. If current user is not in the
3913+
minor_update_group, this parameter is simply ignored.
3914+
38753915
=back
38763916
38773917
B<Note>: All following fields specify the values you want to set on the
@@ -4442,6 +4482,12 @@ If you specify a URL that is not in the See Also field of a particular bug,
44424482
it will just be silently ignored. Invaild URLs are currently silently ignored,
44434483
though this may change in some future version of Bugzilla.
44444484
4485+
=item C<minor_update>
4486+
4487+
C<boolean> If set to true, this is considered a minor update and no mail is sent
4488+
to users who do not want minor update emails. If current user is not in the
4489+
minor_update_group, this parameter is simply ignored.
4490+
44454491
=back
44464492
44474493
NOTE: If you specify the same URL in both C<add> and C<remove>, it will

attachment.cgi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ sub insert {
511511
@obsolete_attachments = Bugzilla::Attachment->validate_obsolete($bug, \@obsolete);
512512
}
513513

514+
my $minor_update = $cgi->param('minor_update') ? 1 : 0;
515+
$minor_update = $bug->has_unsent_changes ? 0 : $minor_update;
516+
514517
# Must be called before create() as it may alter $cgi->param('ispatch').
515518
my $content_type = Bugzilla::Attachment::get_content_type();
516519

@@ -586,7 +589,8 @@ sub insert {
586589
$vars->{'contenttypemethod'} = $cgi->param('contenttypemethod');
587590

588591
my $recipients = { 'changer' => $user, 'owner' => $owner };
589-
$vars->{'sent_bugmail'} = Bugzilla::BugMail::Send($bugid, $recipients);
592+
my $params = { 'minor_update' => $minor_update };
593+
$vars->{'sent_bugmail'} = Bugzilla::BugMail::Send($bugid, $recipients, $params);
590594

591595
print $cgi->header();
592596
# Generate and return the UI (HTML page) from the appropriate template.
@@ -677,6 +681,9 @@ sub update {
677681
my $token = $cgi->param('token');
678682
check_hash_token($token, [$attachment->id, $attachment->modification_time]);
679683

684+
my $minor_update = $cgi->param('minor_update') ? 1 : 0;
685+
$minor_update = $bug->has_unsent_changes ? 0 : $minor_update;
686+
680687
# If the user submitted a comment while editing the attachment,
681688
# add the comment to the bug. Do this after having validated isprivate!
682689
my $comment = $cgi->param('comment');
@@ -739,7 +746,8 @@ sub update {
739746
$vars->{'bugs'} = [$bug];
740747
$vars->{'header_done'} = 1;
741748
$vars->{'sent_bugmail'} =
742-
Bugzilla::BugMail::Send($bug->id, { 'changer' => $user });
749+
Bugzilla::BugMail::Send($bug->id, { 'changer' => $user },
750+
{'minor_update' => $minor_update });
743751

744752
print $cgi->header();
745753

0 commit comments

Comments
 (0)