aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Buckinghamshire.pm33
-rw-r--r--t/cobrand/bucks.t49
2 files changed, 82 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
index 095e80604..5e9316709 100644
--- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
@@ -197,6 +197,39 @@ sub default_map_zoom { 3 }
sub enable_category_groups { 1 }
+sub _dashboard_export_add_columns {
+ my $self = shift;
+ my $c = $self->{c};
+
+ push @{$c->stash->{csv}->{headers}}, "Staff User";
+ push @{$c->stash->{csv}->{columns}}, "staff_user";
+
+ # All staff users, for contributed_by lookup
+ my @user_ids = $c->model('DB::User')->search(
+ { from_body => $self->body->id },
+ { columns => [ 'id', 'email', ] })->all;
+ my %user_lookup = map { $_->id => $_->email } @user_ids;
+
+ $c->stash->{csv}->{extra_data} = sub {
+ my $report = shift;
+ my $staff_user = '';
+ if (my $contributed_by = $report->get_extra_metadata('contributed_by')) {
+ $staff_user = $user_lookup{$contributed_by};
+ }
+ return {
+ staff_user => $staff_user,
+ };
+ };
+}
+
+sub dashboard_export_updates_add_columns {
+ shift->_dashboard_export_add_columns;
+}
+
+sub dashboard_export_problems_add_columns {
+ shift->_dashboard_export_add_columns;
+}
+
# Enable adding/editing of parish councils in the admin
sub add_extra_areas {
my ($self, $areas) = @_;
diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t
index d9273fbf8..ba0a20ba9 100644
--- a/t/cobrand/bucks.t
+++ b/t/cobrand/bucks.t
@@ -6,6 +6,7 @@ my $mech = FixMyStreet::TestMech->new;
my $body = $mech->create_body_ok(2217, 'Buckinghamshire', {
send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms' });
+my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body);
$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY");
$mech->create_contact_ok(body_id => $body->id, category => 'Potholes', email => "POT");
@@ -58,6 +59,10 @@ subtest 'flytipping on road sent to extra email' => sub {
($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', {
category => 'Potholes', cobrand => 'fixmystreet',
latitude => 51.812244, longitude => -0.827363,
+ extra => {
+ contributed_as => 'another_user',
+ contributed_by => $counciluser->id,
+ },
});
subtest 'pothole on road not sent to extra email' => sub {
@@ -172,6 +177,50 @@ for my $test (
};
}
+subtest 'extra CSV columns are present' => sub {
+ $mech->log_in_ok( $counciluser->email );
+
+ $mech->get_ok('/dashboard?export=1');
+
+ my @rows = $mech->content_as_csv;
+ is scalar @rows, 4, '1 (header) + 3 (reports) = 4 lines';
+ is scalar @{$rows[0]}, 21, '21 columns present';
+
+ is_deeply $rows[0],
+ [
+ 'Report ID', 'Title', 'Detail', 'User Name', 'Category',
+ 'Created', 'Confirmed', 'Acknowledged', 'Fixed', 'Closed',
+ 'Status', 'Latitude', 'Longitude', 'Query', 'Ward',
+ 'Easting', 'Northing', 'Report URL', 'Site Used',
+ 'Reported As', 'Staff User',
+ ],
+ 'Column headers look correct';
+
+ is $rows[1]->[20], '', 'Staff User is empty if not made on behalf of another user';
+ is $rows[2]->[20], $counciluser->email, 'Staff User is correct if made on behalf of another user';
+ is $rows[3]->[20], '', 'Staff User is empty if not made on behalf of another user';
+
+ $mech->create_comment_for_problem($report, $counciluser, 'Staff User', 'Some update text', 'f', 'confirmed', undef, {
+ extra => { contributed_as => 'body' }});
+ $mech->create_comment_for_problem($report, $counciluser, 'Other User', 'Some update text', 'f', 'confirmed', undef, {
+ extra => { contributed_as => 'another_user', contributed_by => $counciluser->id }});
+
+ $mech->get_ok('/dashboard?export=1&updates=1');
+
+ @rows = $mech->content_as_csv;
+ is scalar @rows, 3, '1 (header) + 2 (updates)';
+ is scalar @{$rows[0]}, 9, '9 columns present';
+ is_deeply $rows[0],
+ [
+ 'Report ID', 'Update ID', 'Date', 'Status', 'Problem state',
+ 'Text', 'User Name', 'Reported As', 'Staff User',
+ ],
+ 'Column headers look correct';
+
+ is $rows[1]->[8], '', 'Staff User is empty if not made on behalf of another user';
+ is $rows[2]->[8], $counciluser->email, 'Staff User is correct if made on behalf of another user';
+};
+
};
done_testing();