Skip to content

Commit

Permalink
Export all articles. (#2235)
Browse files Browse the repository at this point in the history
This commit adds a new type of list export: all articles.

Reference: CV2-5007.
  • Loading branch information
caiosba authored Feb 25, 2025
1 parent d95e6b9 commit 5d38a98
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ def get_dashboard_exported_data(filters, dashboard_type)
data
end

def get_articles_exported_data(query)
fact_check_data = FactCheck.get_exported_data(query, self)
explainer_data = Explainer.get_exported_data(query, self).drop(1) # Remove the header, we don't need a second header
fact_check_data + explainer_data
end

# Platforms for which statistics are available (e.g., at least one media request)
def statistics_platforms
TiplineRequest.joins(:project_media).where('project_medias.team_id' => self.id).distinct.pluck(:platform)
Expand Down
6 changes: 5 additions & 1 deletion lib/list_export.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ListExport
TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard ]
TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard, :articles]

def initialize(type, query, team_id)
@type = type
Expand All @@ -21,6 +21,8 @@ def number_of_rows
@team.filtered_fact_checks(@parsed_query).count
when :explainer
@team.filtered_explainers(@parsed_query).count
when :articles
@team.filtered_explainers(@parsed_query).count + @team.filtered_fact_checks(@parsed_query).count
when :articles_dashboard, :tipline_dashboard
1 # Always maintain one row for dashboard data, but use different columns for export.
end
Expand Down Expand Up @@ -64,6 +66,8 @@ def export_data
FactCheck.get_exported_data(@parsed_query, @team)
when :explainer
Explainer.get_exported_data(@parsed_query, @team)
when :articles
@team.get_articles_exported_data(@parsed_query)
when :articles_dashboard, :tipline_dashboard
@team.get_dashboard_exported_data(@parsed_query, @type)
end
Expand Down
16 changes: 16 additions & 0 deletions test/lib/list_export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,20 @@ def teardown
assert_equal 1, csv_content.size
assert_equal 1, export.number_of_rows
end

test "should export articles CSV" do
t = create_team
create_explainer team: t
pm = create_project_media team: t
cd = create_claim_description project_media: pm
create_fact_check claim_description: cd

export = ListExport.new(:articles, '{}', t.id)
csv_url = export.generate_csv_and_send_email(create_user)
response = Net::HTTP.get_response(URI(csv_url))
assert_equal 200, response.code.to_i
csv_content = CSV.parse(response.body, headers: true)
assert_equal 2, csv_content.size
assert_equal 2, export.number_of_rows
end
end

0 comments on commit 5d38a98

Please sign in to comment.