aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm29
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm10
-rw-r--r--t/app/controller/report_updates.t83
-rw-r--r--templates/web/default/report/display.html4
4 files changed, 98 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index ee0d03b5b..fd9c1f1e7 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -159,8 +159,9 @@ sub format_problem_for_display : Private {
$c->stash->{allow_photo_upload} = $c->cobrand->allow_photo_display; # FIXME?
- $c->stash->{cobrand_alert_fields} = $c->cobrand->form_elements( '/alerts' );
- $c->stash->{cobrand_update_fields} = $c->cobrand->form_elements( '/updateForm' );
+ $c->stash->{cobrand_alert_fields} = $c->cobrand->form_elements('/alerts');
+ $c->stash->{cobrand_update_fields} =
+ $c->cobrand->form_elements('/updateForm');
( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) =
map { Utils::truncate_coordinate($_) }
@@ -168,19 +169,23 @@ sub format_problem_for_display : Private {
$c->stash->{report_name} = $c->req->param('name');
- if ( $c->req->param('submit_update' ) ) {
- $c->stash->{form_name} = $c->req->param('name');
- $c->stash->{update} = $c->req->param('update');
- $c->stash->{email} = $c->req->param('rznvy');
- $c->stash->{fixed} = $c->req->param('fixed') ? ' checked' : '';
- $c->stash->{add_alert} = $c->req->param('add_alert') ? ' checked' : '';
- } else {
+ if ( $c->req->param('submit_update') ) {
+ # we may have munged these previously in /report/update
+ # so only set if they're not already in the stash
+ $c->stash->{form_name} ||= $c->req->param('name');
+ $c->stash->{update_text} ||= $c->req->param('update');
+ $c->stash->{email} ||= $c->req->param('rznvy');
+ $c->stash->{fixed} ||= $c->req->param('fixed') ? ' checked' : '';
+ $c->stash->{add_alert_checked} ||=
+ ( $c->req->param('add_alert') ? ' checked' : '' );
+ }
+ else {
if ( $c->user ) {
- $c->stash->{form_name} = $c->user->name;
- $c->stash->{email} = $c->user->email;
+ $c->stash->{form_name} = $c->user->name;
+ $c->stash->{email} = $c->user->email;
$c->stash->{may_show_name} = ' checked' if $c->user->name;
}
- $c->stash->{add_alert} = ' checked';
+ $c->stash->{add_alert_checked} = ' checked';
}
$c->forward('generate_map_tags');
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 234b0021c..3d575f6a5 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -130,6 +130,7 @@ sub process_user : Private {
unless $update_user->name;
$c->stash->{update_user} = $update_user;
+ $c->stash->{email} = $update_user->email;
return 1;
}
@@ -153,11 +154,11 @@ sub process_update : Private {
$params{update} =
Utils::cleanup_text( $params{update}, { allow_multiline => 1 } );
- my $name = Utils::trim_text( $params{ name } );
+ my $name = Utils::trim_text( $params{name} );
my $anonymous = 't';
- $anonymous = 'f' if ( $name && $c->req->param('may_show_name' ) );
+ $anonymous = 'f' if ( $name && $c->req->param('may_show_name') );
my $update = $c->model('DB::Comment')->new(
{
@@ -174,8 +175,9 @@ sub process_update : Private {
}
);
- $c->stash->{update} = $update;
- $c->stash->{add_alert} = $c->req->param('add_alert');
+ $c->stash->{update} = $update;
+ $c->stash->{update_text} = $update->text;
+ $c->stash->{add_alert} = $c->req->param('add_alert');
$c->stash->{may_show_name} = ' checked' if $c->req->param('may_show_name');
return 1;
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index ccbdfd9bf..6e93a7d74 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -192,30 +192,81 @@ subtest "several updates shown in correct order" => sub {
for my $test (
{
+ desc => 'No email, no message',
fields => {
rznvy => '',
update => '',
name => '',
+ photo => '',
+ fixed => undef,
+ add_alert => 1,
+ may_show_name => undef,
},
+ changes => {},
field_errors => [ 'Please enter your email', 'Please enter a message' ]
},
{
+ desc => 'Invalid email, no message',
fields => {
rznvy => 'test',
update => '',
name => '',
+ photo => '',
+ fixed => undef,
+ add_alert => 1,
+ may_show_name => undef,
},
+ changes => {},
field_errors => [ 'Please enter a valid email', 'Please enter a message' ]
},
+ {
+ desc => 'email with spaces, no message',
+ fields => {
+ rznvy => 'test @ example. com',
+ update => '',
+ name => '',
+ photo => '',
+ fixed => undef,
+ add_alert => 1,
+ may_show_name => undef,
+ },
+ changes => {
+ rznvy => 'test@example.com',
+ },
+ field_errors => [ 'Please enter a message' ]
+ },
+ {
+ desc => 'email with uppercase, no message',
+ fields => {
+ rznvy => 'test@EXAMPLE.COM',
+ update => '',
+ name => '',
+ photo => '',
+ fixed => undef,
+ add_alert => 1,
+ may_show_name => undef,
+ },
+ changes => {
+ rznvy => 'test@example.com',
+ },
+ field_errors => [ 'Please enter a message' ]
+ },
)
{
- subtest "submit an update" => sub {
+ subtest "submit an update - $test->{desc}" => sub {
$mech->get_ok("/report/$report_id");
$mech->submit_form_ok( { with_fields => $test->{fields} },
'submit update' );
is_deeply $mech->form_errors, $test->{field_errors}, 'field errors';
+
+ my $values = {
+ %{ $test->{fields} },
+ %{ $test->{changes} },
+ };
+
+ is_deeply $mech->visible_form_values('updateForm'), $values, 'form changes';
};
}
@@ -224,13 +275,27 @@ subtest "submit an update for a non registered user" => sub {
$mech->get_ok("/report/$report_id");
+ my $values = $mech->visible_form_values('updateForm');
+
+ is_deeply $values,
+ {
+ name => '',
+ rznvy => '',
+ may_show_name => undef,
+ add_alert => 1,
+ photo => '',
+ update => '',
+ fixed => undef,
+ },
+ 'initial form values';
+
$mech->submit_form_ok(
{
with_fields => {
submit_update => 1,
- rznvy => 'unregistered@example.com',
- update => 'update from an unregistered user',
- add_alert => 0,
+ rznvy => 'unregistered@example.com',
+ update => 'update from an unregistered user',
+ add_alert => 0,
}
},
'submit update'
@@ -242,7 +307,6 @@ subtest "submit an update for a non registered user" => sub {
ok $email, "got an email";
like $email->body, qr/confirm the update you/i, "Correct email text";
-
my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)};
ok $url, "extracted confirm url '$url'";
@@ -254,11 +318,10 @@ subtest "submit an update for a non registered user" => sub {
);
ok $token, 'Token found in database';
- my $update_id = $token->data->{id};
+ my $update_id = $token->data->{id};
my $add_alerts = $token->data->{add_alert};
- my $update = FixMyStreet::App->model( 'DB::Comment' )->find(
- { id => $update_id }
- );
+ my $update =
+ FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } );
ok $update, 'found update in database';
is $update->state, 'unconfirmed', 'update unconfirmed';
@@ -267,7 +330,7 @@ subtest "submit an update for a non registered user" => sub {
is $add_alerts, 0, 'do not sign up for alerts';
$mech->get_ok( $url . $url_token );
- $mech->content_contains( "/report/$report_id#$update_id" );
+ $mech->content_contains("/report/$report_id#$update_id");
$update->discard_changes;
diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html
index ece7562d0..c1009062b 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -90,7 +90,7 @@
[% END %]
<div class="form-field">
<label for="form_update">[% loc( 'Update:' ) %]</label>
- <textarea name="update" id="form_update" rows="7" cols="30">[% update | html %]</textarea>
+ <textarea name="update" id="form_update" rows="7" cols="30">[% update_text | html %]</textarea>
</div>
@@ -114,7 +114,7 @@
<div class="checkbox">
- <input type="checkbox" name="add_alert" id="form_add_alert" value="1"[% add_alert %]>
+ <input type="checkbox" name="add_alert" id="form_add_alert" value="1"[% add_alert_checked %]>
<label for="form_add_alert">[% loc( 'Alert me to future updates' ) %]</label>
</div>