From ee79433ced6daacdc6c3a58167b377503699e9f5 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 5 Feb 2025 09:32:10 +0000 Subject: [PATCH] [Lincolnshire] Add staff role to CSV export. Extends the dashboard CSV export to include additional columns for staff roles when a report is contributed by a staff member. --- perllib/FixMyStreet/Cobrand/Lincolnshire.pm | 26 +++++++++++++++++++++ perllib/FixMyStreet/Script/CSVExport.pm | 2 +- t/cobrand/lincolnshire.t | 26 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm index 97218efefff..f66344be28e 100644 --- a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm +++ b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm @@ -243,4 +243,30 @@ sub open311_get_user { return $user; } +sub dashboard_export_problems_add_columns { + my ($self, $csv) = @_; + + $csv->add_csv_columns( + staff_role => 'Staff Role', + ); + + return if $csv->dbi; # All covered already + + my $user_lookup = $self->csv_staff_users; + my $userroles = $self->csv_staff_roles($user_lookup); + + $csv->csv_extra_data(sub { + my $report = shift; + + my $by = $report->get_extra_metadata('contributed_by'); + my $staff_role = ''; + if ($by) { + $staff_role = join(',', @{$userroles->{$by} || []}); + } + return { + staff_role => $staff_role, + }; + }); +} + 1; diff --git a/perllib/FixMyStreet/Script/CSVExport.pm b/perllib/FixMyStreet/Script/CSVExport.pm index a1492022303..df438ca3e28 100644 --- a/perllib/FixMyStreet/Script/CSVExport.pm +++ b/perllib/FixMyStreet/Script/CSVExport.pm @@ -55,7 +55,7 @@ my $EXTRAS = { reassigned => { tfl => 1 }, 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 }, + staff_roles => { brent => 1, bromley => 1, lincolnshire => 1, northumberland => 1, oxfordshire => 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 }, diff --git a/t/cobrand/lincolnshire.t b/t/cobrand/lincolnshire.t index b29c4628c20..86ba7b6c07a 100644 --- a/t/cobrand/lincolnshire.t +++ b/t/cobrand/lincolnshire.t @@ -103,6 +103,32 @@ FixMyStreet::override_config { $p->delete; }; + + subtest "Dashboard CSV export includes extra staff columns" => sub { + my $csv_staff = $mech->create_user_ok( + 'csvstaff@lincolnshire.gov.uk', + name => 'CSV Staff', + from_body => $body, + ); + my $csv_role = FixMyStreet::DB->resultset("Role")->create({ + body => $body, + name => 'CSV Role', + permissions => ['moderate', 'user_edit'], + }); + $csv_staff->add_to_roles($csv_role); + + my @csv_problems = $mech->create_problems_for_body( 1, $body->id, 'CSV Export Test Issue', { + cobrand => 'lincolnshire', + user => $csv_staff, + extra => { contributed_by => $csv_staff->id }, + }); + + $mech->log_in_ok($csv_staff->email); + $mech->get_ok('/dashboard?export=1'); + + $mech->content_contains('"Staff Role"'); + $mech->content_like(qr/CSV Role/, "CSV export includes staff role"); + }; }; FixMyStreet::override_config {