Skip to content

Commit ee79433

Browse files
chrismyttondracos
authored andcommitted
[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.
1 parent b2cca58 commit ee79433

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

perllib/FixMyStreet/Cobrand/Lincolnshire.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,30 @@ sub open311_get_user {
243243
return $user;
244244
}
245245

246+
sub dashboard_export_problems_add_columns {
247+
my ($self, $csv) = @_;
248+
249+
$csv->add_csv_columns(
250+
staff_role => 'Staff Role',
251+
);
252+
253+
return if $csv->dbi; # All covered already
254+
255+
my $user_lookup = $self->csv_staff_users;
256+
my $userroles = $self->csv_staff_roles($user_lookup);
257+
258+
$csv->csv_extra_data(sub {
259+
my $report = shift;
260+
261+
my $by = $report->get_extra_metadata('contributed_by');
262+
my $staff_role = '';
263+
if ($by) {
264+
$staff_role = join(',', @{$userroles->{$by} || []});
265+
}
266+
return {
267+
staff_role => $staff_role,
268+
};
269+
});
270+
}
271+
246272
1;

perllib/FixMyStreet/Script/CSVExport.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ my $EXTRAS = {
5555
reassigned => { tfl => 1 },
5656
assigned_to => { northumberland => 1, tfl => 1 },
5757
staff_user => { bathnes => 1, bromley => 1, buckinghamshire => 1, northumberland => 1, peterborough => 1 },
58-
staff_roles => { brent => 1, bromley => 1, northumberland => 1, oxfordshire => 1 },
58+
staff_roles => { brent => 1, bromley => 1, lincolnshire => 1, northumberland => 1, oxfordshire => 1 },
5959
user_details => { bathnes => 1, bexley => 1, brent => 1, camden => 1, cyclinguk => 1, highwaysengland => 1, kingston => 1, southwark => 1, sutton => 1 },
6060
comment_content => { highwaysengland => 1 },
6161
db_state => { peterborough => 1 },

t/cobrand/lincolnshire.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,32 @@ FixMyStreet::override_config {
103103

104104
$p->delete;
105105
};
106+
107+
subtest "Dashboard CSV export includes extra staff columns" => sub {
108+
my $csv_staff = $mech->create_user_ok(
109+
110+
name => 'CSV Staff',
111+
from_body => $body,
112+
);
113+
my $csv_role = FixMyStreet::DB->resultset("Role")->create({
114+
body => $body,
115+
name => 'CSV Role',
116+
permissions => ['moderate', 'user_edit'],
117+
});
118+
$csv_staff->add_to_roles($csv_role);
119+
120+
my @csv_problems = $mech->create_problems_for_body( 1, $body->id, 'CSV Export Test Issue', {
121+
cobrand => 'lincolnshire',
122+
user => $csv_staff,
123+
extra => { contributed_by => $csv_staff->id },
124+
});
125+
126+
$mech->log_in_ok($csv_staff->email);
127+
$mech->get_ok('/dashboard?export=1');
128+
129+
$mech->content_contains('"Staff Role"');
130+
$mech->content_like(qr/CSV Role/, "CSV export includes staff role");
131+
};
106132
};
107133

108134
FixMyStreet::override_config {

0 commit comments

Comments
 (0)