From 493f91e99f47661e888cfa16eeb9199cff0e3898 Mon Sep 17 00:00:00 2001 From: Welp <9769385+WelpThatWorked@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:19:44 -0800 Subject: [PATCH] AO3-6832 Don't attach work download to abuse report if provided comment URL (#4972) * Don't attach work download to abuse report if provided comment URL * Add test, tweak for readability --- app/models/abuse_report.rb | 3 ++- spec/models/abuse_report_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index 23824aaee0d..7583d66ad4a 100644 --- a/app/models/abuse_report.rb +++ b/app/models/abuse_report.rb @@ -124,8 +124,9 @@ def send_report end def attach_work_download(ticket_id) + is_not_comments = url[%r{/comments/}, 0].nil? work_id = url[%r{/works/(\d+)}, 1] - return unless work_id + return unless work_id && is_not_comments work = Work.find_by(id: work_id) ReportAttachmentJob.perform_later(ticket_id, work) if work diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 3ef26276bc0..6c68081ff51 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -359,6 +359,13 @@ .not_to have_enqueued_job end + it "does not attach a download for comment sub-URLs asynchronously" do + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/comments/") + + expect { subject.attach_work_download(ticket_id) } + .not_to have_enqueued_job + end + it "attaches a download for work URLs asynchronously" do allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/")