Skip to content
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 1916929 - Prevent emoji reactions on old, closed bugs #2313

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Bugzilla/Bug.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use Bugzilla::Comment;
use Bugzilla::BugUrl;
use Bugzilla::BugUserLastVisit;

use Date::Parse;
use DateTime;
use List::MoreUtils qw(firstidx uniq part any);
use List::Util qw(min max first);
use Storable qw(dclone);
Expand Down Expand Up @@ -3895,6 +3897,22 @@ sub isopened {
return is_open_state($self->{bug_status}) ? 1 : 0;
}

# Check if the bug is closed and the last resolved date is older than the given
# duration. This method requires the LastResolved extension. To check if the bug
# is closed for a month: `$self->is_closed_for({months => 1})`
sub is_closed_for {
my ($self, $duration) = @_;

if ($self->isopened || !$self->cf_last_resolved) {
return 0;
}

my $past_time = DateTime->now()->subtract(%$duration)->epoch();
my $closed_time = str2time($self->cf_last_resolved);

return $past_time > $closed_time;
}

sub keywords {
my ($self) = @_;
return join(', ', (map { $_->name } @{$self->keyword_objects}));
Expand Down
4 changes: 4 additions & 0 deletions Bugzilla/WebService/Bug.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,10 @@ sub update_comment_reactions {
ThrowUserError('comment_is_private', {id => $comment_id});
}

if ($comment->bug->is_closed_for({months => 3})) {
ThrowUserError('comment_reaction_closed');
}

my $dbh = Bugzilla->dbh;
$dbh->bz_start_transaction();
foreach my $reaction (@{$params->{add} || []}) {
Expand Down
1 change: 1 addition & 0 deletions Bugzilla/WebService/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ use constant WS_ERROR_CODE => {
# Comment reactions
comment_reaction_disabled => 136,
comment_reaction_invalid => 137,
comment_reaction_closed => 138,

# Comment tagging
comment_tag_disabled => 125,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[% IF user.id || total_count %]
<div id="cre-[% comment.count FILTER none %]" class="comment-reactions"
[% IF comment.collapsed +%] style="display:none"[% END %]>
[% IF user.id %]
[% IF user.id && !bug.is_closed_for({months => 3}) %]
<button type="button" class="anchor">
<span class="icon" aria-label="Toggle Reaction Picker"></span>
</button>
Expand Down
5 changes: 5 additions & 0 deletions extensions/BugModal/web/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ Bugzilla.BugModal.CommentReactions = class CommentReactions {
/** @type {Number} */
this.commentId = Number(/** @type {HTMLElement} */ ($wrapper.parentElement.querySelector('.comment')).dataset.id);

// Users cannot react on old bugs
if (!this.$anchor) {
return;
}

if (this.canUsePopover) {
this.$anchor.popoverTargetElement = this.$picker;
this.$anchor.popoverTargetAction = 'toggle';
Expand Down
4 changes: 4 additions & 0 deletions template/en/default/global/user-error.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@
[% title = "Invalid Comment Reaction" %]
The comment reaction "[% reaction FILTER html %]" is not supported.

[% ELSIF error == "comment_reaction_closed" %]
[% title = "Comment Reactions Closed" %]
This [% terms.bug %] no longer accepts comment reactions.

[% ELSIF error == "comment_tag_disabled" %]
[% title = "Comment Tagging Disabled" %]
The comment tagging is not enabled.
Expand Down
Loading