diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-04 16:53:59 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-09-02 14:52:54 +0100 |
commit | 4f96bd558e0b915adef325f27ac5ccd65e9b310f (patch) | |
tree | f4646290b16da6b1eeb4d91ddb6348c900e5e30b | |
parent | af317bf3ade4694ede7a4d8d163929b8576c7bdd (diff) |
[IoW] Small refactor of munging functions.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 50 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/IsleOfWight.pm | 3 |
3 files changed, 25 insertions, 36 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 7b98f01f8..803bfad58 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -240,12 +240,8 @@ sub check_and_stash_category : Private { $c->stash->{bodies_ids} = [ map { $_->id } @bodies]; $c->{stash}->{list_of_names_as_string} = $csv->string; - my $where = { body_id => [ keys %bodies ], }; - - my $cobrand_where = $c->cobrand->call_hook('munge_around_category_where', $where ); - if ( $cobrand_where ) { - $where = $cobrand_where; - } + my $where = { body_id => [ keys %bodies ], }; + $c->cobrand->call_hook('munge_around_category_where', $where); my @categories = $c->model('DB::Contact')->not_deleted->search( $where, diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index ca041bf70..09f5f5296 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -54,32 +54,33 @@ sub relative_url_for_report { sub munge_around_category_where { my ($self, $where) = @_; + my $iow = grep { $_->name eq 'Isle of Wight Council' } @{ $self->{c}->stash->{around_bodies} }; + if ($iow) { + # display all the categories on Isle of Wight at the moment as there's no way to + # do the expand bit later as we fetch it using ajax which uses a bounding box so + # can't determine the body + $where->{send_method} = [ { '!=' => 'Triage' }, undef ]; + } +} + +sub _iow_category_munge { + my ($self, $body, $categories) = @_; my $user = $self->{c}->user; - my @iow = grep { $_->name eq 'Isle of Wight Council' } @{ $self->{c}->stash->{around_bodies} }; - return unless @iow; - - # display all the categories on Isle of Wight at the moment as there's no way to - # do the expand bit later as we fetch it using ajax which uses a bounding box so - # can't determine the body - $where->{send_method} = [ { '!=' => 'Triage' }, undef ]; - return $where; + + if ( $user && ( $user->is_superuser || $user->belongs_to_body( $body->id ) ) ) { + @$categories = grep { !$_->send_method || $_->send_method ne 'Triage' } @$categories; + return; + } + + @$categories = grep { $_->send_method && $_->send_method eq 'Triage' } @$categories; } 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; + if ( my $body = $bodies{'Isle of Wight Council'} ) { + return $self->_iow_category_munge($body, $categories); } } @@ -118,16 +119,9 @@ sub munge_report_new_contacts { my %bodies = map { $_->body->name => $_->body } @$contacts; - if ( $bodies{'Isle of Wight Council'} ) { - my $user = $self->{c}->user; - if ( $user && ( $user->is_superuser || $user->belongs_to_body( $bodies{'Isle of Wight Council'}->id ) ) ) { - @$contacts = grep { !$_->send_method || $_->send_method ne 'Triage' } @$contacts; - return; - } - - @$contacts = grep { $_->send_method && $_->send_method eq 'Triage' } @$contacts; + if ( my $body = $bodies{'Isle of Wight Council'} ) { + return $self->_iow_category_munge($body, $contacts); } - if ( $bodies{'TfL'} ) { # Presented categories vary if we're on/off a red route my $tfl = FixMyStreet::Cobrand->get_class_for_moniker( 'tfl' )->new({ c => $self->{c} }); diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm index 84b916fc2..f6d631a78 100644 --- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm +++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm @@ -128,11 +128,10 @@ sub munge_around_category_where { my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first; if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) { $where->{send_method} = [ { '!=' => 'Triage' }, undef ]; - return $where; + return; } $where->{'send_method'} = 'Triage'; - return $where; } sub munge_load_and_group_problems { |