aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-12-16 12:52:16 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-12-16 12:52:16 +0000
commit12bbcc4bfa64cfb9677b9317929916d24dd472fb (patch)
tree20085c955101175da958ca6b3a481f68b87fc09d /perllib/FixMyStreet/App/Controller
parent38490f6ea18064c232bda6ebfbaee052bd8f0951 (diff)
parentadf07727ab14468c262759a21dedc1ac84cd32c8 (diff)
Merge branch 'issues/forcouncils/20-offline-inspecting'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm13
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Offline.pm32
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm9
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Root.pm20
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm1
8 files changed, 71 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 40cd163cf..c448f8749 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -271,9 +271,8 @@ sub facebook_callback: Path('/auth/Facebook') : Args(0) {
$access_token = $fb->get_access_token(code => $c->get_param('code'));
};
if ($@) {
- ($c->stash->{message} = $@) =~ s/at [^ ]*Auth.pm.*//;
- $c->stash->{template} = 'errors/generic.html';
- $c->detach;
+ (my $message = $@) =~ s/at [^ ]*Auth.pm.*//;
+ $c->detach('/page_error_500_internal_error', [ $message ]);
}
# save this token in session
@@ -339,9 +338,8 @@ sub twitter_callback: Path('/auth/Twitter') : Args(0) {
$twitter->request_access_token(verifier => $verifier);
};
if ($@) {
- ($c->stash->{message} = $@) =~ s/at [^ ]*Auth.pm.*//;
- $c->stash->{template} = 'errors/generic.html';
- $c->detach;
+ (my $message = $@) =~ s/at [^ ]*Auth.pm.*//;
+ $c->detach('/page_error_500_internal_error', [ $message ]);
}
my $info = $twitter->verify_credentials();
@@ -527,8 +525,7 @@ sub check_csrf_token : Private {
sub no_csrf_token : Private {
my ($self, $c) = @_;
- $c->stash->{message} = _('Unknown error');
- $c->stash->{template} = 'errors/generic.html';
+ $c->detach('/page_error_400_bad_request', []);
}
=head2 sign_out
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index 9189b28e5..fbe5a2dc9 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -57,9 +57,9 @@ sub example : Local : Args(0) {
}
};
if ($@) {
- $c->stash->{message} = _("There was a problem showing this page. Please try again later.") . ' ' .
+ my $message = _("There was a problem showing this page. Please try again later.") . ' ' .
sprintf(_('The error was: %s'), $@);
- $c->stash->{template} = 'errors/generic.html';
+ $c->detach('/page_error_500_internal_error', [ $message ]);
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Offline.pm b/perllib/FixMyStreet/App/Controller/Offline.pm
new file mode 100644
index 000000000..9acb33f7e
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Offline.pm
@@ -0,0 +1,32 @@
+package FixMyStreet::App::Controller::Offline;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Offline - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Offline pages Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+sub manifest : Path("/offline/appcache.manifest") {
+ my ($self, $c) = @_;
+ $c->res->content_type('text/cache-manifest; charset=utf-8');
+ $c->res->header(Cache_Control => 'no-cache, no-store');
+}
+
+sub appcache : Path("/offline/appcache") {
+ my ($self, $c) = @_;
+ $c->detach('/page_error_404_not_found', []) if keys %{$c->req->params};
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index 017a552db..1b338732b 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -36,9 +36,8 @@ sub check_questionnaire : Private {
if ( $questionnaire->whenanswered ) {
my $problem_url = $c->cobrand->base_url_for_report( $problem ) . $problem->url;
my $contact_url = $c->uri_for( "/contact" );
- $c->stash->{message} = sprintf(_("You have already answered this questionnaire. If you have a question, please <a href='%s'>get in touch</a>, or <a href='%s'>view your problem</a>.\n"), $contact_url, $problem_url);
- $c->stash->{template} = 'errors/generic.html';
- $c->detach;
+ my $message = sprintf(_("You have already answered this questionnaire. If you have a question, please <a href='%s'>get in touch</a>, or <a href='%s'>view your problem</a>.\n"), $contact_url, $problem_url);
+ $c->detach('/page_error_400_bad_request', [ $message ]);
}
unless ( $problem->is_visible ) {
@@ -86,8 +85,8 @@ Display couldn't locate problem error message
sub missing_problem : Private {
my ( $self, $c ) = @_;
- $c->stash->{message} = _("I'm afraid we couldn't locate your problem in the database.\n");
- $c->stash->{template} = 'errors/generic.html';
+ my $message = _("I'm afraid we couldn't locate your problem in the database.\n");
+ $c->detach('/page_error_400_bad_request', [ $message ]);
}
sub submit_creator_fixed : Private {
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 5a1cfbe54..3c251a5cb 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -408,10 +408,14 @@ sub inspect : Private {
$problem->lastupdate( \'current_timestamp' );
$problem->update;
if ( defined($update_text) ) {
+ my $timestamp = \'current_timestamp';
+ if (my $saved_at = $c->get_param('saved_at')) {
+ $timestamp = DateTime->from_epoch( epoch => $saved_at );
+ }
$problem->add_to_comments( {
text => $update_text,
- created => \'current_timestamp',
- confirmed => \'current_timestamp',
+ created => $timestamp,
+ confirmed => $timestamp,
user_id => $c->user->id,
name => $c->user->from_body->name,
state => 'confirmed',
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 813c2052d..f2c43b5ee 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -76,13 +76,12 @@ sub index : Path : Args(0) {
$c->stash->{open} = $j->{open};
};
if ($@) {
- $c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later.");
+ my $message = _("There was a problem showing the All Reports page. Please try again later.");
if ($c->config->{STAGING_SITE}) {
- $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports</p><p>'
+ $message .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports</p><p>'
. sprintf(_('The error was: %s'), $@);
}
- $c->stash->{template} = 'errors/generic.html';
- return;
+ $c->detach('/page_error_500_internal_error', [ $message ]);
}
# Down here so that error pages aren't cached.
diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm
index 3d4c6a1ba..20a871b17 100644
--- a/perllib/FixMyStreet/App/Controller/Root.pm
+++ b/perllib/FixMyStreet/App/Controller/Root.pm
@@ -103,9 +103,25 @@ sub page_error_410_gone : Private {
sub page_error_403_access_denied : Private {
my ( $self, $c, $error_msg ) = @_;
+ $c->detach('page_error', [ $error_msg || _("Sorry, you don't have permission to do that."), 403 ]);
+}
+
+sub page_error_400_bad_request : Private {
+ my ( $self, $c, $error_msg ) = @_;
+ $c->forward('/auth/get_csrf_token');
+ $c->detach('page_error', [ $error_msg, 400 ]);
+}
+
+sub page_error_500_internal_error : Private {
+ my ( $self, $c, $error_msg ) = @_;
+ $c->detach('page_error', [ $error_msg, 500 ]);
+}
+
+sub page_error : Private {
+ my ($self, $c, $error_msg, $code) = @_;
$c->stash->{template} = 'errors/generic.html';
- $c->stash->{message} = $error_msg || _("Sorry, you don't have permission to do that.");
- $c->response->status(403);
+ $c->stash->{message} = $error_msg || _('Unknown error');
+ $c->response->status($code);
}
=head2 end
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index da017c57f..a1b0c57ba 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -348,6 +348,7 @@ sub token_too_old : Private {
my ( $self, $c ) = @_;
$c->stash->{token_not_found} = 1;
$c->stash->{template} = 'auth/token.html';
+ $c->response->status(400);
}
__PACKAGE__->meta->make_immutable;