aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-06-09 11:22:54 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-06-09 11:22:54 +0100
commit5d60e828ccd46a805e9463d14f388188efef9f4e (patch)
tree7d2a7b88a8cb7b0dc963a133f3d3230d8878ff94
parent2f905f6b8f74a5a892b3974e4f0b4076f9b58ddf (diff)
Centralise problem report loading, 404/410 checking.
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm15
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm21
3 files changed, 10 insertions, 34 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index bd7d415e7..047de7691 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -63,16 +63,8 @@ sub determine_contact_type : Private {
$update_id = undef unless $update_id && $update_id =~ /^[1-9]\d*$/;
if ($id) {
- my $problem = $c->cobrand->problems->find(
- { id => $id },
- {
- 'select' => [
- 'title', 'detail', 'name',
- 'anonymous', 'id',
- 'user_id', 'confirmed',
- ]
- }
- );
+
+ $c->forward( '/report/load_problem_or_display_error', [ $id ] );
if ($update_id) {
my $update = $c->model('DB::Comment')->find(
@@ -81,9 +73,6 @@ sub determine_contact_type : Private {
$c->stash->{update} = $update;
}
- elsif ($problem) {
- $c->stash->{problem} = $problem;
- }
}
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 0fe1834e7..497ec784a 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -52,6 +52,7 @@ sub display : Path('') : Args(1) {
}
$c->forward('load_problem_or_display_error', [ $id ] );
+ $c->forward( 'load_updates' );
$c->forward( 'format_problem_for_display' );
}
@@ -76,9 +77,14 @@ sub load_problem_or_display_error : Private {
}
$c->stash->{problem} = $problem;
+ return 1;
+}
+
+sub load_updates : Private {
+ my ( $self, $c ) = @_;
my $updates = $c->model('DB::Comment')->search(
- { problem_id => $problem->id, state => 'confirmed' },
+ { problem_id => $c->stash->{problem}->id, state => 'confirmed' },
{ order_by => 'confirmed' }
);
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 2ca9245ad..2f1d88d08 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -24,7 +24,7 @@ sub report_update : Path : Args(0) {
$c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] )
unless $c->req->param('id');
- $c->forward('setup_page')
+ $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] )
&& $c->forward('process_user')
&& $c->forward('process_update')
&& $c->forward('/report/new/process_photo')
@@ -89,25 +89,6 @@ sub display_confirmation : Private {
return 1;
}
-=head2 setup_page
-
-Setup things we need for later.
-
-=cut
-
-sub setup_page : Private {
- my ( $self, $c ) = @_;
-
- my $problem =
- $c->cobrand->problems->find( { id => $c->req->param('id') } );
-
- return unless $problem;
-
- $c->stash->{problem} = $problem;
-
- return 1;
-}
-
=head2 process_user
Load user from the database or prepare a new one.