diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 16 |
3 files changed, 24 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index f732b94f1..6c14f33fb 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -60,9 +60,9 @@ sub load_problem_or_display_error : Private { my ( $self, $c, $id ) = @_; # try to load a report if the id is a number - my $problem # - = $id =~ m{\D} # is id non-numeric? - ? undef # ...don't even search + my $problem + = ( !$id || $id =~ m{\D} ) # is id non-numeric? + ? undef # ...don't even search : $c->cobrand->problems->find( { id => $id } ); # check that the problem is suitable to show. diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2f1d88d08..4e0d6d6c5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,10 +20,6 @@ Creates an update to a report sub report_update : Path : Args(0) { my ( $self, $c ) = @_; - # if there's no id then we should just stop now - $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ) - unless $c->req->param('id'); - $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ) && $c->forward('process_user') && $c->forward('process_update') @@ -182,7 +178,7 @@ sub check_for_errors : Private { # let the model check for errors my %field_errors = ( - %{ $c->stash->{update_user}->check_for_errors }, + %{ $c->stash->{update}->user->check_for_errors }, %{ $c->stash->{update}->check_for_errors }, ); @@ -213,14 +209,13 @@ Save the update and the user as appropriate. sub save_update : Private { my ( $self, $c ) = @_; - my $user = $c->stash->{update_user}; my $update = $c->stash->{update}; - if ( !$user->in_storage ) { - $user->insert; + if ( !$update->user->in_storage ) { + $update->user->insert; } - elsif ( $c->user && $c->user->id == $user->id ) { - $user->update; + elsif ( $c->user && $c->user->id == $update->user->id ) { + $update->user->update; $update->confirm; } diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 30314ffa3..5e18596c2 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -115,4 +115,20 @@ sub answered_ever_reported { return $has_answered->count > 0; } +=head2 alert_for_problem + +Returns whether the user is already subscribed to an +alert for the problem ID provided. + +=cut + +sub alert_for_problem { + my ( $self, $id ) = @_; + + return $self->alerts->find( { + alert_type => 'new_updates', + parameter => $id, + } ); +} + 1; |