diff options
author | Struan Donald <struan@exo.org.uk> | 2017-08-09 16:46:39 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2017-08-16 10:42:23 +0100 |
commit | f066a3937216e0cc4dc0413efc8e8f90e79b6066 (patch) | |
tree | 46b9dd9d5c71b3ba8b44358e5a2864b33b24f6a1 | |
parent | 60b941bc7868c4b0a829f7d497262015d6ab69c4 (diff) |
enable body users to report problems anonymously
uses the body user but flags the report as anonymous
Fixes #fixmystreetforcouncils/207
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 1 | ||||
-rw-r--r-- | t/app/controller/admin.t | 1 | ||||
-rw-r--r-- | t/app/controller/admin_permissions.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 14 | ||||
-rw-r--r-- | templates/web/base/report/new/form_user_loggedin.html | 6 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/staff.js | 10 |
9 files changed, 44 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 50c937b10..cea9e8782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Unreleased - New features: - Body and category names can now be translated in the admin. #1244 + - Body users can now create reports as an anonymous user. #1796 - Front end improvements: - Always show pagination figures even if only one page. - Admin improvements: diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ab4c616fb..a8d5b995e 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -201,8 +201,10 @@ sub report_form_ajax : Path('ajax') : Args(0) { if ($c->user_exists) { my @bodies = keys %{$c->stash->{bodies}}; my $ca_another_user = $c->user->has_permission_to('contribute_as_another_user', \@bodies); + my $ca_anonymous_user = $c->user->has_permission_to('contribute_as_anonymous_user', \@bodies); my $ca_body = $c->user->from_body && $c->user->has_permission_to('contribute_as_body', \@bodies); $contribute_as->{another_user} = $ca_another_user if $ca_another_user; + $contribute_as->{anonymous_user} = $ca_anonymous_user if $ca_anonymous_user; $contribute_as->{body} = $ca_body if $ca_body; } @@ -742,7 +744,8 @@ sub process_user : Private { $user->title( $user_title ) if $user_title; $report->user( $user ); - if ($c->stash->{contributing_as_body} = $user->contributing_as('body', $c, $c->stash->{bodies})) { + if ($c->stash->{contributing_as_body} = $user->contributing_as('body', $c, $c->stash->{bodies}) or + $c->stash->{contributing_as_anonymous_user} = $user->contributing_as('anonymous_user', $c, $c->stash->{bodies})) { $report->name($user->from_body->name); $user->name($user->from_body->name) unless $user->name; $c->stash->{no_reporter_alert} = 1; @@ -822,6 +825,8 @@ sub process_report : Private { # set some simple bool values (note they get inverted) if ($c->stash->{contributing_as_body}) { $report->anonymous(0); + } elsif ($c->stash->{contributing_as_anonymous_user}) { + $report->anonymous(1); } else { $report->anonymous( $params{may_show_name} ? 0 : 1 ); } @@ -1148,7 +1153,7 @@ sub save_user_and_report : Private { sub created_as_someone_else : Private { my ($self, $c, $bodies) = @_; - return $c->stash->{contributing_as_another_user} || $c->stash->{contributing_as_body}; + return $c->stash->{contributing_as_another_user} || $c->stash->{contributing_as_body} || $c->stash->{contributing_as_anonymous_user}; } =head2 generate_map diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 1a0bbb0c8..852f380f0 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -710,6 +710,7 @@ sub available_permissions { report_instruct => _("Instruct contractors to fix problems"), # future use planned_reports => _("Manage shortlist"), contribute_as_another_user => _("Create reports/updates on a user's behalf"), + contribute_as_anonymous_user => _("Create reports/updates as anonymous user"), contribute_as_body => _("Create reports/updates as the council"), view_body_contribute_details => _("See user detail for reports created as the council"), diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 069e00b5e..075ab0fd0 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1177,6 +1177,7 @@ my %default_perms = ( "permissions[report_inspect]" => undef, "permissions[report_instruct]" => undef, "permissions[contribute_as_another_user]" => undef, + "permissions[contribute_as_anonymous_user]" => undef, "permissions[contribute_as_body]" => undef, "permissions[view_body_contribute_details]" => undef, "permissions[user_edit]" => undef, diff --git a/t/app/controller/admin_permissions.t b/t/app/controller/admin_permissions.t index 0997e1e38..7944cc0b1 100644 --- a/t/app/controller/admin_permissions.t +++ b/t/app/controller/admin_permissions.t @@ -146,6 +146,7 @@ FixMyStreet::override_config { "permissions[report_inspect]" => undef, "permissions[report_instruct]" => undef, "permissions[contribute_as_another_user]" => undef, + "permissions[contribute_as_anonymous_user]" => undef, "permissions[contribute_as_body]" => undef, "permissions[user_edit]" => undef, "permissions[user_manage_permissions]" => undef, @@ -178,6 +179,7 @@ FixMyStreet::override_config { "permissions[report_inspect]" => undef, "permissions[report_instruct]" => undef, "permissions[contribute_as_another_user]" => undef, + "permissions[contribute_as_anonymous_user]" => undef, "permissions[contribute_as_body]" => undef, "permissions[user_edit]" => undef, "permissions[user_manage_permissions]" => undef, diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index 86c2deb93..326b3c906 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -76,6 +76,20 @@ subtest "Body user, has permission to add report as another (existing) user" => push @users, $report->user; }; +subtest "Body user, has permission to add report as anonymous user" => sub { + my $report = add_report( + 'contribute_as_anonymous_user', + form_as => 'anonymous_user', + title => "Test Report", + detail => 'Test report details.', + category => 'Street lighting', + ); + is $report->name, 'Oxfordshire County Council', 'report name is body'; + is $report->user->name, 'Body User', 'user name unchanged'; + is $report->user->id, $user->id, 'user matches'; + is $report->anonymous, 1, 'report anonymous'; +}; + subtest "Body user, has permission to add update as council" => sub { my $update = add_update( 'contribute_as_body', diff --git a/templates/web/base/report/new/form_user_loggedin.html b/templates/web/base/report/new/form_user_loggedin.html index d5c347d8c..8e6629273 100644 --- a/templates/web/base/report/new/form_user_loggedin.html +++ b/templates/web/base/report/new/form_user_loggedin.html @@ -6,8 +6,9 @@ </div> [% ELSE %] [% can_contribute_as_another_user = c.user.has_permission_to("contribute_as_another_user", bodies.keys) %] + [% can_contribute_as_anonymous_user = c.user.has_permission_to("contribute_as_anonymous_user", bodies.keys) %] [% can_contribute_as_body = c.user.from_body AND c.user.has_permission_to("contribute_as_body", bodies.keys) %] - [% IF can_contribute_as_another_user OR can_contribute_as_body %] + [% IF can_contribute_as_another_user OR can_contribute_as_anonymous_user OR can_contribute_as_body %] [% INCLUDE form_as %] [% END %] [% END %] @@ -16,6 +17,9 @@ <label for="form_as">[% loc('Report as') %]</label> <select id="form_as" class="form-control js-contribute-as" name="form_as"> <option value="myself" [% c.user.has_body_permission_to('planned_reports') ? '' : 'selected' %]>[% loc('Yourself') %]</option> + [% IF js || can_contribute_as_anonymous_user %] + <option value="anonymous_user">[% loc('Anonymous user') %]</option> + [% END %] [% IF js || can_contribute_as_another_user %] <option value="another_user">[% loc('Another user') %]</option> [% END %] diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 4d38c81d2..291455aa7 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -912,6 +912,9 @@ fixmystreet.update_pin = function(lonlat, savePushState) { if (!data.contribute_as.another_user) { $select.find('option[value=another_user]').remove(); } + if (!data.contribute_as.anonymous_user) { + $select.find('option[value=anonymous_user]').remove(); + } if (!data.contribute_as.body) { $select.find('option[value=body]').remove(); } diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js index 66f9411cd..95fbad81a 100644 --- a/web/cobrands/fixmystreet/staff.js +++ b/web/cobrands/fixmystreet/staff.js @@ -173,21 +173,31 @@ $.extend(fixmystreet.set_up, { txt = opt.text; var $emailInput = $('input[name=email]').add('input[name=rznvy]'); var $nameInput = $('input[name=name]'); + var $phoneInput = $('input[name=phone]'); var $showNameCheckbox = $('input[name=may_show_name]'); var $addAlertCheckbox = $('#form_add_alert'); if (val === 'myself') { $emailInput.val($emailInput.prop('defaultValue')).prop('disabled', true); $nameInput.val($nameInput.prop('defaultValue')).prop('disabled', false); + $phoneInput.val($phoneInput.prop('defaultValue')).prop('disabled', false); $showNameCheckbox.prop('checked', false).prop('disabled', false); $addAlertCheckbox.prop('checked', true).prop('disabled', false); } else if (val === 'another_user') { $emailInput.val('').prop('disabled', false); $nameInput.val('').prop('disabled', false); + $phoneInput.val('').prop('disabled', false); $showNameCheckbox.prop('checked', false).prop('disabled', true); $addAlertCheckbox.prop('checked', true).prop('disabled', false); + } else if (val === 'anonymous_user') { + $emailInput.val('-').prop('disabled', true); + $nameInput.val('-').prop('disabled', true); + $phoneInput.val('-').prop('disabled', true); + $showNameCheckbox.prop('checked', false).prop('disabled', true); + $addAlertCheckbox.prop('checked', false).prop('disabled', true); } else if (val === 'body') { $emailInput.val('-').prop('disabled', true); $nameInput.val(txt).prop('disabled', true); + $phoneInput.val('-').prop('disabled', true); $showNameCheckbox.prop('checked', true).prop('disabled', true); $addAlertCheckbox.prop('checked', false).prop('disabled', true); } |