From fea0f9eeb46e28fe8e7e0d71a7c55ceb0913c2e6 Mon Sep 17 00:00:00 2001 From: Nik Gupta Date: Mon, 27 Jan 2025 19:41:43 +0000 Subject: [PATCH] [Southwark] Include user email in CSV report export. For https://mysocietysupport.freshdesk.com/a/tickets/5051 --- perllib/FixMyStreet/Cobrand/Southwark.pm | 29 ++++++++++++++++++++++++ perllib/FixMyStreet/Script/CSVExport.pm | 2 +- t/cobrand/southwark.t | 13 +++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/perllib/FixMyStreet/Cobrand/Southwark.pm b/perllib/FixMyStreet/Cobrand/Southwark.pm index ad20917e264..ad965f5fb41 100644 --- a/perllib/FixMyStreet/Cobrand/Southwark.pm +++ b/perllib/FixMyStreet/Cobrand/Southwark.pm @@ -273,4 +273,33 @@ sub _filter_categories_by_group { return values %contacts_hash; } +=head2 dashboard_export_problems_add_columns + +Has user email added to their csv reports export. + +=cut + +sub dashboard_export_problems_add_columns { + my ($self, $csv) = @_; + + $csv->add_csv_columns( + user_email => 'User Email', + ); + + $csv->objects_attrs({ + '+columns' => ['user.email'], + join => 'user', + }); + + return if $csv->dbi; # user_email already included. + + $csv->csv_extra_data(sub { + my $report = shift; + return { + user_email => $report->user ? $report->user->email : '', + }; + }); +} + + 1; diff --git a/perllib/FixMyStreet/Script/CSVExport.pm b/perllib/FixMyStreet/Script/CSVExport.pm index c85ec20af34..a1492022303 100644 --- a/perllib/FixMyStreet/Script/CSVExport.pm +++ b/perllib/FixMyStreet/Script/CSVExport.pm @@ -56,7 +56,7 @@ my $EXTRAS = { assigned_to => { northumberland => 1, tfl => 1 }, staff_user => { bathnes => 1, bromley => 1, buckinghamshire => 1, northumberland => 1, peterborough => 1 }, staff_roles => { brent => 1, bromley => 1, northumberland => 1, oxfordshire => 1 }, - user_details => { bathnes => 1, bexley => 1, brent => 1, camden => 1, cyclinguk => 1, highwaysengland => 1, kingston => 1, sutton => 1 }, + user_details => { bathnes => 1, bexley => 1, brent => 1, camden => 1, cyclinguk => 1, highwaysengland => 1, kingston => 1, southwark => 1, sutton => 1 }, comment_content => { highwaysengland => 1 }, db_state => { peterborough => 1 }, alerts_count => { surrey => 1 }, diff --git a/t/cobrand/southwark.t b/t/cobrand/southwark.t index 8d4686ceb70..986a265b000 100644 --- a/t/cobrand/southwark.t +++ b/t/cobrand/southwark.t @@ -32,6 +32,8 @@ my $southwark = $mech->create_body_ok( { cobrand => 'southwark' }, ); +my $staffuser = $mech->create_user_ok( 'staff@example.com', name => 'Staffer', from_body => $southwark ); + $mech->create_contact_ok( body_id => $southwark->id, category => 'Abandoned Bike (Street)', @@ -97,6 +99,17 @@ FixMyStreet::override_config { }, "Southwark 'estate' area doesn't have TfL categories or street category"; }; + + subtest 'Dashboard CSV extra columns' => sub { + $mech->log_in_ok($staffuser->email); + $mech->create_problems_for_body(1, $southwark->id, 'Title', { + user => $staffuser, + cobrand => 'southwark', + }); + $mech->get_ok('/dashboard?export=1'); + $mech->content_contains('"User Email"'); + $mech->content_contains($staffuser->email); + }; }; done_testing;