From e9fb4131ea82fd190185ba49ffd32d4c5158726f Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 14 Jan 2025 13:31:55 +1000 Subject: [PATCH] FIX: Add Type column to Flag Status CSV export (#30756) This Type column is a special ":post" column on the Flag Status report, so it did not show by default in the CSV export of that report. This adds it so the type of flag e.g. illegal, off topic, innapropriate is shown in the CSV output. --- app/jobs/regular/export_csv_file.rb | 3 +++ spec/models/report_spec.rb | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb index d43b718e318..fb28fabf239 100644 --- a/app/jobs/regular/export_csv_file.rb +++ b/app/jobs/regular/export_csv_file.rb @@ -218,6 +218,9 @@ module Jobs elsif label[:type] == :topic titles[label[:properties][:id]] = label[:title] header << label[:properties][:id] + elsif label[:type] == :post + titles[label[:properties][:truncated_raw]] = label[:title] + header << label[:properties][:truncated_raw] else titles[label[:property]] = label[:title] header << label[:property] diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 4c436461369..9a32dcf5aa1 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -699,7 +699,7 @@ RSpec.describe Report do context "with flags" do let(:flagger) { Fabricate(:user, refresh_auto_groups: true) } - let(:post) { Fabricate(:post, user: flagger) } + let(:post) { Fabricate(:post, user: Fabricate(:user)) } before { freeze_time } @@ -723,6 +723,26 @@ RSpec.describe Report do expect(row[:resolution]).to eq("No action") expect(row[:response_time]).to eq(nil) end + + it "exports the CSV of the report correctly" do + result = + PostActionCreator.new(flagger, post, PostActionType.types[:spam], message: "bad").perform + + result.reviewable.perform(flagger, :agree_and_hide) + expect(result.success).to eq(true) + expect(report.data).to be_present + + exporter = Jobs::ExportCsvFile.new + exporter.entity = "report" + exporter.extra = HashWithIndifferentAccess.new(name: "flags_status") + exporter.current_user = flagger + exported_csv = [] + exporter.report_export { |entry| exported_csv << entry } + expect(exported_csv[0]).to eq(["Type", "Assigned", "Poster", "Flagger", "Resolution time"]) + expect(exported_csv[1]).to eq( + ["spam", flagger.username, post.user.username, flagger.username, "0.0"], + ) + end end end