aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
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 /perllib/FixMyStreet/Cobrand/IsleOfWight.pm
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.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/IsleOfWight.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand/IsleOfWight.pm34
1 files changed, 27 insertions, 7 deletions
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 {