Skip to content

Commit

Permalink
[Lincolnshire] Add staff role to CSV export.
Browse files Browse the repository at this point in the history
Extends the dashboard CSV export to include additional columns for staff
roles when a report is contributed by a staff member.
  • Loading branch information
chrismytton authored and dracos committed Feb 12, 2025
1 parent b2cca58 commit ee79433
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
26 changes: 26 additions & 0 deletions perllib/FixMyStreet/Cobrand/Lincolnshire.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Script/CSVExport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
26 changes: 26 additions & 0 deletions t/cobrand/lincolnshire.t
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'[email protected]',
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 {
Expand Down

0 comments on commit ee79433

Please sign in to comment.