aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-08-17 18:43:04 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-08-17 18:43:04 +0100
commite020fe9e36b96b447d992f0d4a5ff2eaea34fcf3 (patch)
treecb508c0cbe59776aacfe3ccf5dcda8f737ec6370
parent9e7d7e358d098ff91f8585fe97b53a4b58bad46e (diff)
parent1c15d23b6950618d3518197352a3330390bd9c3e (diff)
Merge branch 'issues/forcouncils/187-all-reports-filter-by-substates'
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm13
-rw-r--r--t/app/controller/reports.t79
-rw-r--r--templates/web/base/reports/_list-filters.html12
4 files changed, 105 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95886d478..789a1e456 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
- Body and category names can now be translated in the admin. #1244
- Body users can now create reports as an anonymous user. #1796
- Extra fields can be added to report form site-wide. #1743
+ - Body users can filter reports by all states. #1790
- Front end improvements:
- Always show pagination figures even if only one page.
- Admin improvements:
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index ec18e33d0..2b5777773 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -542,6 +542,19 @@ sub stash_report_filter_status : Private {
$filter_status{unshortlisted} = 1;
}
+ if ($c->user and ($c->user->is_superuser or (
+ $c->stash->{body} and $c->user->belongs_to_body($c->stash->{body}->id)
+ ))) {
+ foreach my $state (FixMyStreet::DB::Result::Problem->visible_states()) {
+ if ($status{$state}) {
+ %filter_problem_states = (%filter_problem_states, ($state => 1));
+ my $pretty_state = $state;
+ $pretty_state =~ tr/ /_/;
+ $filter_status{$pretty_state} = 1;
+ }
+ }
+ }
+
if (keys %filter_problem_states == 0) {
my $s = FixMyStreet::DB::Result::Problem->open_states();
%filter_problem_states = (%filter_problem_states, %$s);
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 9f28a6c89..f3958a0a5 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -277,6 +277,85 @@ subtest "it lists shortlisted reports" => sub {
};
};
+subtest "it allows body users to filter by subtypes" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/'
+ }, sub {
+ my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id );
+ my $user = $mech->log_in_ok( 'test@example.com' );
+ $user->update({ from_body => $body });
+
+ my ($investigating_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Investigating report');
+ my ($scheduled_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'A Scheduled report');
+ my ($in_progress_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'In progress report');
+
+ $investigating_problem->update({ state => 'investigating' });
+ $scheduled_problem->update({ state => 'action scheduled' });
+ $in_progress_problem->update({ state => 'in progress' });
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council');
+ $mech->content_contains('<option value="investigating">Investigating</option>');
+ $mech->content_contains('<option value="in progress">In progress</option>');
+ $mech->content_contains('<option value="action scheduled">Action scheduled</option>');
+ $mech->content_contains('<option value="unable to fix">No further action</option>');
+ $mech->content_contains('<option value="not responsible">Not responsible</option>');
+ $mech->content_contains('<option value="internal referral">Internal referral</option>');
+ $mech->content_contains('<option value="duplicate">Duplicate</option>');
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council?status=investigating');
+
+ $in_progress_problem->discard_changes();
+
+ $mech->content_contains('Investigating report');
+ $mech->content_lacks('In progress report');
+ $mech->content_lacks('A Scheduled report');
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council?status=in progress');
+
+ $mech->content_lacks('Investigating report');
+ $mech->content_contains('In progress report');
+ $mech->content_lacks('A Scheduled report');
+ };
+};
+
+subtest "it does not allow non body users to filter by subtypes" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/'
+ }, sub {
+ my $user = $mech->log_in_ok( 'test@example.com' );
+ $user->update({ from_body => undef });
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council');
+ $mech->content_lacks('<option value="investigating">Investigating</option>');
+ $mech->content_lacks('<option value="in progress">In progress</option>');
+ $mech->content_lacks('<option value="action scheduled">Action scheduled</option>');
+ $mech->content_lacks('<option value="unable to fix">No further action</option>');
+ $mech->content_lacks('<option value="not responsible">Not responsible</option>');
+ $mech->content_lacks('<option value="internal referral">Internal referral</option>');
+ $mech->content_lacks('<option value="duplicate">Duplicate</option>');
+ };
+};
+
+subtest "it does not allow body users to filter subcategories for other bodies" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/'
+ }, sub {
+ my $body = FixMyStreet::App->model('DB::Body')->find( $body_west_id );
+ my $user = $mech->log_in_ok( 'test@example.com' );
+ $user->update({ from_body => $body });
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council');
+
+ $mech->content_lacks('<option value="investigating">Investigating</option>');
+ $mech->content_lacks('<option value="in progress">In progress</option>');
+ $mech->content_lacks('<option value="action scheduled">Action scheduled</option>');
+ $mech->content_lacks('<option value="unable to fix">No further action</option>');
+ $mech->content_lacks('<option value="not responsible">Not responsible</option>');
+ $mech->content_lacks('<option value="internal referral">Internal referral</option>');
+ $mech->content_lacks('<option value="duplicate">Duplicate</option>');
+ };
+};
+
subtest "can use translated body name" => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
diff --git a/templates/web/base/reports/_list-filters.html b/templates/web/base/reports/_list-filters.html
index 73afe64f4..ef7c7ad78 100644
--- a/templates/web/base/reports/_list-filters.html
+++ b/templates/web/base/reports/_list-filters.html
@@ -9,9 +9,21 @@
<option value="shortlisted"[% ' selected' IF filter_status.shortlisted %]>[% loc('Shortlisted') %]</option>
<option value="unshortlisted"[% ' selected' IF filter_status.unshortlisted %]>[% loc('Unshortlisted') %]</option>
[% END %]
+ [% IF c.user_exists AND c.user.is_superuser OR c.user.belongs_to_body(body.id) %]
+ <option value="confirmed"[% ' selected' IF filter_status.confirmed %]>[% loc('Open') %]</option>
+ <option value="investigating"[% ' selected' IF filter_status.investigating %]>[% loc('Investigating') %]</option>
+ <option value="in progress"[% ' selected' IF filter_status.in_progress %]>[% loc('In progress') %]</option>
+ <option value="action scheduled"[% ' selected' IF filter_status.action_scheduled %]>[% loc('Action scheduled') %]</option>
+ <option value="fixed"[% ' selected' IF filter_status.fixed %]>[% loc('Fixed reports') %]</option>
+ <option value="unable to fix"[% ' selected' IF filter_status.unable_to_fix %]>[% loc('No further action') %]</option>
+ <option value="not responsible"[% ' selected' IF filter_status.not_responsible %]>[% loc('Not responsible') %]</option>
+ <option value="internal referral"[% ' selected' IF filter_status.internal_referral %]>[% loc('Internal referral') %]</option>
+ <option value="duplicate"[% ' selected' IF filter_status.duplicate %]>[% loc('Duplicate') %]</option>
+ [% ELSE %]
<option value="open"[% ' selected' IF filter_status.open %]>[% loc('Unfixed reports') %]</option>
<option value="closed"[% ' selected' IF filter_status.closed %]>[% loc('Closed reports') %]</option>
<option value="fixed"[% ' selected' IF filter_status.fixed %]>[% loc('Fixed reports') %]</option>
+ [% END %]
</select>
[% END %]