diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 33 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 11 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 14 | ||||
-rw-r--r-- | t/cobrand/bathnes.t | 22 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 49 | ||||
-rw-r--r-- | t/cobrand/fixmystreet.t | 7 | ||||
-rw-r--r-- | web/cobrands/buckinghamshire/assets.js | 25 |
7 files changed, 100 insertions, 61 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/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index bb4a48d65..3ecb13b6a 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -716,4 +716,15 @@ sub encoded_content { return encode_utf8($self->content); } +sub content_as_csv { + my $self = shift; + open my $data_handle, '<', \$self->content; + my $csv = Text::CSV->new({ binary => 1 }); + my @rows; + while (my $row = $csv->getline($data_handle)) { + push @rows, $row; + } + return @rows; +} + 1; diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 37903513c..ff8d1a9d5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -167,12 +167,7 @@ FixMyStreet::override_config { areas => ",$alt_area_id,2651,", }); $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 19, '1 (header) + 18 (reports) = 19 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -209,12 +204,7 @@ FixMyStreet::override_config { subtest 'export updates as csv' => sub { $mech->get_ok('/dashboard?updates=1&export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 15, '1 (header) + 14 (updates) = 15 lines'; is scalar @{$rows[0]}, 8, '8 columns present'; diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index 4db2f058c..6586dcb96 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -64,12 +64,7 @@ subtest 'extra CSV columns are absent if permission not granted' => sub { $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -125,12 +120,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 24, '24 columns present'; @@ -194,13 +184,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1&updates=1'); - open $data_handle, '<', \$mech->content; - $csv = Text::CSV->new( { binary => 1 } ); - @rows = (); - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } - + @rows = $mech->content_as_csv; is scalar @rows, 1, '1 (header) + 0 (updates)'; is scalar @{$rows[0]}, 10, '10 columns present'; is_deeply $rows[0], 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(); diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index 57ab51198..b47269db4 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -59,12 +59,7 @@ FixMyStreet::override_config { }); $mech->get_ok('/reports/Birmingham/summary?csv=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 101, '1 (header) + 100 (reports) = 101 lines'; is scalar @{$rows[0]}, 10, '10 columns present'; diff --git a/web/cobrands/buckinghamshire/assets.js b/web/cobrands/buckinghamshire/assets.js index 2f69ba6f6..e0b6f729b 100644 --- a/web/cobrands/buckinghamshire/assets.js +++ b/web/cobrands/buckinghamshire/assets.js @@ -21,7 +21,7 @@ var defaults = { asset_id_field: 'central_as', attributes: { central_asset_id: 'central_as', - site_code: 'Site_code' + site_code: 'site_code' }, geometryName: 'msGeometry', srsName: "EPSG:3857", @@ -35,10 +35,6 @@ fixmystreet.assets.add($.extend(true, {}, defaults, { TYPENAME: "Grit_Bins" } }, - attributes: { - central_asset_id: 'central_as', - site_code: 'site_code' // different capitalisation, sigh - }, asset_category: ["Salt bin damaged", "Salt bin refill"], asset_item: 'grit bin' })); @@ -106,10 +102,6 @@ var streetlight_code_to_type = { var labeled_defaults = $.extend(true, {}, defaults, { select_action: true, stylemap: streetlight_stylemap, - attributes: { - central_asset_id: 'central_as', - site_code: 'site_code' - }, feature_code: 'feature_id', actions: { asset_found: function(asset, config) { @@ -169,9 +161,6 @@ fixmystreet.assets.add($.extend(true, {}, labeled_defaults, { TYPENAME: "Beacons" } }, - attributes: { - central_asset_id: 'central_as', - }, asset_category: [ 'Belisha Beacon broken', ], @@ -185,9 +174,6 @@ fixmystreet.assets.add($.extend(true, {}, labeled_defaults, { TYPENAME: "Beacon_Column" } }, - attributes: { - central_asset_id: 'central_as', - }, asset_category: [ 'Belisha Beacon broken', ], @@ -201,9 +187,6 @@ fixmystreet.assets.add($.extend(true, {}, labeled_defaults, { TYPENAME: "Crossings" } }, - attributes: { - central_asset_id: 'central_as', - }, feature_code: 'asset_no', asset_category: [ 'Traffic lights & crossings problems with buttons, beep or lamps', @@ -218,9 +201,6 @@ fixmystreet.assets.add($.extend(true, {}, labeled_defaults, { TYPENAME: "Signs_Union" } }, - attributes: { - central_asset_id: 'central_as', - }, asset_category: [ 'Sign light not working', 'Sign problem', @@ -234,9 +214,6 @@ fixmystreet.assets.add($.extend(true, {}, defaults, { TYPENAME: "Gullies" } }, - attributes: { - central_asset_id: 'central_as', - }, asset_category: [ 'Blocked drain' ], |