aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2017-09-13 09:52:12 +0100
committerStruan Donald <struan@exo.org.uk>2017-09-13 09:52:12 +0100
commita181c520986498ab5a898ad3c21c04affa215378 (patch)
tree9630a7b97fd57081f9175741cdeeeb8046d39d32
parent81744445eedc8686827cfc119b51ae8ec704a963 (diff)
parente2225f14211e061330223b9f752b7924610bc0f9 (diff)
Merge branch 'issues/forcouncils/224-default-priority'
-rw-r--r--CHANGELOG.md1
-rw-r--r--db/downgrade_0055---0054.sql6
-rw-r--r--db/schema.sql1
-rw-r--r--db/schema_0055-add-default-to-reponsepriority.sql5
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/ResponsePriority.pm6
-rw-r--r--t/app/controller/admin.t20
-rw-r--r--t/app/controller/report_inspect.t12
-rw-r--r--templates/web/base/admin/responsepriorities/edit.html12
-rw-r--r--templates/web/base/admin/responsepriorities/list.html2
-rw-r--r--templates/web/base/report/_inspect.html4
12 files changed, 72 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fc68419b..86fd35983 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@
- Clearer highlight for selected duplicate on inspect form. #1798
- Include MapIt API key on admin config page. #1778
- Redirect to same map view after inspection. #1820
+ - A default response priority can now be set #1838
- Bugfixes:
- Set up action scheduled field when report loaded. #1789
- Fix display of thumbnail images on page reload. #1815
diff --git a/db/downgrade_0055---0054.sql b/db/downgrade_0055---0054.sql
new file mode 100644
index 000000000..a38d74ded
--- /dev/null
+++ b/db/downgrade_0055---0054.sql
@@ -0,0 +1,6 @@
+BEGIN;
+
+ALTER TABLE response_priorities DROP COLUMN is_default;
+
+COMMIT;
+
diff --git a/db/schema.sql b/db/schema.sql
index fedab2b9d..f428ff59d 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -144,6 +144,7 @@ CREATE TABLE response_priorities (
name text not null,
description text,
external_id text,
+ is_default boolean not null default 'f',
unique(body_id, name)
);
diff --git a/db/schema_0055-add-default-to-reponsepriority.sql b/db/schema_0055-add-default-to-reponsepriority.sql
new file mode 100644
index 000000000..0f8b72e13
--- /dev/null
+++ b/db/schema_0055-add-default-to-reponsepriority.sql
@@ -0,0 +1,5 @@
+BEGIN;
+
+ALTER TABLE response_priorities ADD is_default boolean not null default 'f';
+
+COMMIT;
diff --git a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
index 7983a6e4d..2613f6ae0 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
@@ -65,6 +65,7 @@ sub edit : Path : Args(2) {
$priority->name( $c->get_param('name') );
$priority->description( $c->get_param('description') );
$priority->external_id( $c->get_param('external_id') );
+ $priority->is_default( $c->get_param('is_default') ? 1 : 0 );
$priority->update_or_insert;
my @live_contact_ids = map { $_->id } @live_contacts;
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 60d373a16..e37e08698 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -320,6 +320,12 @@ sub inspect : Private {
$c->stash->{post_inspect_url} = $c->req->referer;
}
+ if ($c->user->has_body_permission_to('report_edit_priority') or
+ $c->user->has_body_permission_to('report_inspect')
+ ) {
+ $c->stash->{has_default_priority} = scalar( grep { $_->is_default } $problem->response_priorities );
+ }
+
if ( $c->get_param('save') ) {
$c->forward('/auth/check_csrf_token');
diff --git a/perllib/FixMyStreet/DB/Result/ResponsePriority.pm b/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
index 44635d174..df54cfa08 100644
--- a/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
@@ -28,6 +28,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"external_id",
{ data_type => "text", is_nullable => 1 },
+ "is_default",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("response_priorities_body_id_name_key", ["body_id", "name"]);
@@ -51,8 +53,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-12-14 17:12:09
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:glsO0fLK6fNvg4TmW1DMPg
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-09-12 09:32:53
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JBIHFnaLvXCAUjgwTSB3CQ
__PACKAGE__->many_to_many( contacts => 'contact_response_priorities', 'contact' );
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 075ab0fd0..bd0f9e408 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -1470,6 +1470,7 @@ subtest "response priorities can be added" => sub {
name => "Cat 1A",
description => "Fixed within 24 hours",
deleted => undef,
+ is_default => undef,
"contacts[".$oxfordshirecontact->id."]" => 1,
};
$mech->submit_form_ok( { with_fields => $fields } );
@@ -1478,6 +1479,25 @@ subtest "response priorities can be added" => sub {
is $oxfordshirecontact->response_priorities->count, 1, "Response template was added to contact";
};
+subtest "response priorities can set to default" => sub {
+ my $priority_id = $oxfordshire->response_priorities->first->id;
+ is $oxfordshire->response_priorities->count, 1, "Response priority exists";
+ $mech->get_ok( "/admin/responsepriorities/" . $oxfordshire->id . "/$priority_id" );
+
+ my $fields = {
+ name => "Cat 1A",
+ description => "Fixed within 24 hours",
+ deleted => undef,
+ is_default => 1,
+ "contacts[".$oxfordshirecontact->id."]" => 1,
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+
+ is $oxfordshire->response_priorities->count, 1, "Still one response priority";
+ is $oxfordshirecontact->response_priorities->count, 1, "Still one response template";
+ ok $oxfordshire->response_priorities->first->is_default, "Response priority set to default";
+};
+
subtest "response priorities can be listed" => sub {
$mech->get_ok( "/admin/responsepriorities/" . $oxfordshire->id );
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 68f9063cf..5bbbdff79 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -226,6 +226,18 @@ FixMyStreet::override_config {
$user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
};
+ subtest "default response priorities display correctly" => sub {
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('Priority</label', 'report priority list present');
+ 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');
+
+ $rp->update({ is_default => 1});
+ $mech->get_ok("/report/$report_id");
+ unlike $mech->content, qr/<select name="priority" id="problem_priority" class="form-control">[^<]*<option value="" selecte/s, 'blank priority option not selected';
+ $mech->content_contains('value="' . $rp->id . '" selected>High', 'default priority selected');
+ };
+
foreach my $test (
{ type => 'report_edit_priority', priority => 1 },
{ type => 'report_edit_category', category => 1 },
diff --git a/templates/web/base/admin/responsepriorities/edit.html b/templates/web/base/admin/responsepriorities/edit.html
index 07d6906ba..608f19e74 100644
--- a/templates/web/base/admin/responsepriorities/edit.html
+++ b/templates/web/base/admin/responsepriorities/edit.html
@@ -30,6 +30,18 @@
<div class="admin-hint">
<p>
+ [% loc('Select if this is the default priority') %]
+ </p>
+ </div>
+ <p>
+ <label>
+ <input type="checkbox" name="is_default" is="is_deleted" value="1"[% ' checked' IF rp.is_default %]>
+ [% loc('Default priority') %]
+ </label>
+ </p>
+
+ <div class="admin-hint">
+ <p>
[% loc('If you only want this priority to be an option for specific categories, pick them here. By default they will show for all categories.') %]
</p>
</div>
diff --git a/templates/web/base/admin/responsepriorities/list.html b/templates/web/base/admin/responsepriorities/list.html
index 80d4e2cee..eedaccfdb 100644
--- a/templates/web/base/admin/responsepriorities/list.html
+++ b/templates/web/base/admin/responsepriorities/list.html
@@ -6,6 +6,7 @@
<th> [% loc('Name') %] </th>
<th> [% loc('Description') %] </th>
<th> [% loc('Categories') %] </th>
+ <th> [% loc('Default') %] </th>
<th> &nbsp; </th>
</tr>
</thead>
@@ -23,6 +24,7 @@
[% END %]
[% END %]
</td>
+ <td> [% IF p.is_default %]X[% END %]</td>
<td> <a href="[% c.uri_for('', body.id, p.id) %]" class="btn">[% loc('Edit') %]</a> </td>
</tr>
[% END %]
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index 561be30d1..436c89e4a 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -122,9 +122,9 @@
<p>
<label for="problem_priority">[% loc('Priority') %]</label>
<select name="priority" id="problem_priority" class="form-control">
- <option value="" [% 'selected' UNLESS problem.response_priority_id %]>-</option>
+ <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 %] [% 'disabled' IF priority.deleted %]>[% priority.name | html %]</option>
+ <option value="[% priority.id %]" [% 'selected' IF ( problem.response_priority_id == priority.id ) OR priority.is_default %][% 'disabled' IF priority.deleted %]>[% priority.name | html %]</option>
[% END %]
</select>
</p>