aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-05-04 16:33:01 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-05-07 10:27:09 +0100
commita2cc36b0d94143d1150a73993541eb829bd9b9fa (patch)
tree211643081ea5e55b8dbedbe86f251740811631e5
parentab0d1dc84b1ed7a1c572e986eda3a4bdc5157d77 (diff)
Include group in CSV export if enabled.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm29
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm27
-rw-r--r--perllib/FixMyStreet/Cobrand/TfL.pm12
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Contact.pm9
-rw-r--r--t/cobrand/bexley.t19
-rw-r--r--t/cobrand/tfl.t1
7 files changed, 37 insertions, 61 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7772d93e8..0877dcca0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
- Speed up dashboard export and report search. #2988
- Allow a template to be an initial update on reports. #2973
- Interface for disabling updates for certain categories. #2991
+ - Include group in CSV export if enabled. #2994
- Bugfixes:
- Application user in Docker container can't install packages. #2914
- Look at all categories when sending reports.
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index f3b607ba8..e5a526efc 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -152,14 +152,14 @@ sub index : Path : Args(0) {
sub construct_rs_filter : Private {
my ($self, $c, $updates) = @_;
+ my $table_name = $updates ? 'problem' : 'me';
+
my %where;
$where{areas} = [ map { { 'like', "%,$_,%" } } @{$c->stash->{ward}} ]
if @{$c->stash->{ward}};
- $where{category} = $c->stash->{category}
+ $where{"$table_name.category"} = $c->stash->{category}
if $c->stash->{category};
- my $table_name = $updates ? 'problem' : 'me';
-
my $state = $c->stash->{q_state};
if ( FixMyStreet::DB::Result::Problem->fixed_states->{$state} ) { # Probably fixed - council
$where{"$table_name.state"} = [ FixMyStreet::DB::Result::Problem->fixed_states() ];
@@ -347,10 +347,17 @@ sub export_as_csv_updates : Private {
sub export_as_csv : Private {
my ($self, $c) = @_;
+ my $groups = $c->cobrand->enable_category_groups ? 1 : 0;
+ my $join = ['comments'];
+ my $columns = ['comments.problem_state', 'comments.state', 'comments.confirmed', 'comments.mark_fixed'];
+ if ($groups) {
+ push @$join, 'contact';
+ push @$columns, 'contact.extra';
+ }
my $csv = $c->stash->{csv} = {
objects => $c->stash->{objects_rs}->search_rs({}, {
- join => 'comments',
- '+columns' => ['comments.problem_state', 'comments.state', 'comments.confirmed', 'comments.mark_fixed'],
+ join => $join,
+ '+columns' => $columns,
order_by => ['me.confirmed', 'me.id'],
cursor_page_size => 1000,
}),
@@ -360,6 +367,7 @@ sub export_as_csv : Private {
'Detail',
'User Name',
'Category',
+ $groups ? ('Subcategory') : (),
'Created',
'Confirmed',
'Acknowledged',
@@ -381,6 +389,7 @@ sub export_as_csv : Private {
'detail',
'user_name_display',
'category',
+ $groups ? ('subcategory') : (),
'created',
'confirmed',
'acknowledged',
@@ -481,6 +490,16 @@ sub generate_csv : Private {
($hashref->{local_coords_x}, $hashref->{local_coords_y}) =
$obj->local_coords;
}
+
+ if ($asked_for{subcategory}) {
+ my $group = $obj->contact && $obj->contact->get_extra_metadata('group') || '';
+ $group = join(',', ref $group ? @$group : $group);
+ if ($group) {
+ $hashref->{subcategory} = $obj->category;
+ $hashref->{category} = $group;
+ }
+ }
+
if ($obj->can('url')) {
my $base = $c->cobrand->base_url_for_report($obj->can('problem') ? $obj->problem : $obj);
$hashref->{url} = join '', $base, $obj->url;
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index f37394794..ad3036711 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -216,33 +216,6 @@ sub email_list {
return @to;
}
-sub dashboard_export_problems_add_columns {
- my $self = shift;
- my $c = $self->{c};
-
- my %groups;
- if ($c->stash->{body}) {
- %groups = FixMyStreet::DB->resultset('Contact')->search({
- body_id => $c->stash->{body}->id,
- })->group_lookup;
- }
-
- splice @{$c->stash->{csv}->{headers}}, 5, 0, 'Subcategory';
- splice @{$c->stash->{csv}->{columns}}, 5, 0, 'subcategory';
-
- $c->stash->{csv}->{extra_data} = sub {
- my $report = shift;
-
- if ($groups{$report->category}) {
- return {
- category => $groups{$report->category},
- subcategory => $report->category,
- };
- }
- return {};
- };
-}
-
sub _is_out_of_hours {
my $time = localtime;
return 1 if $time->hour > 16 || ($time->hour == 16 && $time->min >= 45);
diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm
index b98ad1d8b..78b7c271a 100644
--- a/perllib/FixMyStreet/Cobrand/TfL.pm
+++ b/perllib/FixMyStreet/Cobrand/TfL.pm
@@ -245,16 +245,6 @@ sub dashboard_export_problems_add_columns {
my $self = shift;
my $c = $self->{c};
- my %groups;
- if ($c->stash->{body}) {
- %groups = FixMyStreet::DB->resultset('Contact')->search({
- body_id => $c->stash->{body}->id,
- })->group_lookup;
- }
-
- splice @{$c->stash->{csv}->{headers}}, 5, 0, 'Subcategory';
- splice @{$c->stash->{csv}->{columns}}, 5, 0, 'subcategory';
-
$c->stash->{csv}->{headers} = [
map { $_ eq 'Ward' ? 'Borough' : $_ } @{ $c->stash->{csv}->{headers} },
"Agent responsible",
@@ -315,8 +305,6 @@ sub dashboard_export_problems_add_columns {
my $fields = {
acknowledged => $report->whensent,
agent_responsible => $agent ? $agent->name : '',
- category => $groups{$report->category},
- subcategory => $report->category,
user_name_display => $user_name_display,
safety_critical => $safety_critical,
delivered_to => join(',', @$delivered_to),
diff --git a/perllib/FixMyStreet/DB/ResultSet/Contact.pm b/perllib/FixMyStreet/DB/ResultSet/Contact.pm
index 801d20cc0..3aceee9e7 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Contact.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Contact.pm
@@ -90,13 +90,4 @@ sub summary_count {
);
}
-sub group_lookup {
- my $rs = shift;
- map {
- my $group = $_->get_extra_metadata('group') || '';
- $group = join(',', ref $group ? @$group : $group);
- $_->category => $group
- } $rs->all;
-}
-
1;
diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t
index 352e61389..91e30ff50 100644
--- a/t/cobrand/bexley.t
+++ b/t/cobrand/bexley.t
@@ -50,14 +50,17 @@ FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'bexley' ],
MAPIT_URL => 'http://mapit.uk/',
STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
- COBRAND_FEATURES => { open311_email => { bexley => {
- p1 => 'p1@bexley',
- p1confirm => 'p1confirm@bexley',
- lighting => 'thirdparty@notbexley.example.com,another@notbexley.example.com',
- outofhours => 'outofhours@bexley,ooh2@bexley',
- flooding => 'flooding@bexley',
- eh => 'eh@bexley',
- } } },
+ COBRAND_FEATURES => {
+ open311_email => { bexley => {
+ p1 => 'p1@bexley',
+ p1confirm => 'p1confirm@bexley',
+ lighting => 'thirdparty@notbexley.example.com,another@notbexley.example.com',
+ outofhours => 'outofhours@bexley,ooh2@bexley',
+ flooding => 'flooding@bexley',
+ eh => 'eh@bexley',
+ } },
+ category_groups => { bexley => 1 },
+ },
}, sub {
subtest 'cobrand displays council name' => sub {
diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t
index 8ddc3d671..f8e0a11c8 100644
--- a/t/cobrand/tfl.t
+++ b/t/cobrand/tfl.t
@@ -188,6 +188,7 @@ FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'tfl', 'bromley', 'fixmystreet'],
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => {
+ category_groups => { tfl => 1 },
internal_ips => { tfl => [ '127.0.0.1' ] },
base_url => {
tfl => 'https://street.tfl'