diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 51 | ||||
-rw-r--r-- | templates/web/default/alert/list.html | 2 |
4 files changed, 52 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index db9602ff5..b8b7cce40 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -58,9 +58,14 @@ sub subscribe : Path('subscribe') : Args(0) { if ( $c->req->param('rss') ) { $c->detach('rss'); } - elsif ( $c->req->param('rznvy') ) { + # if it exists then it's been submitted so we should + # go to subscribe email and let it work out the next step + elsif ( exists $c->req->params->{'rznvy'} ) { $c->detach('subscribe_email'); } + + # shouldn't get to here but if we have then do something sensible + $c->go('index'); } =head2 rss @@ -194,7 +199,10 @@ sub create_alert : Private { unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); - $options->{confirmed} = 1 if $c->stash->{alert_user}->in_storage; + + if ( $c->user && $c->user->id == $c->stash->{alert_user}->id ) { + $options->{confirmed} = 1; + } $alert = $c->model('DB::Alert')->new($options); $alert->insert(); @@ -221,7 +229,6 @@ sub set_update_alert_options : Private { }; $c->stash->{alert_options} = $options; - $c->forward('create_alert'); } =head2 set_local_alert_options @@ -255,7 +262,6 @@ sub set_local_alert_options : Private { push @params, $1, $2; } - my $options = { user => $c->stash->{alert_user}, alert_type => $type diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index be0f8dc16..e8bb0f70d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,6 +20,10 @@ 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('setup_page') && $c->forward('process_user') && $c->forward('process_update') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 3d06594de..91e86bd46 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -153,7 +153,9 @@ foreach my $test ( } ) { - subtest "use existing user in a alert" => sub { + subtest "use existing unlogged in user in a alert" => sub { + $mech->log_out_ok(); + my $type = $test->{type} . '_problems'; my $user = @@ -170,7 +172,7 @@ foreach my $test ( ); # clear existing data so we can be sure we're creating it - $alert->delete() if $alert; + ok $alert->delete() if $alert; } $mech->get_ok( $test->{uri} ); @@ -181,41 +183,61 @@ foreach my $test ( alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 1, + confirmed => 0, } ); + $mech->content_contains( 'Now check your email' ); + ok $alert, 'New alert created with existing user'; }; } foreach my $test ( { + desc => 'logged in user signing up', + user => 'test-login@example.com', + email => 'test-login@example.com', + type => 'council', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + param1 => 2651, + param2 => 2651, + confirmed => 1, + }, + { + desc => 'logged in user signing up with different email', + user => 'loggedin@example.com', email => 'test-login@example.com', type => 'council', content => 'your alert will not be activated', email_text => 'confirm the alert', param1 => 2651, param2 => 2651, + confirmed => 0, } ) { - subtest "use logged in user in an alert" => sub { + subtest $test->{desc} => sub { my $type = $test->{type} . '_problems'; my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => $test->{email} } ); + ->find_or_create( { email => $test->{user} } ); + + my $alert_user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); - $mech->log_in_ok( $test->{email} ); + $mech->log_in_ok( $test->{user} ); $mech->clear_emails_ok; my $alert; - if ($user) { + if ($alert_user) { $alert = FixMyStreet::App->model('DB::Alert')->find( { - user => $user, + user => $alert_user, alert_type => $type } ); @@ -227,25 +249,26 @@ foreach my $test ( $mech->get_ok('/alert/list?pc=EH991SP'); my $form_values = $mech->visible_form_values(); - ok $form_values->{rznvy} eq $test->{email}, + ok $form_values->{rznvy} eq $test->{user}, 'auto filled in correct email'; - $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ] ); + $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ], + [ text => $test->{email} ] ); $mech->click('alert'); $alert = FixMyStreet::App->model('DB::Alert')->find( { - user => $user, + user => $alert_user, alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 1, + confirmed => $test->{confirmed}, } ); - ok $alert, 'New alert created with existing user'; + ok $alert, 'New alert created with logged in user'; - $mech->email_count_is(0); + $mech->email_count_is( $test->{confirmed} ? 0 : 1 ); }; } diff --git a/templates/web/default/alert/list.html b/templates/web/default/alert/list.html index 3eb28788a..5b1677e8b 100644 --- a/templates/web/default/alert/list.html +++ b/templates/web/default/alert/list.html @@ -36,7 +36,7 @@ </p> <p id="rss_local"> - <input type="radio" name="feed" id="[% rss_feed_id %]" value="[% rss_feed_id %]"[% IF rss_feed_id == selected_feed %] checked[% END %]> + <input type="radio" name="feed" id="[% rss_feed_id %]" value="[% rss_feed_id %]"[% IF rss_feed_id == selected_feed || selected_feed == '' %] checked[% END %]> <label for="[% rss_feed_id %]">[% tprintf( loc('Problems within %.1fkm of this location'), population_radius ) %]</label> ([% loc('a default distance which covers roughly 200,000 people') %]) <a href='[% rss_feed_uri %]'> <img src='/i/feed.png' width='16' height='16' title='[% loc('RSS feed of nearby problems') %]' alt='[% loc('RSS feed') %]' border='0'></a> |