diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 7 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 116 | ||||
-rw-r--r-- | templates/web/default/report/display.html | 6 |
4 files changed, 129 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index b2f476fec..ee0d03b5b 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -178,6 +178,7 @@ sub format_problem_for_display : Private { if ( $c->user ) { $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'; } diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 6ad6ffaa5..234b0021c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -155,6 +155,10 @@ sub process_update : Private { my $name = Utils::trim_text( $params{ name } ); + my $anonymous = 't'; + + $anonymous = 'f' if ( $name && $c->req->param('may_show_name' ) ); + my $update = $c->model('DB::Comment')->new( { text => $params{update}, @@ -166,12 +170,13 @@ sub process_update : Private { cobrand => $c->cobrand->moniker, cobrand_data => $c->cobrand->extra_update_data, lang => $c->stash->{lang_code}, - anonymous => ( $name ? 'f': 't' ), + anonymous => $anonymous, } ); $c->stash->{update} = $update; $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 8c34541ed..ccbdfd9bf 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -277,29 +277,136 @@ subtest "submit an update for a non registered user" => sub { for my $test ( { desc => 'submit update for register user', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 0, + fixed => 0, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => '', + alert => 0, + anonymous => 0, + }, + { + desc => 'submit update for register user anonymously by unchecking', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + may_show_name => 0, + add_alert => 0, + fixed => 0, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => '', + alert => 0, + anonymous => 1, + }, + { + desc => 'submit update for register user anonymously by deleting name', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, fields => { submit_update => 1, + name => '', rznvy => 'test@example.com', update => 'update from a registered user', + may_show_name => 1, add_alert => 0, + fixed => 0, }, changed => { update => 'Update from a registered user' }, + initial_banner => '', + endstate_banner => '', alert => 0, + anonymous => 1, }, { desc => 'submit update for register user and sign up', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, fields => { submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', add_alert => 1, + fixed => 0, }, changed => { update => 'Update from a registered user' }, + initial_banner => '', + endstate_banner => '', alert => 1, + anonymous => 0, + }, + { + desc => 'submit update for register user and mark fixed', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 0, + fixed => 1, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => ' This problem has been fixed. ', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, }, ) { subtest $test->{desc} => sub { @@ -313,6 +420,12 @@ for my $test ( $mech->log_in_ok( $user->email ); $mech->get_ok("/report/$report_id"); + my $values = $mech->visible_form_values( 'updateForm' ); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; + $mech->submit_form_ok( { with_fields => $test->{fields}, @@ -322,6 +435,8 @@ for my $test ( is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner'; + $mech->email_count_is(0); my $results = { @@ -334,6 +449,7 @@ for my $test ( is $update->text, $results->{update}, 'update text'; is $update->user->email, 'test@example.com', 'update user'; is $update->state, 'confirmed', 'update confirmed'; + is $update->anonymous, $test->{anonymous}, 'user anonymous'; my $alert = FixMyStreet::App->model('DB::Alert') diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html index 6467a8a62..ece7562d0 100644 --- a/templates/web/default/report/display.html +++ b/templates/web/default/report/display.html @@ -71,6 +71,12 @@ <input type="text" name="name" id="form_name" value="[% form_name | html %]" size="20"> [% loc( '(optional)' ) %] </div> + <div class="checkbox"> + <input type="checkbox" name="may_show_name" id="form_may_show_name" value="1"[% may_show_name %]> + <label for="form_may_show_name">[% loc('Can we show your name publicly?') %]</label> + <small>[% loc('(we never show your email address or phone number)') %]</small> + </div> + [% IF field_errors.email %] <div class='form-error'>[% field_errors.email %]</div> [% END %] |