aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2019-09-09 17:43:59 +0100
committerStruan Donald <struan@exo.org.uk>2019-09-27 17:43:38 +0100
commit6a1ad33c07de846f15af48c7a01eb567d9263da3 (patch)
tree350a272827596636a36526acbdab24404fe875fe
parent9ac592d4327ea7ed253ed2d9eeed89e4efbcd7c5 (diff)
[IsleOfWight] correctly filter categories on report page
If it's a standard user only display the Triage category list but if one of these is selected then look up all the categories in that group and use those to select the reports to display. It it's a staff user then ignore the Triage categories.
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm74
-rw-r--r--perllib/FixMyStreet/Cobrand/IsleOfWight.pm34
-rw-r--r--templates/email/isleofwight/confirm_report_sent.html (renamed from templates/email/isleofwight/other-reported.html)0
-rw-r--r--templates/email/isleofwight/confirm_report_sent.txt (renamed from templates/email/isleofwight/other-reported.txt)0
5 files changed, 105 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 9b33b42b4..8e167a70d 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -165,10 +165,13 @@ sub ward : Path : Args(2) {
$c->stash->{stats} = $c->cobrand->get_report_stats();
my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, {
- columns => [ 'id', 'category', 'extra' ],
+ columns => [ 'id', 'category', 'extra', 'body_id', 'send_method' ],
distinct => 1,
order_by => [ 'category' ],
} )->all;
+
+ $c->cobrand->call_hook('munge_reports_category_list', \@categories);
+
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 377253955..bfa991b09 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -38,6 +38,24 @@ sub restriction {
return {};
}
+sub munge_reports_categories_list {
+ my ($self, $categories) = @_;
+
+ my %bodies = map { $_->body->name => $_->body } @$categories;
+ if ( $bodies{'Isle of Wight Council'} ) {
+ my $user = $self->{c}->user;
+ my $b = $bodies{'Isle of Wight Council'};
+
+ if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) {
+ @$categories = grep { !$_->send_method || $_->send_method ne 'Triage' } @$categories;
+ return @$categories;
+ }
+
+ @$categories = grep { $_->send_method && $_->send_method eq 'Triage' } @$categories;
+ return @$categories;
+ }
+}
+
sub munge_category_list {
my ($self, $options, $contacts, $extras) = @_;
@@ -62,6 +80,62 @@ sub munge_category_list {
}
}
+sub munge_load_and_group_problems {
+ my ($self, $where, $filter) = @_;
+
+ return unless $where->{category} && $self->{c}->stash->{body}->name eq 'Isle of Wight Council';
+
+ my $cat_names = $self->expand_triage_cat_list($where->{category});
+
+ $where->{category} = $cat_names;
+ my $problems = $self->problems->search($where, $filter);
+ return $problems;
+}
+
+sub expand_triage_cat_list {
+ my ($self, $categories) = @_;
+
+ my $b = $self->{c}->stash->{body};
+
+ my $all_cats = $self->{c}->model('DB::Contact')->not_deleted->search(
+ {
+ body_id => $b->id,
+ send_method => [{ '!=', 'Triage'}, undef]
+ }
+ );
+
+ my %group_to_category;
+ while ( my $cat = $all_cats->next ) {
+ next unless $cat->get_extra_metadata('group');
+ my $groups = $cat->get_extra_metadata('group');
+ $groups = ref $groups eq 'ARRAY' ? $groups : [ $groups ];
+ for my $group ( @$groups ) {
+ $group_to_category{$group} //= [];
+ push @{ $group_to_category{$group} }, $cat->category;
+ }
+ }
+
+ my $cats = $self->{c}->model('DB::Contact')->not_deleted->search(
+ {
+ body_id => $b->id,
+ category => $categories
+ }
+ );
+
+ my @cat_names;
+ while ( my $cat = $cats->next ) {
+ if ( $cat->send_method && $cat->send_method eq 'Triage' ) {
+ # include the category itself
+ push @cat_names, $cat->category;
+ push @cat_names, @{ $group_to_category{$cat->category} } if $group_to_category{$cat->category};
+ } else {
+ push @cat_names, $cat->category;
+ }
+ }
+
+ return \@cat_names;
+}
+
sub title_list {
my $self = shift;
my $areas = shift;
diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
index c8fc75eaa..dd4b936d7 100644
--- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
+++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
@@ -88,6 +88,22 @@ sub open311_munge_update_params {
}
# this handles making sure the user sees the right categories on the new report page
+sub munge_reports_category_list {
+ my ($self, $categories) = @_;
+
+ my $user = $self->{c}->user;
+ my %bodies = map { $_->body->name => $_->body } @$categories;
+ my $b = $bodies{'Isle of Wight Council'};
+
+ if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) {
+ @$categories = grep { !$_->send_method || $_->send_method ne 'Triage' } @$categories;
+ return @$categories;
+ }
+
+ @$categories = grep { $_->send_method && $_->send_method eq 'Triage' } @$categories;
+ return @$categories;
+}
+
sub munge_category_list {
my ($self, $options, $contacts, $extras) = @_;
@@ -129,9 +145,9 @@ sub munge_load_and_group_problems {
return unless $where->{category};
- my @cat_names = $self->expand_triage_cat_list($where->{category});
+ my $cat_names = $self->expand_triage_cat_list($where->{category});
- $where->{category} = \@cat_names;
+ $where->{category} = $cat_names;
my $problems = $self->problems->search($where, $filter);
return $problems;
}
@@ -142,8 +158,8 @@ sub munge_filter_category {
my $c = $self->{c};
return unless $c->stash->{filter_category};
- my @cat_names = $self->expand_triage_cat_list([ keys %{$c->stash->{filter_category}} ]);
- $c->stash->{filter_category} = { map { $_ => 1 } @cat_names };
+ my $cat_names = $self->expand_triage_cat_list([ keys %{$c->stash->{filter_category}} ]);
+ $c->stash->{filter_category} = { map { $_ => 1 } @$cat_names };
}
# this assumes that each Triage category has the same name as a group
@@ -164,8 +180,12 @@ sub expand_triage_cat_list {
my %group_to_category;
while ( my $cat = $all_cats->next ) {
next unless $cat->get_extra_metadata('group');
- $group_to_category{$cat->get_extra_metadata('group')} //= [];
- push @{ $group_to_category{$cat->get_extra_metadata('group')} }, $cat->category;
+ my $groups = $cat->get_extra_metadata('group');
+ $groups = ref $groups eq 'ARRAY' ? $groups : [ $groups ];
+ for my $group ( @$groups ) {
+ $group_to_category{$group} //= [];
+ push @{ $group_to_category{$group} }, $cat->category;
+ }
}
my $cats = $self->{c}->model('DB::Contact')->not_deleted->search(
@@ -186,7 +206,7 @@ sub expand_triage_cat_list {
}
}
- return @cat_names;
+ return \@cat_names;
}
sub open311_get_update_munging {
diff --git a/templates/email/isleofwight/other-reported.html b/templates/email/isleofwight/confirm_report_sent.html
index 8e85c5729..8e85c5729 100644
--- a/templates/email/isleofwight/other-reported.html
+++ b/templates/email/isleofwight/confirm_report_sent.html
diff --git a/templates/email/isleofwight/other-reported.txt b/templates/email/isleofwight/confirm_report_sent.txt
index a368bd95e..a368bd95e 100644
--- a/templates/email/isleofwight/other-reported.txt
+++ b/templates/email/isleofwight/confirm_report_sent.txt