aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm8
-rwxr-xr-xperllib/FixMyStreet/App/Controller/JS.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm35
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm18
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm70
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyBarangay.pm12
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/Oxfordshire.pm55
-rw-r--r--perllib/FixMyStreet/Cobrand/SeeSomething.pm148
-rw-r--r--perllib/FixMyStreet/Cobrand/Stevenage.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm16
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm9
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm113
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm5
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm52
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm3
-rw-r--r--perllib/FixMyStreet/EmailSend.pm5
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm46
-rw-r--r--perllib/Open311.pm54
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm60
-rw-r--r--perllib/Open311/PopulateServiceList.pm2
30 files changed, 678 insertions, 107 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index f253575c8..b76f4d3ba 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -283,9 +283,8 @@ sub send_email {
my $template = shift;
my $extra_stash_values = shift || {};
- my $sender = $c->cobrand->contact_email;
+ my $sender = $c->config->{DO_NOT_REPLY_EMAIL};
my $sender_name = $c->cobrand->contact_name;
- $sender =~ s/team/fms-DO-NOT-REPLY/;
# create the vars to pass to the email template
my $vars = {
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 17bc3ca76..a3a241590 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -29,9 +29,11 @@ sub begin : Private {
$c->uri_disposition('relative');
- if ($c->cobrand->moniker eq 'zurich') {
+ if ( $c->cobrand->moniker eq 'zurich' || $c->cobrand->moniker eq 'seesomething' ) {
$c->detach( '/auth/redirect' ) unless $c->user_exists;
$c->detach( '/auth/redirect' ) unless $c->user->from_body;
+ }
+ if ( $c->cobrand->moniker eq 'zurich' ) {
$c->cobrand->admin_type();
}
}
@@ -75,11 +77,9 @@ sub index : Path : Args(0) {
%prob_counts =
map { $_ => $prob_counts{$_} || 0 }
- ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council',
- 'fixed - user', 'fixed', 'unconfirmed', 'hidden',
- 'partial', 'planned');
+ ( FixMyStreet::DB::Result::Problem->all_states() );
$c->stash->{problems} = \%prob_counts;
- $c->stash->{total_problems_live} += $prob_counts{$_}
+ $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0
for ( FixMyStreet::DB::Result::Problem->visible_states() );
$c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
@@ -399,12 +399,13 @@ sub update_contacts : Private {
sub body_params : Private {
my ( $self, $c ) = @_;
- my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved parent/;
+ my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts send_extended_statuses comment_user_id can_be_devolved parent/;
my %defaults = map { $_ => '' } @fields;
%defaults = ( %defaults,
send_comments => 0,
suppress_alerts => 0,
comment_user_id => undef,
+ send_extended_statuses => 0,
can_be_devolved => 0,
parent => undef,
);
@@ -981,6 +982,10 @@ sub stats : Path('stats') : Args(0) {
$c->forward('fetch_all_bodies');
+ if ( $c->cobrand->moniker eq 'seesomething' ) {
+ return $c->cobrand->admin_stats();
+ }
+
if ( $c->req->param('getcounts') ) {
my ( $start_date, $end_date, @errors );
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index 926a3f2a5..04360301e 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -113,6 +113,9 @@ sub validate : Private {
or $c->req->param('update_id')
&& $c->req->param('update_id') !~ /^[1-9]\d*$/;
+ push @errors, _('There was a problem showing this page. Please try again later.')
+ if $c->req->params->{message} && $c->req->params->{message} =~ /\[url=/;
+
unshift @errors,
_('There were problems with your report. Please see below.')
if scalar keys %field_errors;
@@ -184,7 +187,7 @@ generally required to stash
sub setup_request : Private {
my ( $self, $c ) = @_;
- $c->stash->{contact_email} = $c->cobrand->contact_email( 'contact' );
+ $c->stash->{contact_email} = $c->cobrand->contact_email;
$c->stash->{contact_email} =~ s/\@/@/;
for my $param (qw/em subject message/) {
@@ -206,7 +209,7 @@ Sends the email
sub send_email : Private {
my ( $self, $c ) = @_;
- my $recipient = $c->cobrand->contact_email( 'contact' );
+ my $recipient = $c->cobrand->contact_email;
my $recipient_name = $c->cobrand->contact_name();
$c->stash->{host} = $c->req->header('HOST');
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index 657751e5c..028b9aadd 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -141,6 +141,8 @@ sub index : Path : Args(0) {
$prob_where->{state} = [ FixMyStreet::DB::Result::Problem->fixed_states() ];
} elsif ( $c->stash->{q_state} ) {
$prob_where->{state} = $c->stash->{q_state};
+ $prob_where->{state} = { IN => [ 'planned', 'action scheduled' ] }
+ if $prob_where->{state} eq 'action scheduled';
}
my $params = {
%$prob_where,
@@ -184,11 +186,13 @@ sub updates_search : Private {
map { $_ => $counts{$_} || 0 }
('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council',
'fixed - user', 'fixed', 'unconfirmed', 'hidden',
- 'partial', 'planned');
+ 'partial', 'action scheduled', 'planned');
+
+ $counts{'action scheduled'} += $counts{planned} || 0;
for my $vars (
[ 'time_to_fix', 'fixed - council' ],
- [ 'time_to_mark', 'in progress', 'planned', 'investigating', 'closed' ],
+ [ 'time_to_mark', 'in progress', 'action scheduled', 'investigating', 'closed' ],
) {
my $col = shift @$vars;
my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and problem_state in ('"
diff --git a/perllib/FixMyStreet/App/Controller/JS.pm b/perllib/FixMyStreet/App/Controller/JS.pm
index 1ced9d43b..483c3c2cc 100755
--- a/perllib/FixMyStreet/App/Controller/JS.pm
+++ b/perllib/FixMyStreet/App/Controller/JS.pm
@@ -24,6 +24,8 @@ sub translation_strings : LocalRegex('^translation_strings\.(.*?)\.js$') : Args(
$c->res->content_type( 'application/javascript' );
}
+sub validation_rules : Path('validation_rules.js') : Args(0) { }
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index 3a6794325..7b8cb649f 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -100,7 +100,7 @@ sub error : Private {
sub get_discovery : Private {
my ( $self, $c ) = @_;
- my $contact_email = $c->config->{CONTACT_EMAIL};
+ my $contact_email = $c->cobrand->contact_email;
my $prod_url = 'http://www.fiksgatami.no/open311';
my $test_url = 'http://fiksgatami-dev.nuug.no/open311';
my $prod_changeset = '2011-04-08T00:00:00Z';
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 39d750562..460ccaec5 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -114,7 +114,7 @@ sub load_problem_or_display_error : Private {
if ( !$c->user || $c->user->id != $problem->user->id ) {
$c->detach(
'/page_error_403_access_denied',
- [ _('That report cannot be viewed on FixMyStreet.') ] #
+ [ sprintf(_('That report cannot be viewed on %s.'), $c->cobrand->site_title) ] #
);
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 0ba8c5f71..687e54fbe 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -194,6 +194,7 @@ sub report_form_ajax : Path('ajax') : Args(0) {
councils_text => $councils_text,
category => $category,
extra_name_info => $extra_name_info,
+ categories => $c->stash->{category_options},
}
);
@@ -716,6 +717,14 @@ sub process_user : Private {
my $user_title = Utils::trim_text( $params{fms_extra_title} );
+ if ( $c->cobrand->allow_anonymous_reports ) {
+ my $anon_details = $c->cobrand->anonymous_account;
+
+ for my $key ( qw( email name ) ) {
+ $params{ $key } ||= $anon_details->{ $key };
+ }
+ }
+
# The user is already signed in
if ( $c->user_exists ) {
my $user = $c->user->obj;
@@ -780,7 +789,9 @@ sub process_report : Private {
'detail_offensive',
'may_show_name', #
'category', #
+ 'subcategory', #
'partial', #
+ 'service', #
);
# load the report
@@ -805,9 +816,14 @@ sub process_report : Private {
}
$report->detail( $detail );
+ # mobile device type
+ $report->service( $params{service} ) if $params{service};
+
# set these straight from the params
$report->category( _ $params{category} ) if $params{category};
+ $report->subcategory( $params{subcategory} );
+
my $areas = $c->stash->{all_areas_mapit};
$report->areas( ',' . join( ',', sort keys %$areas ) . ',' );
@@ -927,11 +943,7 @@ sub check_for_errors : Private {
# let the model check for errors
$c->stash->{field_errors} ||= {};
- my %field_errors = (
- %{ $c->stash->{field_errors} },
- %{ $c->stash->{report}->user->check_for_errors },
- %{ $c->stash->{report}->check_for_errors },
- );
+ my %field_errors = $c->cobrand->report_check_for_errors( $c );
# Zurich, we don't care about title or name
# There is no title, and name is optional
@@ -978,7 +990,14 @@ sub save_user_and_report : Private {
my $report = $c->stash->{report};
# Save or update the user if appropriate
- if ( !$report->user->in_storage ) {
+ if ( $c->cobrand->never_confirm_reports ) {
+ if ( $report->user->in_storage() ) {
+ $report->user->update();
+ } else {
+ $report->user->insert();
+ }
+ $report->confirm();
+ } elsif ( !$report->user->in_storage ) {
# User does not exist.
# Store changes in token for when token is validated.
$c->stash->{token_data} = {
@@ -1106,6 +1125,10 @@ sub redirect_or_confirm_creation : Private {
if ( $c->cobrand->moniker eq 'fixmybarangay' && $c->user->from_body && $c->stash->{external_source_id}) {
$report_uri = $c->uri_for( '/report', $report->id, undef, { external_source_id => $c->stash->{external_source_id} } );
+ } elsif ( $c->cobrand->never_confirm_reports && $report->non_public ) {
+ $c->log->info( 'cobrand was set to always confirm reports and report was non public, success page showed');
+ $c->stash->{template} = 'report_created.html';
+ return 1;
} else {
$report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url;
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 4467a7036..dbfd57e78 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -203,8 +203,23 @@ sub process_update : Private {
$params{state} = 'fixed - council'
if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_body( $update->problem->bodies_str );
$update->problem_state( $params{state} );
+ } else {
+ # we do this so we have a record of the state of the problem at this point
+ # for use when sending updates to external parties
+ if ( $update->mark_fixed ) {
+ $update->problem_state( 'fixed - user' );
+ } elsif ( $update->mark_open ) {
+ $update->problem_state( 'confirmed' );
+ # if there is not state param and neither of the above conditions apply
+ # then we are not changing the state of the problem so can use the current
+ # problem state
+ } else {
+ my $problem = $c->stash->{problem} || $update->problem;
+ $update->problem_state( $problem->state );
+ }
}
+
my @extra; # Next function fills this, but we don't need it here.
# This is just so that the error checkign for these extra fields runs.
# TODO Use extra here as it is used on reports.
@@ -249,7 +264,8 @@ sub check_for_errors : Private {
$error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->bodies_str );
my $state = $c->req->param('state');
- $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) );
+ $state = 'fixed - council' if $state eq 'fixed';
+ $error = 1 unless ( grep { $state eq $_ } ( FixMyStreet::DB::Result::Problem->council_states() ) );
if ( $error ) {
$c->stash->{errors} ||= [];
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index fc7eb522f..781dee698 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -112,14 +112,21 @@ sub ward : Path : Args(2) {
my $pins = $c->stash->{pins};
$c->stash->{page} = 'reports'; # So the map knows to make clickable pins
- FixMyStreet::Map::display_map(
- $c,
+ my %map_params = (
latitude => @$pins ? $pins->[0]{latitude} : 0,
longitude => @$pins ? $pins->[0]{longitude} : 0,
area => $c->stash->{ward} ? $c->stash->{ward}->{id} : [ keys %{$c->stash->{body}->areas} ],
- pins => $pins,
any_zoom => 1,
);
+ if ( $c->cobrand->moniker eq 'emptyhomes' ) {
+ FixMyStreet::Map::display_map(
+ $c, %map_params, latitude => 0, longitude => 0,
+ );
+ } else {
+ FixMyStreet::Map::display_map(
+ $c, %map_params, pins => $pins,
+ );
+ }
$c->cobrand->tweak_all_reports_map( $c );
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index a4c4f4ffc..0d4894aa8 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -80,9 +80,7 @@ sub process_extras {
sub contact_email {
my $self = shift;
- my $type = shift || '';
- return join( '@', 'info', 'bromley.gov.uk' ) if $type eq 'contact';
- return $self->next::method();
+ return join( '@', 'info', 'bromley.gov.uk' );
}
sub contact_name { 'Bromley Council (do not reply)'; }
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 998f287a1..963c8a6ad 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -145,6 +145,14 @@ Can be specified in template.
sub enter_postcode_text { }
+=head2 site_title
+
+The name of the site
+
+=cut
+
+sub site_title { return 'FixMyStreet'; }
+
=head2 set_lang_and_domain
my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode, $dir )
@@ -581,6 +589,13 @@ For UK sub-cobrands, to specify various alternations needed for them.
=cut
sub is_council { 0; }
+=item is_two_tier
+
+For UK sub-cobrands, to specify various alternations needed for them.
+
+=cut
+sub is_two_tier { 0; }
+
=item council_rss_alert_options
Generate a set of options for council rss alerts.
@@ -723,6 +738,61 @@ until the contacts/area/body handling is rewritten to be better.
sub reports_by_body { 0; }
+=head2 default_show_name
+
+Returns true if the show name checkbox should be ticked by default.
+
+=cut
+
+sub default_show_name {
+ 1;
+}
+
+=head2 report_check_for_errors
+
+Perform validation for new reports. Takes Catalyst context object as an argument
+
+=cut
+
+sub report_check_for_errors {
+ my $self = shift;
+ my $c = shift;
+
+ return (
+ %{ $c->stash->{field_errors} },
+ %{ $c->stash->{report}->user->check_for_errors },
+ %{ $c->stash->{report}->check_for_errors },
+ );
+}
+
+sub report_sent_confirmation_email { 0; }
+
+=head2 never_confirm_reports
+
+If true then we never send an email to confirm a report
+
+=cut
+
+sub never_confirm_reports { 0; }
+
+=head2 allow_anonymous_reports
+
+If true then can have reports that are truely anonymous - i.e with no email or name. You
+need to also put details in the anonymous_account function too.
+
+=cut
+
+sub allow_anonymous_reports { 0; }
+
+=head2 anonymous_account
+
+Details to use for anonymous reports. This should return a hashref with an email and
+a name key
+
+=cut
+
+sub anonymous_account { undef; }
+
=head2 show_unconfirmed_reports
Whether reports in state 'unconfirmed' should still be shown on the public site.
diff --git a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm
index c53b8e971..53bf9f3b4 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm
@@ -43,5 +43,17 @@ sub can_support_problems {
sub reports_by_body { 1 }
+sub default_show_name {
+ my $self = shift;
+
+ return 0 if $self->{c}->user->from_council;
+ return 1;
+}
+
+# makes no sense to send questionnaires since FMB's reporters are mostly staff
+sub send_questionnaires {
+ return 0;
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index 99797f9c9..6a534fc18 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -8,6 +8,7 @@ sub council_id { return 2434; }
sub council_area { return 'Lichfield district'; }
sub council_name { return 'Lichfield District Council'; }
sub council_url { return 'lichfielddc'; }
+sub is_two_tier { return 1; }
# Different to councils parent due to this being a two-tier council. If we get
# more, this can be genericised in the parent.
@@ -26,18 +27,6 @@ sub disambiguate_location {
};
}
-# If we ever link to a county problem report, needs to be to main FixMyStreet
-sub base_url_for_report {
- my ( $self, $report ) = @_;
- my $bodies = $report->bodies;
- my %areas = map { %{$_->areas} } values %$bodies;
- if ( $areas{2434} ) {
- return $self->base_url;
- } else {
- return FixMyStreet->config('BASE_URL');
- }
-}
-
sub map_type {
return 'OSM';
}
diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
new file mode 100644
index 000000000..62550e626
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
@@ -0,0 +1,55 @@
+package FixMyStreet::Cobrand::Oxfordshire;
+use base 'FixMyStreet::Cobrand::UKCouncils';
+
+use strict;
+use warnings;
+
+sub council_id { return 2237; }
+sub council_area { return 'Oxfordshire'; }
+sub council_name { return 'Oxfordshire County Council'; }
+sub council_url { return 'oxfordshire'; }
+sub is_two_tier { return 1; }
+
+sub base_url {
+ return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE');
+ return 'http://fixmystreet.oxfordshire.gov.uk';
+}
+
+# Different to councils parent due to this being a two-tier council. If we get
+# more, this can be genericised in the parent.
+sub problems_clause {
+ return { bodies_str => { like => '%2237%' } };
+}
+
+sub path_to_web_templates {
+ my $self = shift;
+ return [
+ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify,
+ FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify
+ ];
+}
+
+sub enter_postcode_text {
+ my ($self) = @_;
+ return 'Enter an Oxfordshire postcode, or street name and area';
+}
+
+sub disambiguate_location {
+ my $self = shift;
+ my $string = shift;
+ return {
+ %{ $self->SUPER::disambiguate_location() },
+ centre => '51.765765,-1.322324',
+ span => '0.154963,0.24347', # NB span is not correct
+ bounds => [ 51.459413, -1.719500, 52.168471, -0.870066 ],
+ };
+}
+
+sub example_places {
+ return ( 'OX20 1SZ', 'Park St, Woodstock' );
+}
+
+sub default_show_name { 0 }
+
+1;
+
diff --git a/perllib/FixMyStreet/Cobrand/SeeSomething.pm b/perllib/FixMyStreet/Cobrand/SeeSomething.pm
new file mode 100644
index 000000000..88d5f6b78
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/SeeSomething.pm
@@ -0,0 +1,148 @@
+package FixMyStreet::Cobrand::SeeSomething;
+use parent 'FixMyStreet::Cobrand::UKCouncils';
+
+use strict;
+use warnings;
+
+sub council_id { return [ 2520, 2522, 2514, 2546, 2519, 2538, 2535 ]; }
+sub council_area { return 'West Midlands'; }
+sub council_name { return 'See Something Say Something'; }
+sub council_url { return 'seesomething'; }
+sub area_types { [ 'MTD' ] }
+sub site_title { return 'See Something, Say Something'; }
+
+
+sub site_restriction {
+ my $self = shift;
+ return { bodies_str => { IN => $self->council_id } };
+}
+
+sub problems_clause {
+ my $self = shift;
+ return { bodies_str => { IN => $self->council_id } };
+}
+
+sub path_to_web_templates {
+ my $self = shift;
+ return [
+ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify,
+ FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify
+ ];
+}
+
+sub area_check {
+ my ( $self, $params, $context ) = @_;
+
+ my $councils = $params->{all_areas};
+ my $council_match = grep { $councils->{$_} } @{ $self->council_id };
+
+ if ($council_match) {
+ return 1;
+ }
+
+ return ( 0, "That location is not covered by See Something, Say Something" );
+}
+
+sub disambiguate_location {
+ my $self = shift;
+ my $string = shift;
+
+ my $town = 'West Midlands';
+
+ return {
+ %{ $self->SUPER::disambiguate_location() },
+ town => $town,
+ centre => '52.4803101685267,-2.2708272758854',
+ span => '1.4002794815887,2.06340043925997',
+ bounds => [ 51.8259444771676, -3.23554082684068, 53.2262239587563, -1.17214038758071 ],
+ };
+}
+
+sub example_places {
+ return ( 'WS1 4NH', 'Austin Drive, Coventry' );
+}
+
+sub send_questionnaires {
+ return 0;
+}
+
+sub ask_ever_reported {
+ return 0;
+}
+
+sub report_sent_confirmation_email { 1; }
+
+sub report_check_for_errors { return (); }
+
+sub never_confirm_reports { 1; }
+
+sub allow_anonymous_reports { 1; }
+
+sub anonymous_account { return { name => 'Anonymous Submission', email => FixMyStreet->config('DO_NOT_REPLY_EMAIL') }; }
+
+sub admin_pages {
+ my $self = shift;
+
+ return {
+ 'stats' => ['Reports', 0],
+ };
+};
+
+sub admin_stats {
+ my $self = shift;
+ my $c = $self->{c};
+
+ my %filters = ();
+
+ my %councils =
+ map {
+ $c->stash->{council_details}->{$_}->{name} =~ s/(?:Borough|City) Council//;
+ $_ => $c->stash->{council_details}->{$_}
+ }
+ @{ $self->council_id };
+
+ $c->stash->{council_details} = \%councils;
+
+ if ( !$c->user_exists || !grep { $_ == $c->user->from_council } @{ $self->council_id } ) {
+ $c->detach( '/page_error_404_not_found' );
+ }
+
+ if ( $c->req->param('category') ) {
+ $filters{category} = $c->req->param('category');
+ $c->stash->{category} = $c->req->param('category');
+ }
+
+ if ( $c->req->param('subcategory') ) {
+ $filters{subcategory} = $c->req->param('subcategory');
+ $c->stash->{subcategory} = $c->req->param('subcategory');
+ }
+
+ if ( $c->req->param('service') ) {
+ $filters{service} = { -ilike => $c->req->param('service') };
+ $c->stash->{service} = $c->req->param('service');
+ }
+
+ my $page = $c->req->params->{p} || 1;
+
+ my $p = $c->model('DB::Problem')->search(
+ {
+ confirmed => { not => undef },
+ %filters
+ },
+ {
+ columns => [ qw(
+ service category subcategory council confirmed
+ ) ],
+ order_by => { -desc=> [ 'confirmed' ] },
+ rows => 20,
+ }
+ )->page( $page );
+
+ $c->stash->{reports} = $p;
+ $c->stash->{pager} = $p->pager;
+
+ return 1;
+}
+
+1;
+
diff --git a/perllib/FixMyStreet/Cobrand/Stevenage.pm b/perllib/FixMyStreet/Cobrand/Stevenage.pm
index f7a9ccd84..560baba37 100644
--- a/perllib/FixMyStreet/Cobrand/Stevenage.pm
+++ b/perllib/FixMyStreet/Cobrand/Stevenage.pm
@@ -8,6 +8,7 @@ sub council_id { return 2347; }
sub council_area { return 'Stevenage'; }
sub council_name { return 'Stevenage Council'; }
sub council_url { return 'stevenage'; }
+sub is_two_tier { return 1; }
sub path_to_web_templates {
my $self = shift;
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index 2b4385a98..354b1b72a 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -86,4 +86,20 @@ sub recent_photos {
return $self->problems->recent_photos( $num, $lat, $lon, $dist );
}
+# If we ever link to a county problem report, needs to be to main FixMyStreet
+sub base_url_for_report {
+ my ( $self, $report ) = @_;
+ if ( $self->is_two_tier ) {
+ my $bodies = $report->bodies;
+ my %areas = map { %{$_->areas} } values %$bodies;
+ if ( $areas{$self->council_id} ) {
+ return $self->base_url;
+ } else {
+ return FixMyStreet->config('BASE_URL');
+ }
+ } else {
+ return $self->base_url;
+ }
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 27ea1897e..83704563a 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -36,6 +36,8 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"can_be_devolved",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "send_extended_statuses",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
"parent",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
);
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 2098a6495..33fbb9356 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -147,6 +147,11 @@ sub check_for_errors {
$errors{update} = _('Please enter a message')
unless $self->text =~ m/\S/;
+ if ( $self->text && $self->problem && $self->problem->bodies_str
+ && $self->problem->bodies_str eq '2482' && length($self->text) > 2000 ) {
+ $errors{update} = _('Updates are limited to 2000 characters in length. Please shorten your update');
+ }
+
return \%errors;
}
@@ -187,6 +192,10 @@ sub meta_problem_state {
my $state = $self->problem_state;
$state =~ s/ -.*$//;
+ $state = _("not the council's responsibility")
+ if $state eq 'not responsible';
+ $state = _('duplicate report') if $state eq 'duplicate';
+
return $state;
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index f43e31173..d9a2a0273 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -100,6 +100,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"interest_count",
{ data_type => "integer", default_value => 0, is_nullable => 1 },
+ "subcategory",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
@@ -196,10 +198,11 @@ HASHREF.
sub open_states {
my $states = {
- 'confirmed' => 1,
- 'investigating' => 1,
- 'planned' => 1,
- 'in progress' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
};
return wantarray ? keys %{$states} : $states;
@@ -237,7 +240,11 @@ HASHREF.
sub closed_states {
my $states = {
- 'closed' => 1,
+ 'closed' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'internal referral' => 1,
};
return wantarray ? keys %{$states} : $states;
@@ -248,21 +255,26 @@ sub closed_states {
@states = FixMyStreet::DB::Problem::visible_states();
-Get a list or states that should be visible on the site. If called in
+Get a list of states that should be visible on the site. If called in
array context then returns an array of names, otherwise returns a
HASHREF.
=cut
my $visible_states = {
- 'confirmed' => 1,
- 'planned' => 1,
- 'investigating' => 1,
- 'in progress' => 1,
- 'fixed' => 1,
- 'fixed - council' => 1,
- 'fixed - user' => 1,
- 'closed' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'closed' => 1,
+ 'internal referral' => 1,
};
sub visible_states {
return wantarray ? keys %{$visible_states} : $visible_states;
@@ -271,6 +283,63 @@ sub visible_states_add_unconfirmed {
$visible_states->{unconfirmed} = 1;
}
+=head2
+
+ @states = FixMyStreet::DB::Problem::all_states();
+
+Get a list of all states that a problem can have. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub all_states {
+ my $states = {
+ 'hidden' => 1,
+ 'partial' => 1,
+ 'unconfirmed' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'action scheduled' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'closed' => 1,
+ 'internal referral' => 1,
+ };
+
+ return wantarray ? keys %{$states} : $states;
+}
+
+=head2
+
+ @states = FixMyStreet::DB::Problem::council_states();
+
+Get a list of states that are availble to council users. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+sub council_states {
+ my $states = {
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'action scheduled' => 1,
+ 'in progress' => 1,
+ 'fixed - council' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'internal referral' => 1,
+ };
+
+ return wantarray ? keys %{$states} : $states;
+}
+
my $tz = DateTime::TimeZone->new( name => "local" );
sub confirmed_local {
@@ -371,6 +440,11 @@ sub check_for_errors {
$self->category(undef);
}
+ if ( $self->bodies_str && $self->detail &&
+ $self->bodies_str eq '2482' && length($self->detail) > 2000 ) {
+ $errors{detail} = _('Reports are limited to 2000 characters in length. Please shorten your report');
+ }
+
return \%errors;
}
@@ -508,11 +582,7 @@ sub meta_line {
my $category = _($problem->category);
utf8::decode($category);
- if ($problem->anonymous) {
- $meta = sprintf(_('%s, reported anonymously at %s'), $category, $date_time);
- } else {
- $meta = sprintf(_('%s, reported by %s at %s'), $category, $problem->name, $date_time);
- }
+ $meta = sprintf(_('%s, reported at %s'), $category, $date_time);
} else {
@@ -598,7 +668,8 @@ sub body {
# Note: this only makes sense when called on a problem that has been sent!
sub can_display_external_id {
my $self = shift;
- if ($self->external_id && $self->send_method_used && $self->send_method_used eq 'barnet') {
+ if ($self->external_id && $self->send_method_used &&
+ ($self->send_method_used eq 'barnet' || $self->council =~ /2237/)) {
return 1;
}
return 0;
@@ -618,7 +689,7 @@ sub processed_summary_string {
my ( $problem, $c ) = @_;
my ($duration_clause, $external_ref_clause);
if ($problem->whensent) {
- $duration_clause = $problem->duration_string($c)
+ $duration_clause = $problem->duration_string($c);
}
if ($problem->can_display_external_id) {
if ($duration_clause) {
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 5b6b33d94..8e9b3d17e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -231,13 +231,12 @@ sub _send_aggregated_alert_email(%) {
unless -e $template;
$template = Utils::read_file($template);
- my $sender = $cobrand->contact_email;
- (my $from = $sender) =~ s/team/fms-DO-NOT-REPLY/; # XXX
+ my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
my $result = FixMyStreet::App->send_email_cron(
{
_template_ => $template,
_parameters_ => \%data,
- From => [ $from, _($cobrand->contact_name) ],
+ From => [ $sender, _($cobrand->contact_name) ],
To => $data{alert_email},
},
$sender,
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index dc4643673..078c78d0e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -291,6 +291,16 @@ sub send_reports {
$h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row );
}
+ if ( $cobrand->allow_anonymous_reports &&
+ $row->user->email eq $cobrand->anonymous_account->{'email'}
+ ) {
+ $h{anonymous_report} = 1;
+ $h{user_details} = _('This report was submitted anonymously');
+ } else {
+ $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n";
+ $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n";
+ }
+
my %reporters = ();
my ( $sender_count );
if ($site eq 'emptyhomes') {
@@ -338,6 +348,10 @@ sub send_reports {
$h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
}
+ if ( $row->subcategory ) {
+ $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n";
+ }
+
$h{bodies_name} = join(_(' and '), @dear);
if ($h{category} eq _('Other')) {
$h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
@@ -364,12 +378,9 @@ sub send_reports {
if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) {
# on a staging server send emails to ourselves rather than the bodies
- my @testing_bodies = split( '\|', mySociety::Config::get('TESTING_COUNCILS') );
- unless ( grep { $row->bodies_str eq $_ } @testing_bodies ) {
- %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters;
- unless (%reporters) {
- %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() );
- }
+ %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters;
+ unless (%reporters) {
+ %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() );
}
}
@@ -396,6 +407,9 @@ sub send_reports {
whensent => \'ms_current_timestamp()',
lastupdate => \'ms_current_timestamp()',
} );
+ if ( $cobrand->report_sent_confirmation_email && !$h{anonymous_report}) {
+ _send_report_sent_email( $row, \%h, $nomail );
+ }
} else {
my @errors;
for my $sender ( keys %reporters ) {
@@ -441,4 +455,30 @@ sub send_reports {
}
}
+sub _send_report_sent_email {
+ my $row = shift;
+ my $h = shift;
+ my $nomail = shift;
+
+ my $template = 'confirm_report_sent.txt';
+ my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify;
+ $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify
+ unless -e $template_path;
+ $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify
+ unless -e $template_path;
+ $template = Utils::read_file( $template_path );
+
+ my $result = FixMyStreet::App->send_email_cron(
+ {
+ _template_ => $template,
+ _parameters_ => $h,
+ To => $row->user->email,
+ From => mySociety::Config::get('CONTACT_EMAIL'),
+ },
+ mySociety::Config::get('CONTACT_EMAIL'),
+ [ $row->user->email ],
+ $nomail
+ );
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index d6b3eb5cb..1b9521a9f 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -89,9 +89,8 @@ sub send_questionnaires_period {
} );
$h{url} = $cobrand->base_url($row->cobrand_data) . '/Q/' . $token->token;
- my $sender = $cobrand->contact_email;
+ my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
my $sender_name = _($cobrand->contact_name);
- $sender =~ s/team/fms-DO-NOT-REPLY/;
print "Sending questionnaire " . $questionnaire->id . ", problem "
. $row->id . ", token " . $token->token . " to "
diff --git a/perllib/FixMyStreet/EmailSend.pm b/perllib/FixMyStreet/EmailSend.pm
index 61d8a70c2..8b6eed462 100644
--- a/perllib/FixMyStreet/EmailSend.pm
+++ b/perllib/FixMyStreet/EmailSend.pm
@@ -2,10 +2,7 @@ package FixMyStreet::EmailSend;
use base Email::Send::SMTP;
sub get_env_sender {
- # Should really use cobrand's contact_email function, but not sure how
- # best to access that from in here.
- my $sender = FixMyStreet->config('CONTACT_EMAIL');
- $sender =~ s/team/fms-DO-NOT-REPLY/;
+ my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
return $sender;
}
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 182c47d56..1ff476da3 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -33,7 +33,13 @@ sub build_recipient_list {
$self->unconfirmed_notes->{$body_email}{$row->category} = $note;
}
- push @{ $self->to }, [ $body_email, $body->name ];
+ # see something uses council areas but doesn't send to councils so just use a
+ # generic name here to minimise confusion
+ if ( $row->cobrand eq 'seesomething' ) {
+ push @{ $self->to }, [ $body_email, 'See Something, Say Something' ];
+ } else {
+ push @{ $self->to }, [ $body_email, $body->name ];
+ }
$recips{$body_email} = 1;
}
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index c6d838998..1b79bcc99 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -9,6 +9,9 @@ use FixMyStreet::App;
use mySociety::Config;
use DateTime::Format::W3CDTF;
use Open311;
+use Readonly;
+
+Readonly::Scalar my $COUNCIL_ID_OXFORDSHIRE => 2237;
sub should_skip {
my $self = shift;
@@ -34,7 +37,7 @@ sub send {
my $send_notpinpointed = 0;
my $use_service_as_deviceid = 0;
- my $basic_desc = 0;
+ my $extended_desc = 1;
# To rollback temporary changes made by this function
my $revert = 0;
@@ -69,7 +72,22 @@ sub send {
push @$extra, { name => 'last_name', value => $lastname };
}
- $basic_desc = 1;
+ $extended_desc = 0;
+ }
+
+ # extra Oxfordshire fields: send nearest street, postcode, northing and easting, and the FMS id
+ if ( $row->council =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
+
+ my $extra = $row->extra;
+ push @$extra, { name => 'external_id', value => $row->id };
+ push @$extra, { name => 'closest_address', value => $h->{closest_address} } if $h->{closest_address};
+ if ( $row->used_map || ( !$row->used_map && !$row->postcode ) ) {
+ push @$extra, { name => 'northing', value => $h->{northing} };
+ push @$extra, { name => 'easting', value => $h->{easting} };
+ }
+ $row->extra( $extra );
+
+ $extended_desc = 'oxfordshire';
}
# FIXME: we've already looked this up before
@@ -86,7 +104,7 @@ sub send {
always_send_latlong => $always_send_latlong,
send_notpinpointed => $send_notpinpointed,
use_service_as_deviceid => $use_service_as_deviceid,
- basic_description => $basic_desc,
+ extended_description => $extended_desc,
);
# non standard west berks end points
@@ -94,6 +112,12 @@ sub send {
$open311->endpoints( { services => 'Services', requests => 'Requests' } );
}
+ # non-standard Oxfordshire endpoint (because it's just a script, not a full Open311 service)
+ if ( $row->council =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
+ $open311->endpoints( { requests => 'open311_service_request.cgi' } );
+ $revert = 1;
+ }
+
# required to get round issues with CRM constraints
if ( $row->bodies_str =~ /2218/ ) {
$row->user->name( $row->user->id . ' ' . $row->user->name );
@@ -101,7 +125,7 @@ sub send {
}
if ($row->cobrand eq 'fixmybarangay') {
- # FixMyBarangay endpoints expect external_id as an attribute
+ # FixMyBarangay endpoints expect external_id as an attribute, as do Oxfordshire
$row->extra( [ { 'name' => 'external_id', 'value' => $row->id } ] );
$revert = 1;
}
@@ -115,9 +139,17 @@ sub send {
$row->external_id( $resp );
$row->send_method_used('Open311');
if ($row->cobrand eq 'fixmybarangay') {
- # currently the only external body using Open311 is DPS
- # (this will change when we have 'body' logic in place, meanwhile: hardcoded)
- $row->external_body("DPS");
+ # FixMyBarangay: currently the external bodies using Open311 are DPS, DEPW, DPWH
+ # for now identify the latter two by their name in the service_code ($contact->email)
+ # So: this works because we are anticipating the service codes for (e.g., potholes) look
+ # like this:
+ # POTDEPW or POTDPWH
+ # (TODO: this will change when we have 'body' logic in place, meanwhile: hardcoded)
+ if ($contact->email =~ /(DEPW|DPWH)$/i) {
+ $row->external_body(uc $1); # body is DEPW (city roads) or DPWH (national roads)
+ } else {
+ $row->external_body("DPS"); # only other open311 dept is DPS
+ }
}
$result *= 0;
$self->success( 1 );
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index 52e17e99d..efa0ac64f 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -22,9 +22,10 @@ has success => ( is => 'rw', 'isa' => 'Bool', default => 0 );
has error => ( is => 'rw', 'isa' => 'Str', default => '' );
has always_send_latlong => ( is => 'ro', isa => 'Bool', default => 1 );
has send_notpinpointed => ( is => 'ro', isa => 'Bool', default => 0 );
-has basic_description => ( is => 'ro', isa => 'Bool', default => 0 );
+has extended_description => ( is => 'ro', isa => 'Str', default => 1 );
has use_service_as_deviceid => ( is => 'ro', isa => 'Bool', default => 0 );
has use_extended_updates => ( is => 'ro', isa => 'Bool', default => 0 );
+has extended_statuses => ( is => 'ro', isa => 'Bool', default => 0 );
before [
qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates
@@ -38,7 +39,11 @@ sub get_service_list {
my $service_list_xml = $self->_get( $self->endpoints->{services} );
- return $self->_get_xml_object( $service_list_xml );
+ if ( $service_list_xml ) {
+ return $self->_get_xml_object( $service_list_xml );
+ } else {
+ return undef;
+ }
}
sub get_service_meta_info {
@@ -95,12 +100,12 @@ sub _populate_service_request_params {
my $service_code = shift;
my $description;
- if ( $self->basic_description ) {
- $description = $problem->detail;
- } else {
+ if ( $self->extended_description ) {
$description = $self->_generate_service_request_description(
$problem, $extra
);
+ } else {
+ $description = $problem->detail;
}
my ( $firstname, $lastname ) = ( $problem->user->name =~ /(\w+)\.?\s+(.+)/ );
@@ -168,8 +173,6 @@ sub _generate_service_request_description {
my $extra = shift;
my $description = <<EOT;
-title: @{[$problem->title()]}
-
detail: @{[$problem->detail()]}
url: $extra->{url}
@@ -177,6 +180,12 @@ url: $extra->{url}
Submitted via FixMyStreet
EOT
;
+ if ($self->extended_description ne 'oxfordshire') {
+ $description = <<EOT . $description;
+title: @{[$problem->title()]}
+
+EOT
+ }
return $description;
}
@@ -283,10 +292,39 @@ sub _populate_service_request_update_params {
my $name = $comment->name || $comment->user->name;
my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ );
+ # fall back to problem state as it's probably correct
+ my $state = $comment->problem_state || $comment->problem->state;
+
+ my $status = 'OPEN';
+ if ( $self->extended_statuses ) {
+ if ( FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) {
+ $status = 'FIXED';
+ } elsif ( $state eq 'in progress' ) {
+ $status = 'IN_PROGRESS';
+ } elsif ($state eq 'action scheduled'
+ || $state eq 'planned' ) {
+ $status = 'ACTION_SCHEDULED';
+ } elsif ( $state eq 'investigating' ) {
+ $status = 'INVESTIGATING';
+ } elsif ( $state eq 'duplicate' ) {
+ $status = 'DUPLICATE';
+ } elsif ( $state eq 'not responsible' ) {
+ $status = 'NOT_COUNCILS_RESPONSIBILITY';
+ } elsif ( $state eq 'unable to fix' ) {
+ $status = 'NO_FURTHER_ACTION';
+ } elsif ( $state eq 'internal referral' ) {
+ $status = 'INTERNAL_REFERRAL';
+ }
+ } else {
+ if ( !FixMyStreet::DB::Result::Problem->open_states()->{$state} ) {
+ $status = 'CLOSED';
+ }
+ }
+
my $params = {
updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)),
service_request_id => $comment->problem->external_id,
- status => $comment->problem->is_open ? 'OPEN' : 'CLOSED',
+ status => $status,
email => $comment->user->email,
description => $comment->text,
last_name => $lastname,
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 27cb21c3a..e4416f792 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -11,6 +11,9 @@ has end_date => ( is => 'ro', default => undef );
has suppress_alerts => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
+Readonly::Scalar my $AREA_ID_BROMLEY => 2482;
+Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
+
sub fetch {
my $self = shift;
@@ -31,11 +34,16 @@ sub fetch {
jurisdiction => $body->jurisdiction,
);
- if ( $body->areas->{2482} ) {
+ # custom endpoint URLs because these councils have non-standard paths
+ if ( $body->areas->{$AREA_ID_BROMLEY} ) {
my $endpoints = $o->endpoints;
$endpoints->{update} = 'update.xml';
$endpoints->{service_request_updates} = 'update.xml';
$o->endpoints( $endpoints );
+ } elsif ( $body->areas->{$AREA_ID_OXFORDSHIRE} ) {
+ my $endpoints = $o->endpoints;
+ $endpoints->{service_request_updates} = 'open311_service_request_update.cgi';
+ $o->endpoints( $endpoints );
}
$self->suppress_alerts( $body->suppress_alerts );
@@ -55,7 +63,7 @@ sub update_comments {
push @args, $self->start_date;
push @args, $self->end_date;
# default to asking for last 2 hours worth if not Bromley
- } elsif ( ! $body_details->{areas}->{2482} ) {
+ } elsif ( ! $body_details->{areas}->{$AREA_ID_BROMLEY} ) {
my $end_dt = DateTime->now();
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -2 );
@@ -79,13 +87,15 @@ sub update_comments {
# what problem it belongs to so just skip
next unless $request_id;
- my $problem =
- FixMyStreet::App->model('DB::Problem')
- ->search( {
- external_id => $request_id,
- # XXX This assumes that areas will actually only be one area.
- bodies_str => { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' },
- } );
+ my $problem;
+ my $criteria = { external_id => $request_id };
+ if ($open311->jurisdiction =~ /^fixmybarangay_(dps|dpwh|depw)$/i) { # use jurisdiction (not area_id) for FMB bodies
+ $criteria->{ external_body } = uc $1;
+ } else {
+ # XXX This assumes that areas will actually only be one area.
+ $criteria->{ bodies_str } = { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' };
+ }
+ $problem = FixMyStreet::App->model('DB::Problem')->search( $criteria );
if (my $p = $problem->first) {
my $c = $p->comments->search( { external_id => $request->{update_id} } );
@@ -113,12 +123,14 @@ sub update_comments {
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
if ( $comment->created_local > $p->lastupdate_local ) {
- if ( $p->is_open and lc($request->{status}) eq 'closed' ) {
- $p->state( 'fixed - council' );
- $comment->problem_state( 'fixed - council' );
- } elsif ( ( $p->is_closed || $p->is_fixed ) and lc($request->{status}) eq 'open' ) {
- $p->state( 'confirmed' );
- $comment->problem_state( 'confirmed' );
+ my $state = $self->map_state( $request->{status} );
+
+ # don't update state unless it's an allowed state and it's
+ # actually changing the state of the problem
+ if ( FixMyStreet::DB::Result::Problem->council_states()->{$state} && $p->state ne $state &&
+ !( $p->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) ) {
+ $p->state($state);
+ $comment->problem_state($state);
}
}
@@ -146,4 +158,22 @@ sub update_comments {
return 1;
}
+sub map_state {
+ my $self = shift;
+ my $incoming_state = shift;
+
+ $incoming_state = lc($incoming_state);
+ $incoming_state =~ s/_/ /g;
+
+ my %state_map = (
+ fixed => 'fixed - council',
+ 'not councils responsibility' => 'not responsible',
+ 'no further action' => 'unable to fix',
+ open => 'confirmed',
+ closed => 'fixed - council'
+ );
+
+ return $state_map{$incoming_state} || $incoming_state;
+}
+
1;
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index bd90e10e9..57ef90ecb 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -22,6 +22,7 @@ sub process_bodies {
while ( my $body = $self->bodies->next ) {
next unless $body->endpoint;
next unless lc($body->send_method) eq 'open311';
+ next if $body->jurisdiction =~ /^fixmybarangay_\w+$/; # FMB depts. not using service discovery yet
$self->_current_body( $body );
$self->process_body;
}
@@ -29,7 +30,6 @@ sub process_bodies {
sub process_body {
my $self = shift;
-
my $open311 = Open311->new(
endpoint => $self->_current_body->endpoint,
jurisdiction => $self->_current_body->jurisdiction,