diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm | 46 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ResponseTemplate.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 23 |
5 files changed, 97 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index 58d8e58de..ea9b656aa 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -55,10 +55,16 @@ __PACKAGE__->belongs_to( { id => "body_id" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, ); +__PACKAGE__->has_many( + "contact_response_templates", + "FixMyStreet::DB::Result::ContactResponseTemplate", + { "foreign.contact_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hq/BFHDEu4OUI4MSy3OyHg +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CXUabm3Yd11OoIYJceSPag __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); @@ -68,6 +74,8 @@ use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Extra'; +__PACKAGE__->many_to_many( response_templates => 'contact_response_templates', 'response_template' ); + sub get_metadata_for_input { my $self = shift; my $id_field = $self->id_field; diff --git a/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm new file mode 100644 index 000000000..3c777533c --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm @@ -0,0 +1,46 @@ +use utf8; +package FixMyStreet::DB::Result::ContactResponseTemplate; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); +__PACKAGE__->table("contact_response_templates"); +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "contact_response_templates_id_seq", + }, + "contact_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "response_template_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, +); +__PACKAGE__->set_primary_key("id"); +__PACKAGE__->belongs_to( + "contact", + "FixMyStreet::DB::Result::Contact", + { id => "contact_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); +__PACKAGE__->belongs_to( + "response_template", + "FixMyStreet::DB::Result::ResponseTemplate", + { id => "response_template_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d6niNsxi2AsijhvJSuQeKw + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 308fba71f..8236524d6 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -678,6 +678,13 @@ sub duration_string { } else { $body = $problem->body( $c ); } + if ( $c->cobrand->can('get_body_handler_for_problem') ) { + my $handler = $c->cobrand->get_body_handler_for_problem( $problem ); + if ( $handler->can('is_council_with_case_management') && $handler->is_council_with_case_management ) { + return sprintf(_('Received by %s moments later'), $body); + } + } + return unless $problem->whensent; return sprintf(_('Sent to %s %s later'), $body, Utils::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute') ); diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm index d189bf3ec..0d4377dba 100644 --- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm +++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm @@ -31,6 +31,8 @@ __PACKAGE__->add_columns( is_nullable => 0, original => { default_value => \"now()" }, }, + "auto_response", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("response_templates_body_id_title_key", ["body_id", "title"]); @@ -40,11 +42,18 @@ __PACKAGE__->belongs_to( { id => "body_id" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, ); +__PACKAGE__->has_many( + "contact_response_templates", + "FixMyStreet::DB::Result::ContactResponseTemplate", + { "foreign.response_template_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ECFQLMxOFGwv7cwfHLlszw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KRm0RHbtrzuxzH0S/UAsdw +__PACKAGE__->many_to_many( contacts => 'contact_response_templates', 'contact' ); # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 697cfedf6..6444cfe6a 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -254,6 +254,29 @@ sub has_permission_to { return $permission ? 1 : undef; } +=head2 has_body_permission_to + +Checks if the User has a from_body set, and the specified permission on that body. + +Instead of saying: + + ($user->from_body && $user->has_permission_to('user_edit', $user->from_body->id)) + +You can just say: + + $user->has_body_permission_to('user_edit') + +NB unlike has_permission_to, this doesn't blindly return 1 if the user is a superuser. + +=cut + +sub has_body_permission_to { + my ($self, $permission_type) = @_; + return unless $self->from_body; + + return $self->has_permission_to($permission_type, $self->from_body->id); +} + sub contributing_as { my ($self, $other, $c, $bodies) = @_; $bodies = join(',', keys %$bodies) if ref $bodies eq 'HASH'; |