aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Report/Update.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-19 17:11:37 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-19 17:11:37 +0100
commit2c3160b0fb07d9412925a3d57f4017c998de835e (patch)
tree8071a5be05d5ccb3c20c1bce4649400cf6b92b95 /perllib/FixMyStreet/App/Controller/Report/Update.pm
parent1463288a3282ec5d0f195e2ed44253b78f5b915b (diff)
sign up logged in users for alerts as appropriate
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm29
1 files changed, 29 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index d9136698d..e1e90bb93 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -228,6 +228,8 @@ sub save_update : Private {
} else {
$update->insert;
}
+
+ return 1;
}
=head2 redirect_or_confirm_creation
@@ -243,6 +245,7 @@ sub redirect_or_confirm_creation : Private {
# If confirmed send the user straight there.
if ( $update->confirmed ) {
+ $c->forward( 'signup_for_alerts' );
my $report_uri = $c->uri_for( '/report', $update->problem_id );
$c->res->redirect($report_uri);
$c->detach;
@@ -268,6 +271,32 @@ sub redirect_or_confirm_creation : Private {
return 1;
}
+=head2 signup_for_alerts
+
+If the user has selected to be signed up for alerts then create a
+new_updates alert.
+
+NB: this does not check if they are a registered user so that should
+happen before calling this.
+
+=cut
+
+sub signup_for_alerts : Private {
+ my ( $self, $c ) = @_;
+
+ if ( $c->req->param( 'add_alert' ) ) {
+ my $alert = $c->model( 'DB::Alert' )->find_or_create(
+ user => $c->stash->{update_user},
+ alert_type => 'new_updates',
+ parameter => $c->stash->{problem}->id
+ );
+
+ $alert->update;
+ }
+
+ return 1;
+}
+
__PACKAGE__->meta->make_immutable;
1;