diff options
-rw-r--r-- | .cypress/cypress/integration/staff.js | 46 | ||||
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rwxr-xr-x | bin/fixmystreet.com/fixture | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 1 | ||||
-rw-r--r-- | t/app/controller/admin/users.t | 1 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 25 | ||||
-rw-r--r-- | templates/web/base/report/new/category.html | 3 | ||||
-rw-r--r-- | templates/web/base/report/new/category_wrapper.html | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/staff.js | 3 |
9 files changed, 84 insertions, 5 deletions
diff --git a/.cypress/cypress/integration/staff.js b/.cypress/cypress/integration/staff.js new file mode 100644 index 000000000..88afb5490 --- /dev/null +++ b/.cypress/cypress/integration/staff.js @@ -0,0 +1,46 @@ +Cypress.Commands.add('cleanUpXHR', function() { + cy.visit('/404', { failOnStatusCode: false }); +}); + +describe('Staff user tests', function() { + it('report as defaults to body', function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.request({ + method: 'POST', + url: '/auth?r=/', + form: true, + body: { username: 'cs_full@example.org', password_sign_in: 'password' } + }); + cy.visit('/'); + cy.contains('Go'); + cy.get('[name=pc]').type(Cypress.env('postcode')); + cy.get('[name=pc]').parents('form').submit(); + cy.url().should('include', '/around'); + cy.get('#map_box').click(210, 200); + cy.get('[name=form_as]').should('have.value', 'body'); + cy.cleanUpXHR(); + }); + + it('report title and detail are correctly prefilled', function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.request({ + method: 'POST', + url: '/auth?r=/', + form: true, + body: { username: 'cs_full@example.org', password_sign_in: 'password' } + }); + cy.visit('/'); + cy.contains('Go'); + cy.get('[name=pc]').type(Cypress.env('postcode')); + cy.get('[name=pc]').parents('form').submit(); + cy.url().should('include', '/around'); + cy.get('#map_box').click(210, 200); + cy.wait('@report-ajax'); + cy.get('select:eq(3)').select('Graffiti'); + cy.get('[name=title]').should('have.value', 'A Graffiti problem has been found'); + cy.get('[name=detail]').should('have.value', 'A Graffiti problem has been found by Borsetshire'); + cy.cleanUpXHR(); + }); +}); diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b1885c7..21e6066fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Unreleased - New features: - default_to_body permission to control default report as behaviour + - report_prefill permission to control report prefill behaviour - Front end improvements: - Clearer relocation options while you’re reporting a problem #2238 - Simplify /auth sign in page. #2208 diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture index 8e943a5b5..1ca840c71 100755 --- a/bin/fixmystreet.com/fixture +++ b/bin/fixmystreet.com/fixture @@ -84,9 +84,15 @@ my $perms_cs = [ 'contribute_as_body', 'contribute_as_another_user', 'moderate', 'view_body_contribute_details', ]; +my $perms_cs_full = [ + 'contribute_as_body', 'contribute_as_another_user', + 'moderate', 'view_body_contribute_details', + 'report_prefill', 'default_to_body' +]; foreach ( { name => 'Inspector Gadget', email => 'inspector@example.org', email_verified => 1, body => $body, permissions => $perms_inspector }, { name => 'Harriet Helpful', email_verified => 1, email => 'cs@example.org', body => $body, permissions => $perms_cs }, + { name => 'Andrew Agreeable', email_verified => 1, email => 'cs_full@example.org', body => $body, permissions => $perms_cs_full }, { name => 'Super User', email_verified => 1, email => 'super@example.org', body => $body, permissions => [ @$perms_cs, @$perms_inspector, 'report_edit', 'category_edit', 'template_edit', 'responsepriority_edit', diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index c6616a003..88d208c85 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -720,6 +720,7 @@ sub available_permissions { report_mark_private => _("View/Mark private reports"), report_inspect => _("Markup problem details"), report_instruct => _("Instruct contractors to fix problems"), # future use + report_prefill => _("Automatically populate report subject/detail"), 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"), diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index 08bfb73fd..be781d3ae 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -174,6 +174,7 @@ my %default_perms = ( "permissions[report_edit_priority]" => undef, "permissions[report_inspect]" => undef, "permissions[report_instruct]" => undef, + "permissions[report_prefill]" => undef, "permissions[contribute_as_another_user]" => undef, "permissions[contribute_as_anonymous_user]" => undef, "permissions[contribute_as_body]" => undef, diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index c2e731e61..5f807f0e9 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -2048,10 +2048,33 @@ subtest "check map click ajax response for inspector" => sub { }, sub { $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=55.952055&longitude=-3.189579' ); }; - like $extra_details->{category}, qr/data-role="inspector/, 'category has correct data-role'; + like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set'; ok !$extra_details->{contribute_as}, 'no contribute as section'; }; +subtest "check map click ajax response for inspector and uk cobrand" => sub { + $mech->log_out_ok; + + my $extra_details; + $inspector->user_body_permissions->find_or_create({ + body => $bodies[4], + permission_type => 'planned_reports', + }); + $inspector->user_body_permissions->find_or_create({ + body => $bodies[4], + permission_type => 'report_inspect', + }); + + $mech->log_in_ok('inspector@example.org'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { bromley => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.402096&longitude=0.015784' ); + }; + like $extra_details->{category}, qr/data-prefill="0/, 'inspector prefill not set'; +}; + for my $test ( { desc => 'map click ajax for contribute_as_another_user', diff --git a/templates/web/base/report/new/category.html b/templates/web/base/report/new/category.html index 83af42c6d..44ed8df71 100644 --- a/templates/web/base/report/new/category.html +++ b/templates/web/base/report/new/category.html @@ -15,7 +15,8 @@ </label>[% =%] <select class="form-control[% IF category_groups.size %] js-grouped-select[% END %]" name="category" id="form_category" [%~ IF c.user.from_body =%] - data-role="[% c.user.has_body_permission_to('planned_reports') ? 'inspector' : 'user' %]" data-body="[% c.user.from_body.name %]" data-prefill="[% c.cobrand.prefill_report_fields_for_inspector %]" + [%~ prefill_report = ( c.cobrand.prefill_report_fields_for_inspector && inspector ) || c.user.has_body_permission_to('report_prefill') %] + data-body="[% c.user.from_body.name %]" data-prefill="[% prefill_report %]" [%~ END ~%] > [%~ IF category_groups.size ~%] diff --git a/templates/web/base/report/new/category_wrapper.html b/templates/web/base/report/new/category_wrapper.html index abc44d062..da25e51df 100644 --- a/templates/web/base/report/new/category_wrapper.html +++ b/templates/web/base/report/new/category_wrapper.html @@ -3,7 +3,8 @@ <label for="form_category">[% loc('Category') %]</label> <select class="form-control" name="category" id="form_category" [%~ IF c.user.from_body =%] - data-role="[% c.user.has_body_permission_to('planned_reports') ? 'inspector' : 'user' %]" data-body="[% c.user.from_body.name %]" data-prefill="[% c.cobrand.prefill_report_fields_for_inspector %]" + [%~ prefill_report = c.cobrand.prefill_report_fields_for_inspector || c.user.has_body_permission_to('report_prefill') %] + data-body="[% c.user.from_body.name %]" data-prefill="[% prefill_report %]" [%~ END =%] required><option>[% loc('Loading...') %]</option></select> [% ELSE %] diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js index a52595802..7fe12b04b 100644 --- a/web/cobrands/fixmystreet/staff.js +++ b/web/cobrands/fixmystreet/staff.js @@ -455,10 +455,9 @@ $.extend(fixmystreet.set_up, { $(fixmystreet).on('report_new:category_change', function(evt, $this) { var category = $this.val(); var prefill_reports = $this.data('prefill'); - var role = $this.data('role'); var body = $this.data('body'); - if (prefill_reports && role == 'inspector') { + if (prefill_reports) { var title = 'A ' + category + ' problem has been found'; var description = 'A ' + category + ' problem has been found by ' + body; |