diff options
25 files changed, 100 insertions, 62 deletions
diff --git a/.cypress/cypress/integration/simple_spec.js b/.cypress/cypress/integration/simple_spec.js index e2b776d21..074bf72bd 100644 --- a/.cypress/cypress/integration/simple_spec.js +++ b/.cypress/cypress/integration/simple_spec.js @@ -20,6 +20,9 @@ describe('Clicking the map', function() { cy.get('#map_sidebar').should('contain', 'check and confirm your details'); cy.get('#map_sidebar').parents('form').submit(); cy.get('body').should('contain', 'Thank you for reporting this issue'); + cy.visit('http://fixmystreet.localhost:3001/_test/setup/simple-service-check').then(function(w) { + expect(w.document.documentElement.innerText).to.equal('desktop'); + }); }); }); diff --git a/.travis.yml b/.travis.yml index 970f80298..ca5eaee6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ install: - 'if [ "$CYPRESS" = "1" ]; then npm install cypress@3.8.3; fi' before_script: - commonlib/bin/gettext-makemo FixMyStreet - - 'if [ "$COVERAGE_PART" != "0" ]; then export HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,local/lib/perl5,commonlib,perllib/Catalyst/[^A],perllib/Email,^t"; fi' + - 'if [ "$COVERAGE_PART" != "0" ]; then export HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,local/lib/perl5,commonlib,perllib/Catalyst/[^A],perllib/Email,Test.pm,^t"; fi' script: - 'if [ "$CYPRESS" = "0" ] && [ "$COVERAGE_PART" = "0" ]; then script/test --jobs 3 t; fi' - 'if [ "$COVERAGE_PART" = "1" ]; then script/test --jobs 3 `find t/app/controller -name "*.t"`; fi' diff --git a/CHANGELOG.md b/CHANGELOG.md index a9f118021..b31e4cf95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,8 @@ - Allow inspectors to change report asset. - Staff users can use HTML tags in updates. #3143 - Response templates can include HTML tags. #3143 + - Record whether report made on desktop or mobile. + - Do not display deleted priorities in inspect form. #3195 - Development improvements: - `#geolocate_link` is now easier to re-style. #3006 - Links inside `#front-main` can be customised using `$primary_link_*` Sass variables. #3007 diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 81d5b18b5..98c4aba17 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -413,7 +413,8 @@ sub inspect : Private { if ($c->cobrand->can('body')) { my $priorities_by_category = FixMyStreet::App->model('DB::ResponsePriority')->by_categories( $c->stash->{contacts}, - body_id => $c->cobrand->body->id + body_id => $c->cobrand->body->id, + problem => $problem, ); $c->stash->{priorities_by_category} = $priorities_by_category; my $templates_by_category = FixMyStreet::App->model('DB::ResponseTemplate')->by_categories( diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index d676e2856..037e1992a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -29,8 +29,8 @@ Create a new report, or complete a partial one. submit_problem: true if a problem has been submitted, at all. submit_sign_in: true if the sign in button has been clicked by logged out user. -submit_register: true if the register/confirm by email button has been clicked -by logged out user. +submit_register(_mobile): true if the register/confirm by email button has been clicked +by logged out user, or submit button clicked by logged in user. =head2 location (required) @@ -1046,7 +1046,13 @@ sub process_report : Private { $report->detail( $detail ); # mobile device type - $report->service( $params{service} ) if $params{service}; + if ($params{service}) { + $report->service($params{service}); + } elsif ($c->get_param('submit_register_mobile')) { + $report->service('mobile'); + } elsif ($c->get_param('submit_register')) { + $report->service('desktop'); + } # set these straight from the params $report->category( _ $params{category} ) if $params{category}; diff --git a/perllib/FixMyStreet/App/Controller/Test.pm b/perllib/FixMyStreet/App/Controller/Test.pm index 19a8c5321..ce54f004f 100644 --- a/perllib/FixMyStreet/App/Controller/Test.pm +++ b/perllib/FixMyStreet/App/Controller/Test.pm @@ -61,6 +61,9 @@ sub setup : Path('/_test/setup') : Args(1) { }); $category->update; $c->response->body("OK"); + } elsif ($test eq 'simple-service-check') { + my $problem = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first; + $c->response->body($problem->service); } } diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 705f07f79..cd5e876b4 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -780,7 +780,11 @@ alphabetical order of name. sub response_priorities { my $self = shift; - return $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category); + my $rs = $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category); + $rs->search([ + 'me.deleted' => 0, + 'me.id' => $self->response_priority_id, + ]); } =head2 defect_types diff --git a/perllib/FixMyStreet/DB/ResultSet/DefectType.pm b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm index 5b1247129..c4c11042f 100644 --- a/perllib/FixMyStreet/DB/ResultSet/DefectType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm @@ -12,7 +12,7 @@ sub join_table { } sub map_extras { - my ($rs, @ts) = @_; + my ($rs, $params, @ts) = @_; return map { my $meta = $_->get_extra_metadata(); my %extra = map { $_ => $meta->{$_} } keys %$meta; diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm index 96f7cf7a0..af605afa6 100644 --- a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm +++ b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm @@ -12,8 +12,12 @@ sub join_table { } sub map_extras { - my ($rs, @ts) = @_; - return map { { id => $_->id, name => $_->name } } @ts; + my ($rs, $params, @ts) = @_; + my $current = $params->{problem} && $params->{problem}->response_priority_id || 0; + return + map { { id => $_->id, name => $_->name } } + grep { !$_->deleted || $_->id == $current } + @ts; } 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm b/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm index 46fcba153..88ecc2f94 100644 --- a/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm +++ b/perllib/FixMyStreet/DB/ResultSet/ResponseTemplate.pm @@ -14,7 +14,7 @@ sub name_column { } sub map_extras { - my ($rs, @ts) = @_; + my ($rs, $params, @ts) = @_; return map { my $out = { id => $_->text, name => $_->title }; $out->{state} = $_->state if $_->state; diff --git a/perllib/FixMyStreet/Roles/ContactExtra.pm b/perllib/FixMyStreet/Roles/ContactExtra.pm index 73b1d3e6a..9615b0f0c 100644 --- a/perllib/FixMyStreet/Roles/ContactExtra.pm +++ b/perllib/FixMyStreet/Roles/ContactExtra.pm @@ -45,7 +45,7 @@ sub by_categories { $_->$join_table == 0 # There's no category at all on this defect type/template/priority || (grep { $_->contact_id == $contact->get_column('id') } $_->$join_table) } @results; - @ts = $rs->map_extras(@ts); + @ts = $rs->map_extras(\%params, @ts); $extras{$contact->category} = JSON::XS->new->encode(\@ts); } diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index f6854fc98..7f7104d3d 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -609,29 +609,6 @@ sub get_ok_json { return decode_json( $res->content ); } -sub delete_body { - my $mech = shift; - my $body = shift; - - $mech->delete_problems_for_body($body->id); - $mech->delete_defect_type($_) for $body->defect_types; - $mech->delete_contact($_) for $body->contacts; - $mech->delete_user($_) for $body->users; - $_->delete for $body->response_templates; - $_->delete for $body->response_priorities; - $body->body_areas->delete; - $body->delete; -} - -sub delete_contact { - my $mech = shift; - my $contact = shift; - - $contact->contact_response_templates->delete_all; - $contact->contact_response_priorities->delete_all; - $contact->delete; -} - sub delete_problems_for_body { my $mech = shift; my $body = shift; @@ -646,14 +623,6 @@ sub delete_problems_for_body { } } -sub delete_defect_type { - my $mech = shift; - my $defect_type = shift; - - $defect_type->contact_defect_types->delete_all; - $defect_type->delete; -} - sub delete_response_template { my $mech = shift; my $response_template = shift; diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 96325760c..c10fe7f94 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -17,6 +17,11 @@ my $rp2 = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, name => 'Low Priority', }); +my $rp3 = FixMyStreet::DB->resultset("ResponsePriority")->create({ + body => $oxon, + name => 'Deleted Priority', + deleted => 1, +}); FixMyStreet::DB->resultset("ContactResponsePriority")->create({ contact => $contact, response_priority => $rp, @@ -447,6 +452,7 @@ FixMyStreet::override_config { subtest "default response priorities display correctly" => sub { $mech->get_ok("/report/$report_id"); $mech->content_contains('Priority</label', 'report priority list present'); + $mech->content_lacks('Deleted Priority'); like $mech->content, qr/<select name="priority" id="problem_priority" class="form-control">[^<]*<option value="" selecte/s, 'blank priority option is selected'; $mech->content_lacks('value="' . $rp->id . '" selected>High', 'non default priority not selected'); @@ -456,6 +462,12 @@ FixMyStreet::override_config { $mech->content_contains('value="' . $rp->id . '" selected>High', 'default priority selected'); }; + subtest "check when report has deleted priority" => sub { + $report->update({ response_priority => $rp3 }); + $mech->get_ok("/report/$report_id"); + $mech->content_contains('value="' . $rp3->id . '" selected>Deleted Priority'); + }; + foreach my $test ( { type => 'report_edit_priority', priority => 1 }, { type => 'report_edit_category', category => 1 }, diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index b0c93c332..77eb4fefb 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -149,7 +149,7 @@ foreach my $test ( $mech->submit_form_ok( { - button => 'submit_register', + button => 'submit_register_mobile', with_fields => { title => 'Test Report', detail => 'Test report details.', diff --git a/t/app/model/responsepriority.t b/t/app/model/responsepriority.t index bd09c2da0..0ecce1529 100644 --- a/t/app/model/responsepriority.t +++ b/t/app/model/responsepriority.t @@ -12,6 +12,7 @@ my $oxfordshire = $mech->create_body_ok($area_id, 'Oxfordshire County Council'); my $other_body = $mech->create_body_ok($area_id, 'Some Other Council'); my $potholes_contact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); my $traffic_lights_contact =$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); +my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all; my $potholes_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create( { @@ -32,25 +33,42 @@ my $general_response_priority = FixMyStreet::DB->resultset('ResponsePriority')-> } ); -subtest 'for_bodies returns correct results' => sub { +my $deleted1_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create( + { + body_id => $oxfordshire->id, + name => 'Deleted priority 1', + description => 'This priority has been deleted', + deleted => 1, + } +); + +my $deleted2_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create( + { + body_id => $oxfordshire->id, + name => 'Deleted priority 2', + description => 'This priority has been deleted', + deleted => 1, + } +); + +subtest 'for_bodies returns correct results (including deleted)' => sub { my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->for_bodies( [ $oxfordshire->id ], 'Potholes' ); - is $priorities->count, 2, 'Both priorities are included for Potholes category'; + is $priorities->count, 4, 'all priorities are included for Potholes category'; $priorities = FixMyStreet::DB->resultset('ResponsePriority')->for_bodies( [ $oxfordshire->id ], 'Traffic lights' ); - is $priorities->count, 1, 'Only 1 priority is included for Traffic lights category'; + is $priorities->count, 3, 'Pothole-only priority ignored for Traffic lights category'; is $priorities->first->name, $general_response_priority->name, 'Correct priority is returned for Traffic lights category'; }; -subtest 'by_categories returns all response priorities grouped by category' => sub { - my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all; +subtest 'by_categories returns all undeleted response priorities grouped by category' => sub { my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts, body_id => $oxfordshire->id); my $potholes = decode_json($priorities->{Potholes}); my $traffic_lights = decode_json($priorities->{'Traffic lights'}); @@ -59,7 +77,7 @@ subtest 'by_categories returns all response priorities grouped by category' => s is scalar @$traffic_lights, 1, 'Traffic lights have 1 defect type'; }; -subtest 'by_categories returns all response priorities for an area with multiple bodies' => sub { +subtest 'by_categories returns all undeleted response priorities for an area with multiple bodies' => sub { my $other_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create( { body_id => $other_body->id, @@ -68,7 +86,6 @@ subtest 'by_categories returns all response priorities for an area with multiple } ); - my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all; my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts, area_id => $area_id); my $potholes = decode_json($priorities->{Potholes}); my $traffic_lights = decode_json($priorities->{'Traffic lights'}); @@ -77,8 +94,16 @@ subtest 'by_categories returns all response priorities for an area with multiple is scalar @$traffic_lights, 2, 'Traffic lights have 2 defect types'; }; -END { - $mech->delete_body( $other_body ); - $mech->delete_body( $oxfordshire ); - done_testing(); -} +subtest 'test with existing problem' => sub { + my ($problem) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Title', { + response_priority => $deleted1_response_priority, + }); + my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts, + area_id => $area_id, problem => $problem); + my $potholes = decode_json($priorities->{Potholes}); + my $traffic_lights = decode_json($priorities->{'Traffic lights'}); + is scalar @$potholes, 4, 'Potholes have 4 defect types, deleted is included'; + is scalar @$traffic_lights, 3, 'Traffic lights have 3 defect types, deleted is included'; +}; + +done_testing(); diff --git a/templates/web/base/report/form/submit.html b/templates/web/base/report/form/submit.html new file mode 100644 index 000000000..950bed965 --- /dev/null +++ b/templates/web/base/report/form/submit.html @@ -0,0 +1,2 @@ +<input class="desk-only btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Submit') %]"> +<input class="mob-only btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register_mobile" value="[% loc('Submit') %]"> diff --git a/templates/web/base/report/form/user_loggedout_by_email.html b/templates/web/base/report/form/user_loggedout_by_email.html index 2e41deaea..3446fd767 100644 --- a/templates/web/base/report/form/user_loggedout_by_email.html +++ b/templates/web/base/report/form/user_loggedout_by_email.html @@ -87,7 +87,7 @@ [% PROCESS 'auth/form_extra.html' %] - <input class="btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Submit') %]"> + [% PROCESS 'report/form/submit.html' %] </div> <!-- /user_loggedout_by_email.html --> diff --git a/templates/web/base/report/inspect/extra_details.html b/templates/web/base/report/inspect/extra_details.html index 7777e9a78..66e464cef 100644 --- a/templates/web/base/report/inspect/extra_details.html +++ b/templates/web/base/report/inspect/extra_details.html @@ -3,7 +3,7 @@ <select name="priority" id="problem_priority" class="form-control"> <option value="" [% 'selected' UNLESS problem.response_priority_id OR has_default_priority %]>-</option> [% FOREACH priority IN problem.response_priorities %] - <option value="[% priority.id %]" [% 'selected' IF ( problem.response_priority_id == priority.id ) OR priority.is_default %][% 'disabled' IF priority.deleted %]>[% priority.name | html %]</option> + <option value="[% priority.id %]" [% 'selected' IF problem.response_priority_id == priority.id OR (NOT problem.response_priority_id AND priority.is_default) %]>[% priority.name | html %]</option> [% END %] </select> </p> diff --git a/templates/web/base/report/new/form_report.html b/templates/web/base/report/new/form_report.html index 3b28d4aa7..33dd5769e 100644 --- a/templates/web/base/report/new/form_report.html +++ b/templates/web/base/report/new/form_report.html @@ -89,5 +89,6 @@ <input type="hidden" id="single_body_only" name="single_body_only" value=""> <input type="hidden" id="do_not_send" name="do_not_send" value=""> <input type="hidden" name="submit_problem" value="1"> + <input type="hidden" id="form_service" name="service" value=""> </div> <!-- /report/new/form_report.html --> diff --git a/templates/web/base/report/new/form_user_loggedin.html b/templates/web/base/report/new/form_user_loggedin.html index 515f3842a..9215e7d59 100644 --- a/templates/web/base/report/new/form_user_loggedin.html +++ b/templates/web/base/report/new/form_user_loggedin.html @@ -74,5 +74,5 @@ </div> [% END %] -<input class="btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Submit') %]"> +[% PROCESS 'report/form/submit.html' %] <!-- /report/new/form_user_loggedin.html --> diff --git a/templates/web/base/report/new/login_success_form.html b/templates/web/base/report/new/login_success_form.html index 32c414bda..7ef896910 100644 --- a/templates/web/base/report/new/login_success_form.html +++ b/templates/web/base/report/new/login_success_form.html @@ -14,6 +14,6 @@ [% PROCESS "report/form/user_loggedout.html" type='report' object=report %] [% END %] [% PROCESS 'report/new/form_report.html' %] - <input class="btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Submit') %]"> + [% PROCESS 'report/form/submit.html' %] </div> </fieldset> diff --git a/templates/web/base/report/new/oauth_email_form.html b/templates/web/base/report/new/oauth_email_form.html index a0adbe563..126f93409 100644 --- a/templates/web/base/report/new/oauth_email_form.html +++ b/templates/web/base/report/new/oauth_email_form.html @@ -17,6 +17,6 @@ <input type="hidden" name="oauth_need_email" value="1"> [% PROCESS 'report/new/form_report.html' %] - <input class="btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Submit') %]"> + [% PROCESS 'report/form/submit.html' %] </div> </fieldset> diff --git a/templates/web/base/report/update/form_user_loggedin.html b/templates/web/base/report/update/form_user_loggedin.html index 8d55737d2..02e7de51f 100644 --- a/templates/web/base/report/update/form_user_loggedin.html +++ b/templates/web/base/report/update/form_user_loggedin.html @@ -38,5 +38,7 @@ <label class="inline" for="form_add_alert">[% loc( 'Alert me to future updates' ) %]</label> </div> -<div class="clearfix"><input class="btn btn--primary btn--block btn--final js-submit_register" type="submit" name="submit_register" value="[% loc('Post') %]"></div> +<div class="clearfix"> + [% PROCESS 'report/form/submit.html' %] +</div> <!-- /report/update/form_user_loggedin.html --> diff --git a/templates/web/zurich/report/new/fill_in_details_form.html b/templates/web/zurich/report/new/fill_in_details_form.html index 8d840c43e..c7ad0fb96 100644 --- a/templates/web/zurich/report/new/fill_in_details_form.html +++ b/templates/web/zurich/report/new/fill_in_details_form.html @@ -70,7 +70,10 @@ <div class="form-txt-submit-box"> [%# class of submit_sign_in so name can be optional, name of submit_register so it doesn't try and sign us in %] - <p><input class="green-btn js-submit_sign_in" type="submit" name="submit_register" value="[% loc('Submit') %]"> + <p> + <input class="desk-only green-btn js-submit_sign_in" type="submit" name="submit_register" value="[% loc('Submit') %]"> + <input class="mob-only green-btn js-submit_sign_in" type="submit" name="submit_register_mobile" value="[% loc('Submit') %]"> + </p> </div> </div> diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 9c6ce83ed..15856f4ce 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -659,6 +659,7 @@ $.extend(fixmystreet.set_up, { } else { fixmystreet.resize_to.desktop_page(); } + $('#form_service').val(type); last_type = type; }).resize(); }, |