aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-11-01 10:50:38 +0000
committerStruan Donald <struan@exo.org.uk>2018-11-19 13:29:49 +0000
commitb4618c61ff5ddf6db9662b06bc55a0f74b43c903 (patch)
tree17e4c2a7651a60b14bd37a2bc2d19f670ddc4153
parentb35552138fd66673df46747549989d545bbcfa9f (diff)
add default_to_body permission
If a user has this permission then the report_as dropdown will default to reporting as the body. For mysociety/freshdesk#23
-rw-r--r--CHANGELOG.md2
-rw-r--r--docs/_includes/admin-tasks-content.md5
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm1
-rw-r--r--t/app/controller/admin/users.t1
-rw-r--r--t/app/controller/report_as_other.t18
-rw-r--r--templates/web/base/report/new/form_user_loggedin.html4
7 files changed, 30 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ae5734ad..18b1885c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
## Releases
* Unreleased
+ - New features:
+ - default_to_body permission to control default report as behaviour
- Front end improvements:
- Clearer relocation options while you’re reporting a problem #2238
- Simplify /auth sign in page. #2208
diff --git a/docs/_includes/admin-tasks-content.md b/docs/_includes/admin-tasks-content.md
index 712da5b1e..cc1a0691e 100644
--- a/docs/_includes/admin-tasks-content.md
+++ b/docs/_includes/admin-tasks-content.md
@@ -166,6 +166,11 @@ citizen’s experience](/pro-manual/citizens-experience/)'. Those with the appro
the report-making interface, labeled ‘Report As’. Select ‘the council’, ‘yourself’, ‘anonymous’ or
‘another user’.
+If a user has the ‘Default to creating reports/update as the council’
+permission then the dropdown will default to reporting as the council.
+Staff with the ’Markup problem details’ permission will also default to
+reporting as the council.
+
</div>
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index d71b96392..c6616a003 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -724,6 +724,7 @@ sub available_permissions {
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"),
+ default_to_body => _("Default to creating reports/updates as the council"),
view_body_contribute_details => _("See user detail for reports created as the council"),
# NB this permission is special in that it can be assigned to users
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index 72f6ff89e..7eb63a371 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -215,6 +215,7 @@ sub available_permissions {
my $self = shift;
my $perms = $self->next::method();
+ $perms->{Problems}->{default_to_body} = "Default to creating reports/updates as " . $self->council_name;
$perms->{Problems}->{contribute_as_body} = "Create reports/updates as " . $self->council_name;
$perms->{Problems}->{view_body_contribute_details} = "See user detail for reports created as " . $self->council_name;
$perms->{Users}->{user_assign_areas} = "Assign users to areas in " . $self->council_name;
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t
index 903ec3104..08bfb73fd 100644
--- a/t/app/controller/admin/users.t
+++ b/t/app/controller/admin/users.t
@@ -177,6 +177,7 @@ my %default_perms = (
"permissions[contribute_as_another_user]" => undef,
"permissions[contribute_as_anonymous_user]" => undef,
"permissions[contribute_as_body]" => undef,
+ "permissions[default_to_body]" => undef,
"permissions[view_body_contribute_details]" => 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 367d9a1d4..f256374a8 100644
--- a/t/app/controller/report_as_other.t
+++ b/t/app/controller/report_as_other.t
@@ -282,6 +282,24 @@ subtest "Body user, has permission to add update as anonymous user" => sub {
is $update->anonymous, 1, 'update anonymous';
};
+for my $test_permission ( qw/planned_reports default_to_body/ ) {
+ subtest "$test_permission user defaults to reporting as body" => sub {
+ $_->delete for $user->user_body_permissions;
+ for my $permission ( 'contribute_as_another_user', 'contribute_as_anonymous_user', 'contribute_as_body', $test_permission ) {
+ $user->user_body_permissions->create({ body => $body, permission_type => $permission })
+ }
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ PHONE_COUNTRY => 'GB',
+ }, sub {
+ $mech->get_ok('/report/new?latitude=51.7549262252&longitude=-1.25617899435');
+ };
+
+ is $mech->visible_form_values()->{form_as}, 'body', 'report as body is default';
+ };
+}
+
done_testing();
sub start_report {
diff --git a/templates/web/base/report/new/form_user_loggedin.html b/templates/web/base/report/new/form_user_loggedin.html
index 41cbc4a54..8c53b4365 100644
--- a/templates/web/base/report/new/form_user_loggedin.html
+++ b/templates/web/base/report/new/form_user_loggedin.html
@@ -16,7 +16,7 @@
[% BLOCK form_as %]
<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>
+ <option value="myself" [% ( c.user.has_body_permission_to('planned_reports') || c.user.has_body_permission_to('default_to_body') ) ? '' : 'selected' %]>[% loc('Yourself') %]</option>
[% IF js || can_contribute_as_anonymous_user %]
<option value="anonymous_user">[% loc('Anonymous user') %]</option>
[% END %]
@@ -24,7 +24,7 @@
<option value="another_user">[% loc('Another user') %]</option>
[% END %]
[% IF js || can_contribute_as_body %]
- <option value="body" [% c.user.has_body_permission_to('planned_reports') ? 'selected' : '' %]>[% c.user.from_body.name %]</option>
+ <option value="body" [% ( c.user.has_body_permission_to('planned_reports') || c.user.has_body_permission_to('default_to_body') ) ? 'selected' : '' %]>[% c.user.from_body.name %]</option>
[% END %]
</select>
[% END %]