From e81d5b686a44e7a07db276cccc718c4e28a28a1c Mon Sep 17 00:00:00 2001 From: pezholio Date: Wed, 11 Jan 2017 14:17:34 +0000 Subject: Show user details for users with correct permissions --- perllib/FixMyStreet/DB/Result/Problem.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 203e72fae..92c5c160a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -606,20 +606,28 @@ sub meta_line { $meta = sprintf( _('Reported anonymously at %s'), $date_time ); } } else { + my $problem_name = $problem->name; + + if ($c->user_exists and + $c->user->has_permission_to('view_body_contribute_details', $problem->bodies_str_ids) and + $problem->name ne $problem->user->name) { + $problem_name = sprintf( _('%s (%s)'), $problem->name, $problem->user->name ); + } + if ( $problem->service and $category && $category ne _('Other') ) { $meta = sprintf( _('Reported via %s in the %s category by %s at %s'), $problem->service, $category, - $problem->name, $date_time + $problem_name, $date_time ); } elsif ( $problem->service ) { $meta = sprintf( _('Reported via %s by %s at %s'), - $problem->service, $problem->name, $date_time ); + $problem->service, $problem_name, $date_time ); } elsif ( $category and $category ne _('Other') ) { $meta = sprintf( _('Reported in the %s category by %s at %s'), - $category, $problem->name, $date_time ); + $category, $problem_name, $date_time ); } else { - $meta = sprintf( _('Reported by %s at %s'), $problem->name, $date_time ); + $meta = sprintf( _('Reported by %s at %s'), $problem_name, $date_time ); } } -- cgit v1.2.3 From 24fcbfb3705060845d16b6fbe4c3da1e5e12eea2 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 21 Jan 2017 11:54:16 +0000 Subject: No need to translate this string at present. --- perllib/FixMyStreet/DB/Result/Problem.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 92c5c160a..e42e7110a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -611,7 +611,7 @@ sub meta_line { if ($c->user_exists and $c->user->has_permission_to('view_body_contribute_details', $problem->bodies_str_ids) and $problem->name ne $problem->user->name) { - $problem_name = sprintf( _('%s (%s)'), $problem->name, $problem->user->name ); + $problem_name = sprintf('%s (%s)', $problem->name, $problem->user->name ); } if ( $problem->service and $category && $category ne _('Other') ) { -- cgit v1.2.3 From 804506834e0ef7c1d6d9ab21dece21a18651295f Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 1 Feb 2017 12:50:22 +0000 Subject: [Oxfordshire] Allow cobrand-specific traffic management options Fixes mysociety/fixmystreetforcouncils#159 --- perllib/FixMyStreet/DB/Result/Problem.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index e42e7110a..0092dd8b5 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -1056,4 +1056,17 @@ has duplicates => ( }, ); +has traffic_management_options => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $cobrand = $self->get_cobrand_logged; + if ( $cobrand->can('get_body_handler_for_problem') ) { + $cobrand = $cobrand->get_body_handler_for_problem( $self ); + } + return $cobrand->traffic_management_options; + }, +); + 1; -- cgit v1.2.3 From b14319e75b61ce1ee21ebb7d6fa924ebe18ceee9 Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 17 Jan 2017 16:44:50 +0000 Subject: Add Problem->time_ago for pretty-printed duration --- perllib/FixMyStreet/DB/Result/Problem.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0092dd8b5..d0a5a3a4f 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -659,6 +659,20 @@ sub body { return $body; } + +=head2 time_ago + Returns how long ago a problem was reported in an appropriately + prettified duration, depending on the duration. +=cut + +sub time_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $duration = time() - $self->$date->epoch; + + return Utils::prettify_duration( $duration ); +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical -- cgit v1.2.3 From 3010d13823de9833700b18bf4ac3e71437d9001f Mon Sep 17 00:00:00 2001 From: pezholio Date: Wed, 18 Jan 2017 14:44:04 +0000 Subject: Add Problem->tokenised_url for logging user in This method creates a token that logs the reporting user in, optionally with some parameters which are stored with the token for use when redirecting after login. --- perllib/FixMyStreet/DB/Result/Problem.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index d0a5a3a4f..97cb28fe8 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -182,6 +182,8 @@ use Utils; use FixMyStreet::Map::FMS; use LWP::Simple qw($ua); use RABX; +use URI; +use URI::QueryParam; my $IM = eval { require Image::Magick; @@ -511,6 +513,30 @@ sub admin_url { return $cobrand->admin_base_url . '/report_edit/' . $self->id; } +=head2 tokenised_url + +Return a url for this problem report that logs a user in + +=cut + +sub tokenised_url { + my ($self, $user, $params) = @_; + + my $token = FixMyStreet::App->model('DB::Token')->create( + { + scope => 'email_sign_in', + data => { + id => $self->id, + email => $user->email, + r => $self->url, + p => $params, + } + } + ); + + return "/M/". $token->token; +} + =head2 is_open Returns 1 if the problem is in a open state otherwise 0. -- cgit v1.2.3 From 34795d026faf45b0a1bfc103362eb118766c46d7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 22 Sep 2016 16:12:40 +0100 Subject: Add cobrand call_hook fn, calls a fn if defined. --- perllib/FixMyStreet/DB/Result/Problem.pm | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 97cb28fe8..f469c4275 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -613,9 +613,7 @@ sub meta_line { my $meta = ''; my $category = $problem->category; - if ($c->cobrand->can('change_category_text')) { - $category = $c->cobrand->change_category_text($category); - } + $category = $c->cobrand->call_hook(change_category_text => $category) || $category; if ( $problem->anonymous ) { if ( $problem->service and $category && $category ne _('Other') ) { @@ -748,17 +746,10 @@ sub can_display_external_id { sub duration_string { my ( $problem, $c ) = @_; - my $body; - if ( $c->cobrand->can('link_to_council_cobrand') ) { - $body = $c->cobrand->link_to_council_cobrand($problem); - } 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); - } + my $body = $c->cobrand->call_hook(link_to_council_cobrand => $problem) || $problem->body($c); + my $handler = $c->cobrand->call_hook(get_body_handler_for_problem => $problem); + if ( $handler && $handler->call_hook('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, -- cgit v1.2.3 From 4d44ea5530a7dc25122e5135c19d89b4cebc5f40 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 7 Dec 2016 11:39:59 +0000 Subject: [Oxfordshire] Add Exor RDI file download feature The RDI file format encapsulates information about inspections that have taken place, and can be uploaded into Exor to create defects in bulk. This commit adds a page to the Oxfordshire cobrand's admin allowing RDI files to be generated and downloaded from FMS. For mysociety/fixmystreetforcouncils#127 --- perllib/FixMyStreet/DB/Result/Problem.pm | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index f469c4275..d78eda78f 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -1100,4 +1100,13 @@ has traffic_management_options => ( }, ); +has inspection_log_entry => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + return $self->admin_log_entries->search({ action => 'inspected' }, { order_by => { -desc => 'whenedited' } })->first; + }, +); + 1; -- cgit v1.2.3 From 587a125c46f229ed23aaf68d3308f6755e2d8299 Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 24 Jan 2017 16:20:48 +0000 Subject: [Oxfordshire] Use 'days ago' format on problem lists Fixes mysociety/fixmystreetforcouncils#98 --- perllib/FixMyStreet/DB/Result/Problem.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index d78eda78f..4ccad3690 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -697,6 +697,20 @@ sub time_ago { return Utils::prettify_duration( $duration ); } +=head2 days_ago + + Returns how many days ago a problem was reported. + +=cut + +sub days_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $now = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ); + my $duration = $now->delta_days($self->$date); + return $duration->delta_days; +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical -- cgit v1.2.3 From 8b43050c549bc3bb233bab2b7bd5652dfbb39a12 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 22 Sep 2016 19:24:10 +0100 Subject: Refactor SendReport::Open311 to use cobrand hooks. Avoid doing cobrand-specific logic within SendReport::Open311. The hooks defined are: open311_config: set extra fields open311_pre_send: set endpoints and munge data These are tested in the new t/app/sendreport/open311.t, which does not send any actual reports, but just checks that all the data is munged into the expected format. (tests under t/open311* should already test the actual sending) Remove unused Open311 special cases. --- perllib/FixMyStreet/DB/Result/Problem.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 4ccad3690..dcd5ecc71 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -1107,9 +1107,7 @@ has traffic_management_options => ( default => sub { my $self = shift; my $cobrand = $self->get_cobrand_logged; - if ( $cobrand->can('get_body_handler_for_problem') ) { - $cobrand = $cobrand->get_body_handler_for_problem( $self ); - } + $cobrand = $cobrand->call_hook(get_body_handler_for_problem => $self) || $cobrand; return $cobrand->traffic_management_options; }, ); -- cgit v1.2.3 From a91d9562c6c0ec836f10290df779e2012f18ddec Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Mar 2017 17:58:31 +0000 Subject: Add is_in_progress Problem helper. --- perllib/FixMyStreet/DB/Result/Problem.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index dcd5ecc71..0ab52628e 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -549,6 +549,16 @@ sub is_open { return exists $self->open_states->{ $self->state } ? 1 : 0; } +=head2 is_in_progress + +Sees if the problem is in an open, not 'confirmed' state. + +=cut + +sub is_in_progress { + my $self = shift; + return $self->is_open && $self->state ne 'confirmed' ? 1 : 0; +} =head2 is_fixed -- cgit v1.2.3 From 3f21a9742d89c3e4fda47a0be6ec2a17f802c99a Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Mon, 13 Feb 2017 15:13:12 +0000 Subject: Add customisable defect types. Problems can have an associated defect type, that can be assigned during an inspection. Include an admin interface for managing these types, that can also be assigned on a per-category basis, currently available to the Oxfordshire cobrand. (Also include 'TM' in traffic management Exor RDI output.) --- perllib/FixMyStreet/DB/Result/Problem.pm | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0ab52628e..84db41490 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -108,6 +108,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "response_priority_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "defect_type_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -116,6 +118,17 @@ __PACKAGE__->has_many( { "foreign.problem_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->belongs_to( + "defect_type", + "FixMyStreet::DB::Result::DefectType", + { id => "defect_type_id" }, + { + is_deferrable => 0, + join_type => "LEFT", + on_delete => "NO ACTION", + on_update => "NO ACTION", + }, +); __PACKAGE__->has_many( "moderation_original_datas", "FixMyStreet::DB::Result::ModerationOriginalData", @@ -153,8 +166,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-09-07 11:01:40 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iH9c4VZZN/ONnhN6g89DFw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8zzWlJX7OQOdvrGxKuZUmg # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -754,6 +767,18 @@ sub response_priorities { return $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category); } +=head2 defect_types + +Returns all DefectTypes attached to this problem's category/contact, in +alphabetical order of name. + +=cut + +sub defect_types { + my $self = shift; + return $self->result_source->schema->resultset('DefectType')->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 # (by way of an example, the Oxfordshire send method returns a useful reference when # it succeeds, so that is the ref we should show on the problem report page). -- cgit v1.2.3