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 1881253 - Hide the attachment if the corresponding comment is marked as spam. #2193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions Bugzilla/Attachment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ sub isobsolete {

=over

=item C<isspam>

whether or not the comment for the attachment is marked as spam

=back

=cut

sub isspam {
return $_[0]->{isspam};
}

=over

=item C<isprivate>

whether or not the attachment is private
Expand Down Expand Up @@ -573,6 +587,15 @@ sub get_attachments_by_bug {

my $attachments = Bugzilla::Attachment->new_from_list($attach_ids);

my $spam_map = $bug->spam_attachment_id_map;
foreach my $attachment (@$attachments) {
if ($spam_map->{$attachment->id}) {
$attachment->{isspam} = 1;
} else {
$attachment->{isspam} = 0;
}
}

# To avoid $attachment->flags to run SQL queries itself for each
# attachment listed here, we collect all the data at once and
# populate $attachment->{flags} ourselves.
Expand Down
16 changes: 16 additions & 0 deletions Bugzilla/Bug.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3722,6 +3722,22 @@ sub attachments {
return $self->{'attachments'};
}

sub spam_attachment_id_map {
my ($self) = @_;
return $self->{'spam_attachments_id_map'} if exists $self->{'spam_attachments_id_map'};

my $spam_map = ();
my $raw_comments = $self->comments();
foreach my $comment (@$raw_comments) {
if ($comment->is_attachment_created && $comment->is_spam) {
$spam_map->{$comment->raw_attachment_id} = 1;
}
}
$self->{'spam_attachments_id_map'} = $spam_map;

return $self->{'spam_attachments_id_map'};
}

sub assigned_to {
my ($self) = @_;
return $self->{'assigned_to_obj'} if exists $self->{'assigned_to_obj'};
Expand Down
22 changes: 22 additions & 0 deletions Bugzilla/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ sub bug {
return $bug;
}

sub is_spam {
my ($self) = @_;
foreach my $my_tag (@{$self->tags}) {
if (lc($my_tag) eq "spam") {
return 1;
}
}
return 0;
}

sub is_attachment_created {
my ($self) = @_;
return 1 if $self->type == CMT_ATTACHMENT_CREATED;
return 0;
}

sub is_about_attachment {
my ($self) = @_;
return 1
Expand All @@ -264,6 +280,12 @@ sub is_about_attachment {
return 0;
}

sub raw_attachment_id {
my ($self) = @_;
return undef if not $self->is_about_attachment;
return $self->extra_data;
}

sub attachment {
my ($self) = @_;
return undef if not $self->is_about_attachment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
attachment_rendered = 0;
Hook.process("row");
NEXT IF attachment_rendered;
NEXT IF attachment.isspam
%]
<tr class="
[%~ " bz_private" IF attachment.isprivate %]
Expand Down
Loading