diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 13 |
5 files changed, 36 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index bea5345e3..b3067abc9 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -63,6 +63,9 @@ sub subscribe : Path('subscribe') : Args(0) { elsif ( exists $c->req->params->{'rznvy'} ) { $c->detach('subscribe_email'); } + elsif ( $c->req->params->{'id'} ) { + $c->go('updates'); + } # shouldn't get to here but if we have then do something sensible $c->go('index'); @@ -140,7 +143,7 @@ sub subscribe_email : Private { $c->forward('set_local_alert_options'); } else { - throw FixMyStreet::Alert::Error('Invalid type'); + $c->detach( '/page_error_404_not_found', [ 'Invalid type' ] ); } $c->forward('create_alert'); @@ -162,7 +165,7 @@ sub updates : Path('updates') : Args(0) { =head2 confirm -Confirm signup to an alert. Forwarded here from Tokens. +Confirm signup to or unsubscription from an alert. Forwarded here from Tokens. =cut @@ -173,11 +176,9 @@ sub confirm : Private { if ( $c->stash->{confirm_type} eq 'subscribe' ) { $alert->confirm(); - $alert->update; } elsif ( $c->stash->{confirm_type} eq 'unsubscribe' ) { - $alert->delete(); - $alert->update; + $alert->disable(); } } @@ -198,8 +199,9 @@ sub create_alert : Private { unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); + $options->{lang} = $c->stash->{lang_code}; - if ( $c->user && $c->user->id == $c->stash->{alert_user}->id ) { + if ( $c->user && $c->stash->{alert_user}->in_storage && $c->user->id == $c->stash->{alert_user}->id ) { $options->{confirmed} = 1; } @@ -258,7 +260,7 @@ sub set_local_alert_options : Private { m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) { $type = 'local_problems'; - push @params, $1, $2; + push @params, $2, $1; # Note alert parameters are lon,lat } my $options = { diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 671454272..9e0193d3f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -931,8 +931,10 @@ sub redirect_or_confirm_creation : Private { my ( $self, $c ) = @_; my $report = $c->stash->{report}; - # If confirmed send the user straigh there. + # If confirmed send the user straight there. if ( $report->confirmed ) { + # Subscribe problem reporter to email updates + $c->forward( 'create_reporter_alert' ); my $report_uri = $c->uri_for( '/report', $report->id ); $c->res->redirect($report_uri); $c->detach; @@ -950,6 +952,20 @@ sub redirect_or_confirm_creation : Private { $c->stash->{email_type} = 'problem'; } +sub create_reporter_alert : Private { + my ( $self, $c ) = @_; + + my $problem = $c->stash->{report}; + my $alert = $c->model('DB::Alert')->find_or_create( { + user => $problem->user, + alert_type => 'new_updates', + parameter => $problem->id, + cobrand => $problem->cobrand, + cobrand_data => $problem->cobrand_data, + lang => $problem->lang, + } )->confirm; +} + =head2 redirect_to_around Redirect the user to '/around' passing along all the relevant parameters. diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index eadf2beea..a1120470b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -315,12 +315,15 @@ sub signup_for_alerts : Private { my ( $self, $c ) = @_; if ( $c->stash->{add_alert} ) { + my $update = $c->stash->{update}; my $alert = $c->model('DB::Alert')->find_or_create( - user => $c->stash->{update}->user, - alert_type => 'new_updates', - parameter => $c->stash->{update}->problem_id, - confirmed => 1, - ); + user => $update->user, + alert_type => 'new_updates', + parameter => $update->problem_id, + cobrand => $update->cobrand, + cobrand_data => $update->cobrand_data, + lang => $update->lang, + )->confirm(); $alert->update; } diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 92dbced15..993cd752e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -4,7 +4,6 @@ use namespace::autoclean; use Problems; use POSIX qw(strcoll); -# use FixMyStreet::Alert; use mySociety::MaPit; use mySociety::VotingArea; diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 792c875fd..92a44e756 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -4,8 +4,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -use FixMyStreet::Alert; - =head1 NAME FixMyStreet::App::Controller::Tokens - Handle auth tokens @@ -57,15 +55,8 @@ sub confirm_problem : Path('/P') { ) if $problem->state eq 'unconfirmed'; # Subscribe problem reporter to email updates - my $alert = $c->model('DB::Alert')->find_or_create( - { - user => $problem->user, - alert_type => 'new_updates', - cobrand => $problem->cobrand, - cobrand_data => $problem->cobrand_data, - parameter => $problem->id - } - )->confirm; + $c->stash->{report} = $c->stash->{problem}; + $c->forward( '/report/new/create_reporter_alert' ); # log the problem creation user in to the site $c->authenticate( { email => $problem->user->email }, 'no_password' ); |