diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 6 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 12 | ||||
-rw-r--r-- | templates/web/base/report/update/form_name.html | 6 |
3 files changed, 22 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 59171f97b..068f393f2 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -128,7 +128,7 @@ sub process_user : Private { $update->user( $user ); # Just in case, make sure the user will have a name - if ($c->stash->{contributing_as_body}) { + if ($c->stash->{contributing_as_body} or $c->stash->{contributing_as_anonymous_user}) { $user->name($user->from_body->name) unless $user->name; } @@ -277,9 +277,13 @@ sub process_update : Private { $update->mark_open($params{reopen} ? 1 : 0); $c->stash->{contributing_as_body} = $c->user_exists && $c->user->contributing_as('body', $c, $update->problem->bodies_str_ids); + $c->stash->{contributing_as_anonymous_user} = $c->user_exists && $c->user->contributing_as('anonymous_user', $c, $update->problem->bodies_str_ids); if ($c->stash->{contributing_as_body}) { $update->name($c->user->from_body->name); $update->anonymous(0); + } elsif ($c->stash->{contributing_as_anonymous_user}) { + $update->name($c->user->from_body->name); + $update->anonymous(1); } else { $update->name($name); $update->anonymous($c->get_param('may_show_name') ? 0 : 1); diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index 326b3c906..daa213e8c 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -133,6 +133,18 @@ subtest "Body user, has permission to add update as another (existing) user" => like $mech->get_text_body_from_email, qr/Your update has been logged/; }; +subtest "Body user, has permission to add update as anonymous user" => sub { + my $update = add_update( + 'contribute_as_anonymous_user', + form_as => 'anonymous_user', + update => 'Test Update', + ); + is $update->name, 'Oxfordshire County Council', 'update name is body'; + is $update->user->name, 'Body User', 'user name unchanged'; + is $update->user->id, $user->id, 'user matches'; + is $update->anonymous, 1, 'update anonymous'; +}; + done_testing(); sub start_report { diff --git a/templates/web/base/report/update/form_name.html b/templates/web/base/report/update/form_name.html index 926e16878..e4f7ac60c 100644 --- a/templates/web/base/report/update/form_name.html +++ b/templates/web/base/report/update/form_name.html @@ -3,15 +3,19 @@ [% PROCESS 'user/_anonymity.html' anonymous = update.anonymous %] [% can_contribute_as_another_user = c.user.has_permission_to("contribute_as_another_user", problem.bodies_str_ids) %] + [% can_contribute_as_anonymous_user = c.user.has_permission_to("contribute_as_anonymous_user", problem.bodies_str_ids) %] [% can_contribute_as_body = c.user.from_body AND c.user.has_permission_to("contribute_as_body", problem.bodies_str_ids) %] - [% IF can_contribute_as_another_user OR can_contribute_as_body %] + [% IF can_contribute_as_another_user OR can_contribute_as_body OR can_contribute_as_anonymous_user %] <label for="form_as">[% loc('Provide update as') %]</label> <select id="form_as" class="form-control js-contribute-as" name="form_as"> <option value="myself" selected>[% loc('Yourself') %]</option> [% IF can_contribute_as_another_user %] <option value="another_user">[% loc('Another user') %]</option> [% END %] + [% IF can_contribute_as_anonymous_user %] + <option value="anonymous_user">[% loc('Anonymous user') %]</option> + [% END %] [% IF can_contribute_as_body %] <option value="body">[% c.user.from_body.name %]</option> [% END %] |