diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-07-28 16:45:25 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-07-28 16:45:25 +0100 |
commit | aaa1947c2ec5a45cfca0b01213464afcc10e4c9a (patch) | |
tree | 83f708393670602834a377dddbb0629dfa8bd9d6 /perllib/FixMyStreet | |
parent | 77a343a8d148abc4eb8922b645b25eefe0fae8c9 (diff) | |
parent | 9d00e9bc88bde0c604a30d7f72890768b13ee7f0 (diff) |
Merge branch 'issues/968-refusing-councils'
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 42 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Static.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Refused.pm | 7 |
4 files changed, 58 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 91d6be4fb..114a2e19f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -342,7 +342,7 @@ sub update_contacts : Private { my $category = $self->trim( $c->get_param('category') ); $errors{category} = _("Please choose a category") unless $category; my $email = $self->trim( $c->get_param('email') ); - $errors{email} = _('Please enter a valid email') unless is_valid_email($email); + $errors{email} = _('Please enter a valid email') unless is_valid_email($email) || $email eq 'REFUSED'; $errors{note} = _('Please enter a message') unless $c->get_param('note'); $category = 'Empty property' if $c->cobrand->moniker eq 'emptyhomes'; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 69c94b911..b540a1961 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -219,14 +219,21 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { return 1; } $c->forward('setup_categories_and_bodies'); + $c->forward('check_for_category'); + my $category = $c->stash->{category}; my $category_extra = ''; - my $category = $c->get_param('category'); + my $generate; if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) { $c->stash->{report_meta} = {}; - $c->stash->{report} = { category => $category }; $c->stash->{category_extras} = { $category => $c->stash->{category_extras}->{$category} }; - + $generate = 1; + } + if ($c->stash->{unresponsive}->{$category}) { + $generate = 1; + } + if ($generate) { + $c->stash->{report} = { category => $category }; $category_extra = $c->render_fragment( 'report/new/category_extras.html'); } @@ -604,6 +611,11 @@ sub setup_categories_and_bodies : Private { my %category_extras = (); # extra fields to fill in for open311 my %non_public_categories = (); # categories for which the reports are not public + $c->stash->{unresponsive} = {}; + + if (keys %bodies == 1 && $first_body->send_method && $first_body->send_method eq 'Refused') { + $c->stash->{unresponsive}{ALL} = $first_body->id; + } # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { @@ -641,6 +653,9 @@ sub setup_categories_and_bodies : Private { $category_extras{ $contact->category } = $metas if scalar @$metas; + $c->stash->{unresponsive}{$contact->category} = $contact->body_id + if $contact->email =~ /^REFUSED$/i; + $non_public_categories{ $contact->category } = 1 if $contact->non_public; } $seen{$contact->category} = 1; @@ -863,14 +878,19 @@ sub process_report : Private { return 1; } - # construct the bodies string: - # 'x,x' - x are body IDs that have this category - # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact - my $body_string = join( ',', map { $_->body_id } @contacts ); - $body_string .= - '|' . join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } ) - if $body_string && @{ $c->stash->{missing_details_bodies} }; - $report->bodies_str($body_string); + if ($c->stash->{unresponsive}{$report->category} || $c->stash->{unresponsive}{ALL}) { + # Unresponsive, don't try and send a report. + $report->bodies_str(-1); + } else { + # construct the bodies string: + # 'x,x' - x are body IDs that have this category + # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact + my $body_string = join( ',', map { $_->body_id } @contacts ); + $body_string .= + '|' . join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } ) + if $body_string && @{ $c->stash->{missing_details_bodies} }; + $report->bodies_str($body_string); + } my @extra; # NB: we are only checking extras for the *first* retrieved contact. diff --git a/perllib/FixMyStreet/App/Controller/Static.pm b/perllib/FixMyStreet/App/Controller/Static.pm index 8cd82b68e..d91a07fea 100755 --- a/perllib/FixMyStreet/App/Controller/Static.pm +++ b/perllib/FixMyStreet/App/Controller/Static.pm @@ -61,6 +61,25 @@ sub council : Global : Args(0) { my ( $self, $c ) = @_; } +sub unresponsive : Global : Args(0) { + my ( $self, $c ) = @_; + my $body = $c->stash->{body} = $c->model('DB::Body')->find({ id => $c->get_param('body') }) + or $c->detach( '/page_error_404_not_found' ); + + $c->stash->{category} = $c->get_param('category'); + + # If the whole body isn't set to refused, we need to check the contacts + if (!$body->send_method || $body->send_method ne 'Refused') { + my @contacts = $c->model('DB::Contact')->not_deleted->search( { body_id => $body->id } )->all; + my $any_unresponsive = 0; + foreach my $contact (@contacts) { + $any_unresponsive = 1 if $contact->email =~ /^REFUSED$/i; + } + + $c->detach( '/page_error_404_not_found' ) unless $any_unresponsive; + } +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/SendReport/Refused.pm b/perllib/FixMyStreet/SendReport/Refused.pm new file mode 100644 index 000000000..d71fc5c2c --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Refused.pm @@ -0,0 +1,7 @@ +package FixMyStreet::SendReport::Refused; + +use Moose; + +BEGIN { extends 'FixMyStreet::SendReport::Noop'; } + +1; |