aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/fixmystreet.com/fixture13
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm22
-rw-r--r--perllib/FixMyStreet/Cobrand/IsleOfWight.pm88
-rw-r--r--t/cobrand/isleofwight.t64
5 files changed, 188 insertions, 12 deletions
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture
index f1b2ff4c3..1f6063a47 100755
--- a/bin/fixmystreet.com/fixture
+++ b/bin/fixmystreet.com/fixture
@@ -148,15 +148,26 @@ if ($opt->test_fixtures) {
$child_cat = FixMyStreet::DB->resultset("Contact")->find({
body => $bodies->{2636},
+ category => 'Potholes',
+ });
+ $child_cat->update({
+ send_method => 'Triage'
+ });
+ $child_cat = FixMyStreet::DB->resultset("Contact")->find({
+ body => $bodies->{2636},
category => 'Private',
});
$child_cat->update({
- non_public => 1
+ non_public => 1,
+ send_method => 'Triage'
});
$child_cat = FixMyStreet::DB->resultset("Contact")->find({
body => $bodies->{2636},
category => 'Extra',
});
+ $child_cat->update({
+ send_method => 'Triage'
+ });
$child_cat->set_extra_fields({
code => 'extra',
datatype => 'string',
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 203296c4d..cebc4ed85 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -236,10 +236,15 @@ sub check_and_stash_category : Private {
$csv->combine(@list_of_names);
$c->{stash}->{list_of_names_as_string} = $csv->string;
+ my $where = { body_id => [ keys %bodies ], };
+
+ my $cobrand_where = $c->cobrand->call_hook('munge_category_where', $where );
+ if ( $cobrand_where ) {
+ $where = $cobrand_where;
+ }
+
my @categories = $c->model('DB::Contact')->not_deleted->search(
- {
- body_id => [ keys %bodies ],
- },
+ $where,
{
columns => [ 'category', 'extra' ],
order_by => [ 'category' ],
@@ -252,6 +257,7 @@ sub check_and_stash_category : Private {
my $categories = [ $c->get_param_list('filter_category', 1) ];
my %valid_categories = map { $_ => 1 } grep { $_ && $categories_mapped{$_} } @$categories;
$c->stash->{filter_category} = \%valid_categories;
+ $c->cobrand->call_hook('munge_filter_category');
}
sub map_features : Private {
@@ -312,6 +318,7 @@ sub ajax : Path('/ajax') {
my %valid_categories = map { $_ => 1 } $c->get_param_list('filter_category', 1);
$c->stash->{filter_category} = \%valid_categories;
+ $c->cobrand->call_hook('munge_filter_category');
$c->forward('map_features', [ { bbox => $c->stash->{bbox} } ]);
$c->forward('/reports/ajax', [ 'around/on_map_list_items.html' ]);
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index e5327b084..377253955 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -7,6 +7,7 @@ use warnings;
use mySociety::Random;
use constant COUNCIL_ID_BROMLEY => 2482;
+use constant COUNCIL_ID_ISLEOFWIGHT => 2636;
sub on_map_default_status { return 'open'; }
@@ -41,9 +42,24 @@ sub munge_category_list {
my ($self, $options, $contacts, $extras) = @_;
# No TfL Traffic Lights category in Hounslow
- my %bodies = map { $_->body->name => 1 } @$contacts;
- return unless $bodies{'Hounslow Borough Council'};
- @$options = grep { ($_->{category} || $_->category) !~ /^Traffic lights$/i } @$options;
+ my %bodies = map { $_->body->name => $_->body } @$contacts;
+ if ( $bodies{'Hounslow Borough Council'} ) {
+ @$options = grep { ($_->{category} || $_->category) !~ /^Traffic lights$/i } @$options;
+ }
+
+ if ( $bodies{'Isle of Wight Council'} ) {
+ my $user = $self->{c}->user;
+ if ( $user && ( $user->is_superuser || $user->belongs_to_body( $bodies{'Isle of Wight Council'}->id ) ) ) {
+ @$contacts = grep { !$_->send_method || $_->send_method ne 'Triage' } @$contacts;
+ my $seen = { map { $_->category => 1 } @$contacts };
+ @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options;
+ return;
+ }
+
+ @$contacts = grep { $_->send_method && $_->send_method eq 'Triage' } @$contacts;
+ my $seen = { map { $_->category => 1 } @$contacts };
+ @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options;
+ }
}
sub title_list {
diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
index f2cd1a687..c8fc75eaa 100644
--- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
+++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
@@ -87,6 +87,7 @@ sub open311_munge_update_params {
$params->{description} = "FMS-Update: " . $params->{description};
}
+# this handles making sure the user sees the right categories on the new report page
sub munge_category_list {
my ($self, $options, $contacts, $extras) = @_;
@@ -95,14 +96,99 @@ sub munge_category_list {
my $b = $bodies{'Isle of Wight Council'};
if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) {
+ @$contacts = grep { !$_->send_method || $_->send_method ne 'Triage' } @$contacts;
+ my $seen = { map { $_->category => 1 } @$contacts };
+ @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options;
return;
}
- @$contacts = grep { $_->send_method eq 'Triage' } @$contacts;
+ @$contacts = grep { $_->send_method && $_->send_method eq 'Triage' } @$contacts;
my $seen = { map { $_->category => 1 } @$contacts };
@$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options;
}
+sub munge_category_where {
+ my ($self, $where) = @_;
+
+ my $user = $self->{c}->user;
+ my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first;
+ if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) {
+ $where = {
+ body_id => $where->{body_id},
+ send_method => [ { '!=' => 'Triage' }, undef ],
+ };
+ return $where;
+ }
+
+ $where->{'send_method'} = 'Triage';
+ return $where;
+}
+
+sub munge_load_and_group_problems {
+ my ($self, $where, $filter) = @_;
+
+ return unless $where->{category};
+
+ my @cat_names = $self->expand_triage_cat_list($where->{category});
+
+ $where->{category} = \@cat_names;
+ my $problems = $self->problems->search($where, $filter);
+ return $problems;
+}
+
+sub munge_filter_category {
+ my $self = shift;
+
+ my $c = $self->{c};
+ return unless $c->stash->{filter_category};
+
+ my @cat_names = $self->expand_triage_cat_list([ keys %{$c->stash->{filter_category}} ]);
+ $c->stash->{filter_category} = { map { $_ => 1 } @cat_names };
+}
+
+# this assumes that each Triage category has the same name as a group
+# and uses this to generate a list of categories that a triage category
+# could be triaged to
+sub expand_triage_cat_list {
+ my ($self, $categories) = @_;
+
+ my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first;
+
+ my $all_cats = $self->{c}->model('DB::Contact')->not_deleted->search(
+ {
+ body_id => $b->id,
+ send_method => [{ '!=', 'Triage'}, undef]
+ }
+ );
+
+ my %group_to_category;
+ while ( my $cat = $all_cats->next ) {
+ next unless $cat->get_extra_metadata('group');
+ $group_to_category{$cat->get_extra_metadata('group')} //= [];
+ push @{ $group_to_category{$cat->get_extra_metadata('group')} }, $cat->category;
+ }
+
+ my $cats = $self->{c}->model('DB::Contact')->not_deleted->search(
+ {
+ body_id => $b->id,
+ category => $categories
+ }
+ );
+
+ my @cat_names;
+ while ( my $cat = $cats->next ) {
+ if ( $cat->send_method eq 'Triage' ) {
+ # include the category itself
+ push @cat_names, $cat->category;
+ push @cat_names, @{ $group_to_category{$cat->category} } if $group_to_category{$cat->category};
+ } else {
+ push @cat_names, $cat->category;
+ }
+ }
+
+ return @cat_names;
+}
+
sub open311_get_update_munging {
my ($self, $comment) = @_;
diff --git a/t/cobrand/isleofwight.t b/t/cobrand/isleofwight.t
index 414b683cd..5700e410b 100644
--- a/t/cobrand/isleofwight.t
+++ b/t/cobrand/isleofwight.t
@@ -47,6 +47,13 @@ my $contact2 = $mech->create_contact_ok(
send_method => 'Triage',
);
+my $admin_user = $mech->create_user_ok('admin-user@example.org', name => 'Admin User', from_body => $isleofwight);
+
+$admin_user->user_body_permissions->create({
+ body => $isleofwight,
+ permission_type => 'triage'
+});
+
my @reports = $mech->create_problems_for_body(1, $isleofwight->id, 'An Isle of wight report', {
confirmed => '2019-05-25 09:00',
lastupdate => '2019-05-25 09:00',
@@ -326,7 +333,7 @@ subtest "sends branded confirmation emails" => sub {
photo1 => '',
name => 'Joe Bloggs',
username => 'test-1@example.com',
- category => 'Potholes',
+ category => 'Roads',
}
},
"submit good details"
@@ -368,8 +375,8 @@ subtest "check category extra uses correct name" => sub {
order => 1,
datatype_description => 'datatype',
} );
- $contact->set_extra_fields( @extras );
- $contact->update;
+ $contact2->set_extra_fields( @extras );
+ $contact2->update;
my $extra_details;
@@ -377,7 +384,7 @@ subtest "check category extra uses correct name" => sub {
MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => ['isleofwight','fixmystreet'],
}, sub {
- $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Potholes&latitude=50.71086&longitude=-1.29573');
+ $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Roads&latitude=50.71086&longitude=-1.29573');
};
like $extra_details->{category_extra}, qr/Island Roads/, 'correct name in category extras';
@@ -424,4 +431,53 @@ subtest "reports are marked for triage upon submission" => sub {
};
};
+for my $cobrand ( 'fixmystreet', 'isleofwight' ) {
+ subtest "only categories for Triage are displayed on " . $cobrand => sub {
+ $mech->log_out_ok;
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ $cobrand ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ my $f = $mech->form_name('mapSkippedForm');
+ ok $f, 'found form';
+ my $cats = $f->find_input('category');
+ ok $cats, 'found category element';
+ my @values = $cats->possible_values;
+ is_deeply \@values, [ '-- Pick a category --', 'Roads' ], 'correct category list';
+ };
+ };
+
+ subtest "staff user can see non Triage categories on " . $cobrand => sub {
+ $mech->log_out_ok;
+ $mech->log_in_ok($admin_user->email);
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ $cobrand ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'PO30 5XJ', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ my $f = $mech->form_name('mapSkippedForm');
+ ok $f, 'found form';
+ my $cats = $f->find_input('category');
+ ok $cats, 'found category element';
+ my @values = $cats->possible_values;
+ is_deeply \@values, [ '-- Pick a category --', 'Potholes' ], 'correct category list';
+ };
+ };
+}
+
done_testing();