diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 61 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Angus.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EastSussex.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Greenwich.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Harrogate.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Stevenage.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 58 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 4 |
15 files changed, 164 insertions, 44 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index b8f038ce3..f8ea84d08 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -195,6 +195,7 @@ sub display_location : Private { colour => $colour, id => $p->id, title => $p->title_safe, + problem => $p, } } @$on_map_all, @$around_map; } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index c4a2162a8..e81dc719f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -143,22 +143,11 @@ sub report_new_ajax : Path('mobile') : Args(0) { $c->forward('save_user_and_report'); my $report = $c->stash->{report}; - my $data = $c->stash->{token_data} || {}; - my $token = $c->model("DB::Token")->create( { - scope => 'problem', - data => { - %$data, - id => $report->id - } - } ); if ( $report->confirmed ) { $c->forward( 'create_reporter_alert' ); $c->stash->{ json_response } = { success => 1, report => $report->id }; } else { - $c->stash->{token_url} = $c->uri_for_email( '/P', $token->token ); - $c->send_email( 'problem-confirm.txt', { - to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ], - } ); + $c->forward( 'send_problem_confirm_email' ); $c->stash->{ json_response } = { success => 1 }; } @@ -1021,6 +1010,31 @@ sub tokenize_user : Private { if $c->get_param('oauth_need_email') && $c->session->{oauth}{twitter_id}; } +sub send_problem_confirm_email : Private { + my ( $self, $c ) = @_; + my $data = $c->stash->{token_data} || {}; + my $report = $c->stash->{report}; + my $token = $c->model("DB::Token")->create( { + scope => 'problem', + data => { + %$data, + id => $report->id + } + } ); + + my $template = 'problem-confirm.txt'; + $template = 'problem-confirm-not-sending.txt' unless $report->bodies_str; + + $c->stash->{token_url} = $c->uri_for_email( '/P', $token->token ); + if ($c->cobrand->can('problem_confirm_email_extras')) { + $c->cobrand->problem_confirm_email_extras($report); + } + + $c->send_email( $template, { + to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ], + } ); +} + =head2 save_user_and_report Save the user and the report. @@ -1178,30 +1192,13 @@ sub redirect_or_confirm_creation : Private { return 1; } - my $template = 'problem-confirm.txt'; - $template = 'problem-confirm-not-sending.txt' unless $report->bodies_str; - - # otherwise create a confirm token and email it to them. - my $data = $c->stash->{token_data} || {}; - my $token = $c->model("DB::Token")->create( { - scope => 'problem', - data => { - %$data, - id => $report->id - } - } ); - $c->stash->{token_url} = $c->uri_for_email( '/P', $token->token ); - if ($c->cobrand->can('problem_confirm_email_extras')) { - $c->cobrand->problem_confirm_email_extras($report); - } - $c->send_email( $template, { - to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ], - } ); + # otherwise email a confirm token to them. + $c->forward( 'send_problem_confirm_email' ); # tell user that they've been sent an email $c->stash->{template} = 'email_sent.html'; $c->stash->{email_type} = 'problem'; - $c->log->info($report->user->id . ' created ' . $report->id . ', email sent, ' . ($data->{password} ? 'password set' : 'password not set')); + $c->log->info($report->user->id . ' created ' . $report->id . ', email sent, ' . ($c->stash->{token_data}->{password} ? 'password set' : 'password not set')); } sub create_reporter_alert : Private { diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 38f344250..da017c57f 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -32,7 +32,7 @@ sub confirm_problem : Path('/P') { $c->stash->{report} = { id => 123, title => 'Title of Report', - bodies_str => 'True', + bodies_str => '1', url => '/report/123', service => $c->get_param('service'), }; @@ -195,7 +195,7 @@ sub confirm_update : Path('/C') { $c->stash->{problem} = { id => 123, title => 'Title of Report', - bodies_str => 'True', + bodies_str => '1', url => '/report/123', }; return; diff --git a/perllib/FixMyStreet/Cobrand/Angus.pm b/perllib/FixMyStreet/Cobrand/Angus.pm index 23d0d2c58..0361c2d11 100644 --- a/perllib/FixMyStreet/Cobrand/Angus.pm +++ b/perllib/FixMyStreet/Cobrand/Angus.pm @@ -10,7 +10,8 @@ sub council_name { return 'Angus Council'; } sub council_url { return 'angus'; } sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'https://fix.angus.gov.uk'; } diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index c9f9a98be..2d0cb86f1 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -10,7 +10,8 @@ sub council_name { return 'Bromley Council'; } sub council_url { return 'bromley'; } sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'https://fix.bromley.gov.uk'; } diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 65c97f38b..36313cf63 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -74,6 +74,18 @@ sub problems { return $self->problems_restriction($self->{c}->model('DB::Problem')); } +=head1 problems_on_map + +Returns a ResultSet of Problems to be shown on the /around map, potentially +restricted to a subset if we're on a cobrand that only wants some of the data. + +=cut + +sub problems_on_map { + my $self = shift; + return $self->problems_on_map_restriction($self->{c}->model('DB::Problem')); +} + =head1 updates Returns a ResultSet of Comments, potentially restricted to a subset if we're on @@ -115,6 +127,19 @@ sub categories_restriction { return $rs; } + +=head1 problems_on_map_restriction + +Used to restricts reports shown on the /around map in a cobrand in a particular way. Do +nothing by default. + +=cut + +sub problems_on_map_restriction { + my ($self, $rs) = @_; + return $rs; +} + sub site_key { return 0; } =head2 restriction diff --git a/perllib/FixMyStreet/Cobrand/EastSussex.pm b/perllib/FixMyStreet/Cobrand/EastSussex.pm index 2ba3a4f70..80a86706a 100644 --- a/perllib/FixMyStreet/Cobrand/EastSussex.pm +++ b/perllib/FixMyStreet/Cobrand/EastSussex.pm @@ -113,6 +113,8 @@ sub reports_per_page { return 20; } sub pin_colour { my ( $self, $p, $context ) = @_; + return 'grey' unless $self->owns_problem( $p ); + # TODO refactor to a Moo(se)? lazy attribute my $open_states = $self->{open_states} ||= $p->open_states; diff --git a/perllib/FixMyStreet/Cobrand/Greenwich.pm b/perllib/FixMyStreet/Cobrand/Greenwich.pm index d23e62138..7777079a9 100644 --- a/perllib/FixMyStreet/Cobrand/Greenwich.pm +++ b/perllib/FixMyStreet/Cobrand/Greenwich.pm @@ -10,7 +10,8 @@ sub council_name { return 'Royal Borough of Greenwich'; } sub council_url { return 'greenwich'; } sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'https://fix.royalgreenwich.gov.uk'; } diff --git a/perllib/FixMyStreet/Cobrand/Harrogate.pm b/perllib/FixMyStreet/Cobrand/Harrogate.pm index 519521867..8f4a6e2ea 100644 --- a/perllib/FixMyStreet/Cobrand/Harrogate.pm +++ b/perllib/FixMyStreet/Cobrand/Harrogate.pm @@ -12,7 +12,8 @@ sub council_url { return 'harrogate'; } sub is_two_tier { return 1; } # with North Yorkshire CC 2235 sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'http://fix.harrogate.gov.uk'; } diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 39fe95405..d127f5e13 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -11,7 +11,8 @@ sub council_url { return 'oxfordshire'; } sub is_two_tier { return 1; } sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'https://fixmystreet.oxfordshire.gov.uk'; } @@ -97,6 +98,7 @@ sub reports_ordering { sub pin_colour { my ( $self, $p, $context ) = @_; + return 'grey' unless $self->owns_problem( $p ); return 'grey' if $p->state eq 'not responsible'; return 'green' if $p->is_fixed || $p->is_closed; return 'red' if $p->state eq 'confirmed'; diff --git a/perllib/FixMyStreet/Cobrand/Stevenage.pm b/perllib/FixMyStreet/Cobrand/Stevenage.pm index 1f90e0498..2c305d326 100644 --- a/perllib/FixMyStreet/Cobrand/Stevenage.pm +++ b/perllib/FixMyStreet/Cobrand/Stevenage.pm @@ -11,7 +11,8 @@ sub council_url { return 'stevenage'; } sub is_two_tier { return 1; } sub base_url { - return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE'); return 'http://fixmystreet.stevenage.gov.uk'; } diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 0eff48b00..e60b673b4 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -336,5 +336,61 @@ sub report_check_for_errors { return %errors; } -1; +=head2 get_body_handler_for_problem + +Returns a cobrand for the body that a problem was logged against. + + my $handler = $cobrand->get_body_handler_for_problem($row); + my $handler = $cobrand_class->get_body_handler_for_problem($row); + +If the UK council in bodies_str has a FMS.com cobrand then an instance of that +cobrand class is returned, otherwise the default FixMyStreet cobrand is used. + +=cut + +sub get_body_handler_for_problem { + my ($self, $row) = @_; + + my @bodies = values %{$row->bodies}; + my %areas = map { %{$_->areas} } @bodies; + + foreach my $avail ( FixMyStreet::Cobrand->available_cobrand_classes ) { + my $class = FixMyStreet::Cobrand->get_class_for_moniker($avail->{moniker}); + my $cobrand = $class->new({}); + next unless $cobrand->can('council_id'); + return $cobrand if $areas{$cobrand->council_id}; + } + return ref $self ? $self : $self->new; +} + +=head2 link_to_council_cobrand + +If a problem was sent to a UK council who has a FMS cobrand and the report is +currently being viewed on a different cobrand, then link the council's name to +that problem on the council's cobrand. + +=cut + +sub link_to_council_cobrand { + my ( $self, $problem ) = @_; + # If the report was sent to a cobrand that we're not currently on, + # include a link to view it on the responsible cobrand. + # This only occurs if the report was sent to a single body and we're not already + # using the body name as a link to all problem reports. + my $handler = $self->get_body_handler_for_problem($problem); + $self->{c}->log->debug( sprintf "bodies: %s areas: %s self: %s handler: %s", $problem->bodies_str, $problem->areas, $self->moniker, $handler->moniker ); + my $bodies_str_ids = $problem->bodies_str_ids; + if ( !mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS') && + scalar(@$bodies_str_ids) == 1 && $handler->is_council && + $handler->moniker ne $self->{c}->cobrand->moniker + ) { + my $url = sprintf("%s%s", $handler->base_url, $problem->url); + return sprintf("<a href='%s'>%s</a>", $url, $problem->body( $self->{c} )); + } else { + return $problem->body( $self->{c} ); + } +} + + +1; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 6bf70e091..6e98f4ae0 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -129,6 +129,13 @@ sub owns_problem { return $areas{$self->council_id} ? 1 : undef; } +# If the council is two-tier then show pins for the other council as grey +sub pin_colour { + my ( $self, $p, $context ) = @_; + return 'grey' if $self->is_two_tier && !$self->owns_problem( $p ); + return $self->next::method($p, $context); +} + # If we ever link to a county problem report, needs to be to main FixMyStreet sub base_url_for_report { my ( $self, $report ) = @_; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index a2167032a..bc72cf9da 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -658,7 +658,12 @@ sub can_display_external_id { sub duration_string { my ( $problem, $c ) = @_; - my $body = $problem->body( $c ); + my $body; + if ( $c->cobrand->can('link_to_council_cobrand') ) { + $body = $c->cobrand->link_to_council_cobrand($problem); + } else { + $body = $problem->body( $c ); + } return sprintf(_('Sent to %s %s later'), $body, Utils::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute') ); @@ -868,4 +873,24 @@ sub get_time_spent { return $admin_logs ? $admin_logs->get_column('sum_time_spent') : 0; } +=head2 get_cobrand_logged + +Get a cobrand object for the cobrand the problem was logged for. + +e.g. if a problem was logged at www.fixmystreet.com, this will be a +FixMyStreet::Cobrand::FixMyStreet object. + +=cut + +has get_cobrand_logged => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $cobrand_class = FixMyStreet::Cobrand->get_class_for_moniker( $self->cobrand ); + return $cobrand_class->new; + }, +); + + 1; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 6d641331f..b8b128611 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -100,9 +100,9 @@ sub _map_features { my $around_limit = $c->cobrand->on_map_list_limit || undef; my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval ); - my $around_map = $c->cobrand->problems->around_map( @around_args, undef, $category, $states ); + my $around_map = $c->cobrand->problems_on_map->around_map( @around_args, undef, $category, $states ); my $around_map_list = $around_limit - ? $c->cobrand->problems->around_map( @around_args, $around_limit, $category, $states ) + ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $category, $states ) : $around_map; my $dist = FixMyStreet::Gaze::get_radius_containing_population( $lat, $lon ); |