aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-05-19 18:55:44 +0100
committerEdmund von der Burg <evdb@mysociety.org>2011-05-19 18:55:44 +0100
commitb49dac25fb9ec11c09972e3a0b49690ccac3bc68 (patch)
tree80fac638e99a4e183025030941cdbc6e2fc8faff
parent2918a2b1cb6f3fd09b7e5dbd738e762e554521bf (diff)
parentf0e1ae8ad567b5360577f0e18237fa00056e4073 (diff)
Merge branch 'migrate_to_catalyst' of ssh://evdb@git.mysociety.org/data/git/public/fixmystreet into migrate_to_catalyst
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm65
-rw-r--r--t/app/controller/report_updates.t77
-rw-r--r--templates/web/default/report/display.html5
3 files changed, 108 insertions, 39 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 691a4ecc9..105bf9993 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -140,16 +140,17 @@ sub process_update : Private {
my %params = #
map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' );
- use Data::Dumper;
- $c->log->debug( 'params: ' . Dumper( %params ) );
my $update = $c->model('DB::Comment')->new(
{
- text => $params{update},
- name => _trim_text( $params{name} ),
- problem => $c->stash->{problem},
- user => $c->stash->{update_user},
- state => 'unconfirmed',
- mark_fixed => $params{fixed} ? 't' : 'f',
+ text => $params{update},
+ name => _trim_text( $params{name} ),
+ problem => $c->stash->{problem},
+ user => $c->stash->{update_user},
+ state => 'unconfirmed',
+ mark_fixed => $params{fixed} ? 't' : 'f',
+ cobrand => $c->cobrand->moniker,
+ cobrand_data => $c->cobrand->extra_update_data,
+ lang => $c->stash->{lang_code},
}
);
@@ -189,7 +190,10 @@ sub check_for_errors : Private {
delete $field_errors{name};
# all good if no errors
- return 1 unless scalar keys %field_errors;
+ return 1
+ unless ( scalar keys %field_errors
+ || ( $c->stash->{errors} && scalar @{ $c->stash->{errors} } )
+ || $c->stash->{photo_error} );
$c->stash->{field_errors} = \%field_errors;
@@ -228,6 +232,8 @@ sub save_update : Private {
} else {
$update->insert;
}
+
+ return 1;
}
=head2 redirect_or_confirm_creation
@@ -243,21 +249,56 @@ 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;
}
# otherwise create a confirm token and email it to them.
- my $token =
- $c->model("DB::Token")
- ->create( { scope => 'comment', data => $update->id } );
+ my $token = $c->model("DB::Token")->create(
+ {
+ scope => 'comment',
+ data => {
+ id => $update->id,
+ add_alert => ( $c->req->param('add_alert') ? 1 : 0 ),
+ }
+ }
+ );
$c->stash->{token_url} = $c->uri_for_email( '/C', $token->token );
$c->send_email( 'update-confirm.txt', { to => $update->user->email } );
# tell user that they've been sent an email
$c->stash->{template} = 'email_sent.html';
$c->stash->{email_type} = 'update';
+
+ 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;
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index e64e2f4d6..182f3a244 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -249,7 +249,8 @@ subtest "submit an update for a non registered user" => sub {
);
ok $token, 'Token found in database';
- my $update_id = $token->data;
+ my $update_id = $token->data->{id};
+ my $add_alerts = $token->data->{add_alert};
my $update = FixMyStreet::App->model( 'DB::Comment' )->find(
{ id => $update_id }
);
@@ -258,39 +259,63 @@ subtest "submit an update for a non registered user" => sub {
is $update->state, 'unconfirmed', 'update unconfirmed';
is $update->user->email, 'unregistered@example.com', 'update email';
is $update->text, 'update from an unregistered user', 'update text';
+ is $add_alerts, 0, 'do not sign up for alerts';
};
-subtest "submit an update for a registered user" => sub {
- # clear out comments for this problem to make
- # checking details easier later
- ok( $_->delete, 'deleted comment ' . $_->id )
- for $report->comments;
+for my $test (
+ {
+ desc => 'submit update for register user',
+ fields => {
+ rznvy => 'test@example.com',
+ update => 'update from a registered user'
+ },
+ alert => 0,
+ },
+ {
+ desc => 'submit update for register user and sign up',
+ fields => {
+ rznvy => 'test@example.com',
+ update => 'update from a registered user',
+ add_alert => 1,
+ },
+ alert => 1,
+ },
+) {
+ subtest $test->{desc} => sub {
+ # clear out comments for this problem to make
+ # checking details easier later
+ ok( $_->delete, 'deleted comment ' . $_->id )
+ for $report->comments;
- $mech->clear_emails_ok();
+ $mech->clear_emails_ok();
- $mech->log_in_ok( $user->email );
- $mech->get_ok("/report/$report_id");
+ $mech->log_in_ok( $user->email );
+ $mech->get_ok("/report/$report_id");
- $mech->submit_form_ok(
- {
- with_fields => {
- rznvy => 'test@example.com',
- update => 'update from a registered user'
- }
- },
- 'submit update'
- );
+ $mech->submit_form_ok(
+ {
+ with_fields => $test->{fields},
+ },
+ 'submit update'
+ );
- is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
+ is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
- $mech->email_count_is(0);
+ $mech->email_count_is(0);
- my $update = $report->comments->first;
- ok $update, 'found update';
- is $update->text, 'update from a registered user', 'update text';
- is $update->user->email, 'test@example.com', 'update user';
- is $update->state, 'confirmed', 'update confirmed';
-};
+ my $update = $report->comments->first;
+ ok $update, 'found update';
+ is $update->text, $test->{fields}->{update}, 'update text';
+ is $update->user->email, 'test@example.com', 'update user';
+ is $update->state, 'confirmed', 'update confirmed';
+
+ my $alert =
+ FixMyStreet::App->model('DB::Alert')
+ ->find( { user => $user, alert_type => 'new_updates' } );
+
+ ok $test->{alert} ? $alert : !$alert, 'not signed up for alerts';
+ };
+}
ok $comment->delete, 'deleted comment';
$mech->delete_user('commenter@example.com');
diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html
index 48b799978..c1981c093 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -104,6 +104,9 @@
[% IF allow_photo_upload %]
+ [% IF photo_error %]
+ <div class='form-error'>[% photo_error %]</div>
+ [% END %]
<div id="fileupload_normalUI">
<label for="form_photo">[% loc('Photo:') %]</label>
<input type="file" name="photo" id="form_photo">
@@ -118,7 +121,7 @@
<div class="checkbox">
- <input type="submit" id="update_post" value="[% loc('Post:') %]">
+ <input type="submit" id="update_post" value="[% loc('Post') %]">
</div>