aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-05-08 12:24:35 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-07-28 16:18:15 +0100
commit9d00e9bc88bde0c604a30d7f72890768b13ee7f0 (patch)
treedfbbb4496c2b4fe3d00ccd1e76e40d9b93108ad1 /perllib/FixMyStreet
parenta6390b55a0f05ef348b831ad76ce07834ac26e7e (diff)
[fixmystreet.com] Unresponsive bodies page/warning
Add a special category email address used to show an unresponsive message and page when trying to report in that category. Add a "Refused" send method for setting a whole body to be unresponsive and show the message immediately, not on category selection. Factor out category template, and put at top where needed.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm42
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Static.pm19
-rw-r--r--perllib/FixMyStreet/SendReport/Refused.pm7
4 files changed, 58 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 76ee3447f..abb858c32 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -345,7 +345,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;