diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index b54c085568..43ea98f6b1 100755 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -261,6 +261,20 @@ sub isobsolete { =over +=item C + +whether or not the comment for the attachment is marked as spam + +=back + +=cut + +sub isspam { + return $_[0]->{isspam}; +} + +=over + =item C whether or not the attachment is private @@ -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. diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index ccabb58e79..5aea613652 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -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'}; diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index ab9a90e866..fbf0a25e02 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -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 @@ -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; diff --git a/extensions/BugModal/template/en/default/bug_modal/attachments.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/attachments.html.tmpl index f391c19cf3..ff9b279677 100755 --- a/extensions/BugModal/template/en/default/bug_modal/attachments.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/attachments.html.tmpl @@ -23,6 +23,7 @@ attachment_rendered = 0; Hook.process("row"); NEXT IF attachment_rendered; + NEXT IF attachment.isspam %]