aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-12-15 17:25:05 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-12-15 17:25:05 +0000
commit2fd63afc46db7a3a33e608bf1f4b5c0b52c18728 (patch)
treeff9ed0f73cf0979acacb9f03fffeb62623be475a /perllib/FixMyStreet/DB
parentb8aa0d6da9009dc3182093165df9b1a4c6d7d164 (diff)
parent6375eb5d31aa250f5d990d6d6420dd04cf25e3bf (diff)
Merge branch 'issues/forcouncils/108-pick-up-a-priority'
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm22
3 files changed, 24 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index ec1534fe9..203e72fae 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -681,16 +681,7 @@ alphabetical order of name.
sub response_priorities {
my $self = shift;
- return $self->result_source->schema->resultset('ResponsePriority')->search(
- {
- 'me.body_id' => $self->bodies_str_ids,
- 'contact.category' => [ $self->category, undef ],
- },
- {
- order_by => 'name',
- join => { 'contact_response_priorities' => 'contact' },
- }
- );
+ return $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category);
}
# returns true if the external id is the council's ref, i.e., useful to publish it
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 028394795..f4e5144f8 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -268,7 +268,7 @@ sub has_permission_to {
my ($self, $permission_type, $body_ids) = @_;
return 1 if $self->is_superuser;
- return 0 unless $body_ids;
+ return 0 if !$body_ids || (ref $body_ids && !@$body_ids);
my $permission = $self->user_body_permissions->find({
permission_type => $permission_type,
diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm
new file mode 100644
index 000000000..aa9c426f4
--- /dev/null
+++ b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm
@@ -0,0 +1,22 @@
+package FixMyStreet::DB::ResultSet::ResponsePriority;
+use base 'DBIx::Class::ResultSet';
+
+use strict;
+use warnings;
+
+sub for_bodies {
+ my ($rs, $bodies, $category) = @_;
+ my $attrs = {
+ 'me.body_id' => $bodies,
+ };
+ if ($category) {
+ $attrs->{'contact.category'} = [ $category, undef ];
+ }
+ $rs->search($attrs, {
+ order_by => 'name',
+ join => { 'contact_response_priorities' => 'contact' },
+ distinct => 1,
+ });
+}
+
+1;