aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm14
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Council.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm43
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm3
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm32
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm15
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm13
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm52
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyBarangay.pm45
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm21
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm12
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm8
-rw-r--r--perllib/FixMyStreet/DB/Result/Open311conf.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm11
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm18
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm21
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm4
-rw-r--r--perllib/FixMyStreet/Geocode/OSM.pm3
-rw-r--r--perllib/FixMyStreet/Map.pm4
-rw-r--r--perllib/FixMyStreet/SendReport.pm3
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm7
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm9
-rw-r--r--perllib/FixMyStreet/TestMech.pm8
33 files changed, 310 insertions, 83 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index ef299d224..b53b6ab06 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use POSIX qw(strftime strcoll);
use Digest::MD5 qw(md5_hex);
use mySociety::EmailUtil qw(is_valid_email);
+use if !$ENV{TRAVIS}, 'Image::Magick';
use FixMyStreet::SendReport;
@@ -305,6 +306,10 @@ sub update_contacts : Private {
$contact->note( $c->req->param('note') );
$contact->whenedited( \'ms_current_timestamp()' );
$contact->editor( $editor );
+ $contact->endpoint( $c->req->param('endpoint') );
+ $contact->jurisdiction( $c->req->param('jurisdiction') );
+ $contact->api_key( $c->req->param('api_key') );
+ $contact->send_method( $c->req->param('send_method') );
if ( $contact->in_storage ) {
$c->stash->{updated} = _('Values updated');
@@ -341,7 +346,7 @@ sub update_contacts : Private {
} elsif ( $posted eq 'open311' ) {
$c->forward('check_token');
- my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/;
+ my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id devolved/;
if ( $params{open311_id} ) {
my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } );
@@ -353,6 +358,7 @@ sub update_contacts : Private {
$conf->send_comments( $params{send_comments} || 0);
$conf->suppress_alerts( $params{suppress_alerts} || 0);
$conf->comment_user_id( $params{comment_user_id} || undef );
+ $conf->can_be_devolved( $params{devolved} || 0 );
$conf->update();
@@ -367,6 +373,7 @@ sub update_contacts : Private {
$conf->send_comments( $params{send_comments} || 0);
$conf->suppress_alerts( $params{suppress_alerts} || 0);
$conf->comment_user_id( $params{comment_user_id} || undef );
+ $conf->can_be_devolved( $params{devolved} || 0 );
$conf->insert();
@@ -462,6 +469,9 @@ sub council_edit : Path('council_edit') : Args(2) {
$c->stash->{history} = $history;
+ my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders };
+ $c->stash->{send_methods} = \@methods;
+
return 1;
}
@@ -652,7 +662,6 @@ sub report_edit : Path('report_edit') : Args(1) {
|| $flagged != $problem->flagged
|| $non_public != $problem->non_public )
{
- warn "edited";
$edited = 1;
}
@@ -1281,7 +1290,6 @@ sub trim {
sub _rotate_image {
my ($photo, $direction) = @_;
- use Image::Magick;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Rotate($direction);
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 4e5319a59..91ea61fbc 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -438,7 +438,7 @@ sub determine_location : Private {
$c->detach('choose');
}
- $c->go('index') if $c->stash->{location_error};
+ $c->go('index');
}
# truncate the lat,lon for nicer urls
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 3047b195c..f2bb23350 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -45,7 +45,7 @@ sub around_index : Path : Args(0) {
|| $c->forward('/location/determine_location_from_pc');
# Check to see if the spot is covered by a council - if not show an error.
- return unless $c->forward('check_location_is_acceptable');
+ return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable');
# If we have a partial - redirect to /report/new so that it can be
# completed.
@@ -204,6 +204,7 @@ sub display_location : Private {
longitude => $short_longitude,
clickable => 1,
pins => \@pins,
+ area => $c->cobrand->areas_on_around,
);
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm
index a6ce533e4..cb9e78421 100644
--- a/perllib/FixMyStreet/App/Controller/Council.pm
+++ b/perllib/FixMyStreet/App/Controller/Council.pm
@@ -52,7 +52,6 @@ sub load_and_check_councils : Private {
my $short_latitude = Utils::truncate_coordinate($latitude);
my $short_longitude = Utils::truncate_coordinate($longitude);
- # TODO: I think we want in_gb_locale around the MaPit line, needs testing
my $all_councils;
if ( $c->stash->{fetch_all_areas} ) {
my %area_types = map { $_ => 1 } @$area_types;
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index e4266dc64..a5ba8ff07 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -96,7 +96,7 @@ sub index : Path : Args(0) {
$c->stash->{council} = $council_detail;
my $children = mySociety::MaPit::call('area/children', $council,
- type => $mySociety::VotingArea::council_child_types,
+ type => $c->cobrand->area_types_children,
);
$c->stash->{children} = $children;
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm
index c3d754485..3e44cd748 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -64,6 +64,19 @@ sub determine_location_from_pc : Private {
$pc ||= $c->req->param('pc') || return;
$c->stash->{pc} = $pc; # for template
+ if ( $pc =~ /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/ ) {
+ $c->stash->{latitude} = $1;
+ $c->stash->{longitude} = $2;
+ return $c->forward( 'check_location' );
+ }
+ if ( $c->cobrand->country eq 'GB' && $pc =~ /^([A-Z])([A-Z])([\d\s]+)$/i ) {
+ if (my $convert = gridref_to_latlon( $1, $2, $3 )) {
+ $c->stash->{latitude} = $convert->{latitude};
+ $c->stash->{longitude} = $convert->{longitude};
+ return $c->forward( 'check_location' );
+ }
+ }
+
my ( $latitude, $longitude, $error ) =
FixMyStreet::Geocode::lookup( $pc, $c );
@@ -114,6 +127,36 @@ sub check_location : Private {
return 1;
}
+# Utility function for if someone (rarely) enters a grid reference
+sub gridref_to_latlon {
+ my ( $a, $b, $num ) = @_;
+ $a = ord(uc $a) - 65; $a-- if $a > 7;
+ $b = ord(uc $b) - 65; $b-- if $b > 7;
+ my $e = (($a-2)%5)*5 + $b%5;
+ my $n = 19 - int($a/5)*5 - int($b/5);
+
+ $num =~ s/\s+//g;
+ my $l = length($num);
+ return if $l % 2 or $l > 10;
+
+ $l /= 2;
+ $e .= substr($num, 0, $l);
+ $n .= substr($num, $l);
+
+ if ( $l < 5 ) {
+ $e .= 5;
+ $n .= 5;
+ $e .= 0 x (4-$l);
+ $n .= 0 x (4-$l);
+ }
+
+ my ( $lat, $lon ) = Utils::convert_en_to_latlon( $e, $n );
+ return {
+ latitude => $lat,
+ longitude => $lon,
+ };
+}
+
=head1 AUTHOR
Struan Donald
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index fc4c3fde7..fa4baf045 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -9,6 +9,7 @@ use Digest::SHA1 qw(sha1_hex);
use File::Path;
use File::Slurp;
use Path::Class;
+use if !$ENV{TRAVIS}, 'Image::Magick';
=head1 NAME
@@ -116,7 +117,6 @@ sub no_photo : Private {
# Shrinks a picture to the specified size, but keeping in proportion.
sub _shrink {
my ($photo, $size) = @_;
- use Image::Magick;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Scale(geometry => "$size>");
@@ -130,7 +130,6 @@ sub _shrink {
# Shrinks a picture to 90x60, cropping so that it is exactly that.
sub _crop {
my ($photo) = @_;
- use Image::Magick;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Resize( geometry => "90x60^" );
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index f0cc72e07..46d6350d7 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -157,6 +157,8 @@ sub submit_standard : Private {
my $new_state = '';
$new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' &&
FixMyStreet::DB::Result::Problem->open_states()->{$old_state};
+ $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' &&
+ FixMyStreet::DB::Result::Problem->closed_states()->{$old_state};
$new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' &&
FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state};
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index cda569860..a7e1e8a3a 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -56,6 +56,23 @@ sub display : Path('') : Args(1) {
$c->forward( 'format_problem_for_display' );
}
+sub support : Path('support') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $id = $c->req->param('id');
+
+ my $uri =
+ $id
+ ? $c->uri_for( '/report', $id )
+ : $c->uri_for('/');
+
+ if ( $id && $c->cobrand->can_support_problems && $c->user && $c->user->from_council ) {
+ $c->forward( 'load_problem_or_display_error', [ $id ] );
+ $c->stash->{problem}->update( { interest_count => \'interest_count +1' } );
+ }
+ $c->res->redirect( $uri );
+}
+
sub load_problem_or_display_error : Private {
my ( $self, $c, $id ) = @_;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 2318ee9e1..dedd447ee 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -6,7 +6,6 @@ BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Geocode;
use Encode;
-use Image::Magick;
use List::MoreUtils qw(uniq);
use POSIX 'strcoll';
use HTML::Entities;
@@ -14,7 +13,6 @@ use mySociety::MaPit;
use Path::Class;
use Utils;
use mySociety::EmailUtil;
-use mySociety::TempFiles;
use JSON;
=head1 NAME
@@ -709,22 +707,23 @@ sub process_user : Private {
my $report = $c->stash->{report};
+ # Extract all the params to a hash to make them easier to work with
+ my %params = map { $_ => scalar $c->req->param($_) }
+ ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' );
+
+ my $user_title = Utils::trim_text( $params{fms_extra_title} );
+
# The user is already signed in
if ( $c->user_exists ) {
my $user = $c->user->obj;
- my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' );
$user->name( Utils::trim_text( $params{name} ) ) if $params{name};
$user->phone( Utils::trim_text( $params{phone} ) );
- $user->title( Utils::trim_text( $params{fms_extra_title} ) );
+ $user->title( $user_title ) if $user_title;
$report->user( $user );
$report->name( $user->name );
return 1;
}
- # Extract all the params to a hash to make them easier to work with
- my %params = map { $_ => scalar $c->req->param($_) }
- ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' );
-
# cleanup the email address
my $email = $params{email} ? lc $params{email} : '';
$email =~ s{\s+}{}g;
@@ -752,7 +751,7 @@ sub process_user : Private {
$report->user->phone( Utils::trim_text( $params{phone} ) );
$report->user->password( Utils::trim_text( $params{password_register} ) )
if $params{password_register};
- $report->user->title( Utils::trim_text( $params{fms_extra_title} ) );
+ $report->user->title( $user_title ) if $user_title;
$report->name( Utils::trim_text( $params{name} ) );
return 1;
@@ -1010,6 +1009,13 @@ sub save_user_and_report : Private {
# Set unknown to DB unknown
$report->council( undef ) if $report->council eq '-1';
+ # if there is a Message Manager message ID, pass it back to the client view
+ if ($c->cobrand->moniker eq 'fixmybarangay' && $c->req->param('external_source_id')=~/^\d+$/) {
+ $c->stash->{external_source_id} = $c->req->param('external_source_id');
+ $report->external_source_id( $c->req->param('external_source_id') );
+ $report->external_source( $c->config->{MESSAGE_MANAGER_URL} ) ;
+ }
+
# save the report;
$report->in_storage ? $report->update : $report->insert();
@@ -1080,7 +1086,13 @@ sub redirect_or_confirm_creation : Private {
if ( $report->confirmed ) {
# Subscribe problem reporter to email updates
$c->forward( 'create_reporter_alert' );
- my $report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url;
+ my $report_uri;
+
+ if ( $c->cobrand->moniker eq 'fixmybarangay' && $c->user->from_council && $c->stash->{external_source_id}) {
+ $report_uri = $c->uri_for( '/report', $report->id, undef, { external_source_id => $c->stash->{external_source_id} } );
+ } else {
+ $report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url;
+ }
$c->log->info($report->user->id . ' was logged in, redirecting to /report/' . $report->id);
$c->res->redirect($report_uri);
$c->detach;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index c49123a90..da4cc33ca 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -76,6 +76,10 @@ sub update_problem : Private {
$problem->state('confirmed');
}
+ if ( $c->cobrand->can_support_problems && $c->user && $c->user->from_council && $c->req->param('external_source_id') ) {
+ $problem->interest_count( \'interest_count + 1' );
+ }
+
$problem->lastupdate( \'ms_current_timestamp()' );
$problem->update;
@@ -348,6 +352,7 @@ sub redirect_or_confirm_creation : Private {
if ( $update->confirmed ) {
$c->forward( 'update_problem' );
$c->forward( 'signup_for_alerts' );
+
my $report_uri = $c->cobrand->base_url_for_report( $update->problem ) . $update->problem->url;
$c->res->redirect($report_uri);
$c->detach;
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index dd725be19..7087e846b 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -6,7 +6,6 @@ use File::Slurp;
use List::MoreUtils qw(zip);
use POSIX qw(strcoll);
use mySociety::MaPit;
-use mySociety::VotingArea;
BEGIN { extends 'Catalyst::Controller'; }
@@ -71,7 +70,7 @@ sub index : Path : Args(0) {
if ($@) {
$c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later.");
if ($c->config->{STAGING_SITE}) {
- $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running.</p><p>'
+ $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/cron-wrapper bin/update-all-reports</p><p>'
. sprintf(_('The error was: %s'), $@);
}
$c->stash->{template} = 'errors/generic.html';
@@ -135,7 +134,7 @@ sub ward : Path : Args(2) {
# List of wards
unless ($c->stash->{ward}) {
my $children = mySociety::MaPit::call('area/children', [ $c->stash->{council}->{id} ],
- type => $mySociety::VotingArea::council_child_types,
+ type => $c->cobrand->area_types_children,
);
foreach (values %$children) {
$_->{url} = $c->uri_for( $c->stash->{council_url}
@@ -170,13 +169,6 @@ sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) {
$url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward};
$c->stash->{qs} = "/$url";
- my @params;
- push @params, $c->stash->{council}->{id} if $rss eq 'reports';
- push @params, $c->stash->{ward}
- ? $c->stash->{ward}->{id}
- : $c->stash->{council}->{id};
- $c->stash->{db_params} = [ @params ];
-
if ( $rss eq 'area' && $c->stash->{ward} ) {
# All problems within a particular ward
$c->stash->{type} = 'area_problems';
@@ -258,7 +250,6 @@ sub council_check : Private {
This action checks the ward name from a URI exists and is part of the right
parent, already found with council_check. It either stores the ward Area if
okay, or redirects to the council page if bad.
-This is currently only used in the UK, hence the use of mySociety::VotingArea.
=cut
@@ -272,7 +263,7 @@ sub ward_check : Private {
my $council = $c->stash->{council};
my $qw = mySociety::MaPit::call('areas', $ward,
- type => $mySociety::VotingArea::council_child_types,
+ type => $c->cobrand->area_types_children,
min_generation => $c->cobrand->area_min_generation
);
foreach my $area (sort { $a->{name} cmp $b->{name} } values %$qw) {
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index fe4b652ed..baaa3b927 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -106,10 +106,19 @@ sub local_problems_pc_distance : Path('pc') : Args(2) {
}
-sub local_problems : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)(?:/(\d+))?$') {
+sub local_problems_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)/(\d+)$') {
my ( $self, $c ) = @_;
+ $c->forward( 'local_problems', $c->req->captures );
+}
+
+sub local_problems_no_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)$') {
+ my ( $self, $c ) = @_;
+ $c->forward( 'local_problems', $c->req->captures );
+}
+
+sub local_problems : Private {
+ my ( $self, $c, $type, $a, $b, $d ) = @_;
- my ( $type, $a, $b, $d) = @{ $c->req->captures };
$c->forward( 'get_query_parameters', [ $d ] );
$c->detach( 'redirect_lat_lon', [ $a, $b ] )
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index eac194dff..42878be37 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -171,6 +171,7 @@ sub version {
my $path = FixMyStreet->path_to('web', $file);
$version_hash{$file} = ( stat( $path ) )[9];
}
+ $version_hash{$file} ||= '';
return "$file?$version_hash{$file}";
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index b1127833c..6324030b8 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -159,7 +159,8 @@ sub set_lang_and_domain {
my $lang_override = $self->language_override || $lang;
my $lang_domain = $self->language_domain || 'FixMyStreet';
- my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override );
+ my $headers = $self->{c} ? $self->{c}->req->headers : undef;
+ my $set_lang = mySociety::Locale::negotiate_language( $languages, $lang_override, $headers );
mySociety::Locale::gettext_domain( $lang_domain, $unicode, $dir );
mySociety::Locale::change();
return $set_lang;
@@ -645,7 +646,34 @@ Get stats to display on the council reports page
sub get_report_stats { return 0; }
-sub get_council_sender { return 'Email' };
+sub get_council_sender {
+ my ( $self, $area_id, $area_info, $category ) = @_;
+
+ my $send_method;
+
+ my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first;
+ $send_method = $council_config->send_method if $council_config;
+
+ if ( $council_config && $council_config->can_be_devolved ) {
+ # look up via category
+ my $config = FixMyStreet::App->model("DB::Contact")->search( { area_id => $area_id, category => $category } )->first;
+ if ( $config->send_method ) {
+ return { method => $config->send_method, config => $config };
+ } else {
+ return { method => $send_method, config => $council_config };
+ }
+ } elsif ( $send_method ) {
+ return { method => $send_method, config => $council_config };
+ }
+
+ return $self->_fallback_council_sender( $area_id, $area_info, $category );
+}
+
+sub _fallback_council_sender {
+ my ( $self, $area_id, $area_info, $category ) = @_;
+
+ return { method => 'Email' };
+};
sub example_places {
my $e = FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ];
@@ -653,6 +681,24 @@ sub example_places {
return $e;
}
+=head2 only_authed_can_create
+
+If true, only users with the from_council flag set are able to create reports.
+
+=cut
+
+sub only_authed_can_create {
+ return 0;
+}
+
+=head2 areas_on_around
+
+If set to an arrayref, will plot those area ID(s) from mapit on all the /around pages.
+
+=cut
+
+sub areas_on_around { []; }
+
sub process_extras {}
=head 2 pin_colour
@@ -678,6 +724,8 @@ Used in some cobrands to improve the intial display for Internet Explorer.
sub tweak_all_reports_map {}
+sub can_support_problems { return 0; }
+
sub default_map_zoom { undef };
1;
diff --git a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm
new file mode 100644
index 000000000..849a53b2b
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm
@@ -0,0 +1,45 @@
+package FixMyStreet::Cobrand::FixMyBarangay;
+use base 'FixMyStreet::Cobrand::Default';
+
+use strict;
+use warnings;
+
+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 country {
+ return 'PH';
+}
+
+sub language_domain { 'FixMyBarangay' }
+
+sub area_types {
+ return [ 'BGY' ];
+}
+
+sub disambiguate_location {
+ return {
+ country => 'ph',
+ bing_country => 'Philippines',
+ };
+}
+
+sub only_authed_can_create {
+ return 1;
+}
+
+sub areas_on_around {
+ return [ 1, 2 ];
+}
+
+sub can_support_problems {
+ return 1;
+}
+
+1;
+
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index 5c8a04681..b3dbad089 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -37,5 +37,9 @@ sub base_url_for_report {
}
}
+sub map_type {
+ return 'OSM';
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 0d6f98590..58da5166c 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -31,19 +31,11 @@ sub disambiguate_location {
};
}
-sub get_council_sender {
- my ( $self, $area_id, $area_info ) = @_;
-
- my $send_method;
-
- my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first;
- $send_method = $council_config->send_method if $council_config;
-
- return $send_method if $send_method;
-
- return 'London' if $area_info->{type} eq 'LBO';
- return 'NI' if $area_info->{type} eq 'LGD';
- return 'Email';
+sub _fallback_council_sender {
+ my ( $self, $area_id, $area_info, $category ) = @_;
+ return { method => 'London' } if $area_info->{type} eq 'LBO';
+ return { method => 'NI' } if $area_info->{type} eq 'LGD';
+ return { method => 'Email' };
}
sub process_extras {
@@ -53,7 +45,7 @@ sub process_extras {
my $extra = shift;
my $fields = shift || [];
- if ( $area_id == 2482 ) {
+ if ( $area_id eq '2482' ) {
my @fields = ( 'fms_extra_title', @$fields );
for my $field ( @fields ) {
my $value = $ctx->request->param( $field );
@@ -152,7 +144,6 @@ sub find_closest {
my $str = $self->SUPER::find_closest( $latitude, $longitude, $problem );
- # Get nearest postcode from Matthew's random gazetteer (put in MaPit? Or elsewhere?)
my $url = "http://mapit.mysociety.org/nearest/4326/$longitude,$latitude";
my $j = LWP::Simple::get($url);
if ($j) {
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 91695d7d0..8c9fea282 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -54,10 +54,6 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"problem_state",
{ data_type => "text", is_nullable => 1 },
- "external_id",
- { data_type => "text", is_nullable => 1 },
- "extra",
- { data_type => "text", is_nullable => 1 },
"send_fail_count",
{ data_type => "integer", default_value => 0, is_nullable => 0 },
"send_fail_reason",
@@ -66,6 +62,10 @@ __PACKAGE__->add_columns(
{ data_type => "timestamp", is_nullable => 1 },
"whensent",
{ data_type => "timestamp", is_nullable => 1 },
+ "external_id",
+ { data_type => "text", is_nullable => 1 },
+ "extra",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
@@ -82,8 +82,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 15:44:18
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nvkElEgSU6XcLd9znSqhmQ
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-07-11 18:53:26
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tSejJzLxHD/fMWjpa10lfA
__PACKAGE__->filter_column(
extra => {
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index cad12f1fc..993e3524b 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -38,6 +38,14 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"non_public",
{ data_type => "boolean", default_value => \"false", is_nullable => 1 },
+ "endpoint",
+ { data_type => "text", is_nullable => 1 },
+ "jurisdiction",
+ { data_type => "text", default_value => "", is_nullable => 1 },
+ "api_key",
+ { data_type => "text", default_value => "", is_nullable => 1 },
+ "send_method",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]);
diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm
index c95b0c8f2..8051e27de 100644
--- a/perllib/FixMyStreet/DB/Result/Open311conf.pm
+++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm
@@ -34,6 +34,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
"suppress_alerts",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "can_be_devolved",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]);
@@ -50,8 +52,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-11 13:30:31
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ByJbRe/Y/9Z1WHdG8kaIHg
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index a1cf107a9..ce197076b 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -94,6 +94,12 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"non_public",
{ data_type => "boolean", default_value => \"false", is_nullable => 1 },
+ "external_source",
+ { data_type => "text", is_nullable => 1 },
+ "external_source_id",
+ { data_type => "text", is_nullable => 1 },
+ "interest_count",
+ { data_type => "integer", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
@@ -540,9 +546,6 @@ sub meta_line {
}
- $meta .= '; ' . _('the map was not used so pin location may be inaccurate')
- unless $problem->used_map;
-
return $meta;
}
@@ -602,7 +605,7 @@ sub processed_summary_string {
}
if ($problem->can_display_external_id) {
if ($duration_clause) {
- $external_ref_clause = sprintf(_('their ref:&nbsp;%s'), $problem->external_id);
+ $external_ref_clause = sprintf(_('council ref:&nbsp;%s'), $problem->external_id);
} else {
$external_ref_clause = sprintf(_('%s ref:&nbsp;%s'), $problem->external_body, $problem->external_id);
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 2d206d84e..468df2654 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -94,7 +94,23 @@ sub email_alerts ($) {
}
# this is currently only for new_updates
if ($row->{item_text}) {
- $data{problem_url} = $url . "/report/" . $row->{id};
+ if ( $row->{alert_user_id} == $row->{user_id} ) {
+ # This is an alert to the same user who made the report - make this a login link
+ my $user = FixMyStreet::App->model('DB::User')->find( {
+ id => $row->{alert_user_id}
+ } );
+ $data{alert_email} = $user->email;
+ my $token_obj = FixMyStreet::App->model('DB::Token')->create( {
+ scope => 'email_sign_in',
+ data => {
+ email => $user->email,
+ r => 'report/' . $row->{id},
+ }
+ } );
+ $data{problem_url} = $url . "/M/" . $token_obj->token;
+ } else {
+ $data{problem_url} = $url . "/report/" . $row->{id};
+ }
$data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous};
$data{data} .= $row->{item_text} . "\n\n------\n\n";
# this is ward and council problems
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 2f426e8ca..bb826a5ca 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -310,8 +310,8 @@ sub send_reports {
foreach my $council (@councils) {
my $name = $areas_info->{$council}->{name};
- my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} );
- $sender = "FixMyStreet::SendReport::$sender";
+ my $sender_info = $cobrand->get_council_sender( $council, $areas_info->{$council}, $row->category );
+ my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
if ( ! exists $senders->{ $sender } ) {
warn "No such sender [ $sender ] for council $name ( $council )";
@@ -324,7 +324,7 @@ sub send_reports {
$reporters{ $sender }->skipped;
} else {
push @dear, $name;
- $reporters{ $sender }->add_council( $council, $areas_info->{$council} );
+ $reporters{ $sender }->add_council( $council, $areas_info->{$council}, $sender_info->{config} );
}
}
@@ -422,6 +422,21 @@ sub send_reports {
}
printf " %-24s %4d\n", "Total:", $c;
}
+ my $sending_errors = '';
+ my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
+ state => [ 'confirmed', 'fixed' ],
+ whensent => undef,
+ council => { '!=', undef },
+ send_fail_count => { '>', 0 }
+ } );
+ while (my $row = $unsent->next) {
+ $sending_errors .= "* http://www.fixmystreet.com/report/" . $row->id . ", failed "
+ . $row->send_fail_count . " times, last at " . $row->send_fail_timestamp
+ . ", reason " . $row->send_fail_reason . "\n";
+ }
+ if ($sending_errors) {
+ print "The following reports had problems sending:\n$sending_errors";
+ }
}
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index bbf0c9a9e..d6b3eb5cb 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -62,7 +62,9 @@ sub send_questionnaires_period {
($template = $period) =~ s/ //;
$template = Utils::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify );
} else {
- $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify;
+ $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $row->lang, "questionnaire.txt" )->stringify;
+ $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify
+ unless -e $template;
$template = FixMyStreet->path_to( "templates", "email", "default", "questionnaire.txt" )->stringify
unless -e $template;
$template = Utils::read_file( $template );
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm
index 197b2b1e7..d96338c16 100644
--- a/perllib/FixMyStreet/Geocode/OSM.pm
+++ b/perllib/FixMyStreet/Geocode/OSM.pm
@@ -18,6 +18,7 @@ use File::Path ();
use LWP::Simple qw($ua);
use Memcached;
use XML::Simple;
+use mySociety::Locale;
my $osmapibase = "http://www.openstreetmap.org/api/";
my $nominatimbase = "http://nominatim.openstreetmap.org/";
@@ -57,7 +58,7 @@ sub string {
}
if (!$js) {
- return { error => _('Sorry, we could not parse that location. Please try again.') };
+ return { error => _('Sorry, we could not find that location.') };
}
$js = JSON->new->utf8->allow_nonref->decode($js);
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index d36b91ffe..587c63d25 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -52,10 +52,6 @@ sub set_map_class {
$map_class = $str;
}
-sub header_js {
- return $map_class->header_js(@_);
-}
-
sub display_map {
return $map_class->display_map(@_);
}
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
index f750ef479..9ba507862 100644
--- a/perllib/FixMyStreet/SendReport.pm
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -39,8 +39,9 @@ sub add_council {
my $self = shift;
my $council = shift;
my $info = shift;
+ my $config = shift;
- $self->councils->{ $council } = $info;
+ $self->councils->{ $council } = { info => $info, config => $config };
}
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 654ed6b3a..b69436dd7 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -12,6 +12,7 @@ sub build_recipient_list {
my $all_confirmed = 1;
foreach my $council ( keys %{ $self->councils } ) {
+
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
area_id => $council,
@@ -32,7 +33,7 @@ sub build_recipient_list {
$self->unconfirmed_notes->{$council_email}{$row->category} = $note;
}
- push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ];
+ push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ];
$recips{$council_email} = 1;
}
@@ -45,7 +46,9 @@ sub get_template {
my $template = 'submit.txt';
$template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237;
- my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify;
+ 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 );
diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
index e1b914523..4a6f058fe 100644
--- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm
+++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
@@ -28,7 +28,7 @@ sub build_recipient_list {
#$note{$council_email}{$row->category} = $note;
}
- push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ];
+ push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{ info }->{name} ];
$recips{$council_email} = 1;
my $country = $self->councils->{$council}->{country};
diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm
index 0783a385b..810ee60e2 100644
--- a/perllib/FixMyStreet/SendReport/NI.pm
+++ b/perllib/FixMyStreet/SendReport/NI.pm
@@ -23,7 +23,7 @@ sub build_recipient_list {
$email = 'N/A' unless $email;
}
- my $name = $self->councils->{$council}->{name};
+ my $name = $self->councils->{$council}->{info}->{name};
if ( $email =~ /^roads.([^@]*)\@drdni/ ) {
$name = "Roads Service (\u$1)";
$h->{councils_name} = $name;
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 42c103b82..70bce3d47 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -28,7 +28,7 @@ sub send {
my $result = -1;
foreach my $council ( keys %{ $self->councils } ) {
- my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first;
+ my $conf = $self->councils->{$council}->{config};
my $always_send_latlong = 1;
my $send_notpinpointed = 0;
@@ -94,10 +94,15 @@ sub send {
$row->user->name( $row->user->id . ' ' . $row->user->name );
}
+ if ($row->cobrand eq 'fixmybarangay') {
+ # FixMyBarangay endpoints expect external_id as an attribute
+ $row->extra( [ { 'name' => 'external_id', 'value' => $row->id } ] );
+ }
+
my $resp = $open311->send_service_request( $row, $h, $contact->email );
# make sure we don't save user changes from above
- if ( $row->council =~ /2218/ || $row->council =~ /2482/ ) {
+ if ( $row->council =~ /2218/ || $row->council =~ /2482/ || $row->cobrand eq 'fixmybarangay') {
$row->discard_changes();
}
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 2a9c3ba7b..7f81c0fc2 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -460,6 +460,7 @@ sub visible_form_values {
grep { ref($_) ne 'HTML::Form::SubmitInput' }
grep { ref($_) ne 'HTML::Form::ImageInput' }
grep { ref($_) ne 'HTML::Form::TextInput' || $_->type ne 'hidden' }
+ grep { !$_->disabled }
$form->inputs;
my @visible_field_names = map { $_->name } @visible_fields;
@@ -534,12 +535,11 @@ sub delete_problems_for_council {
sub create_problems_for_council {
my ( $mech, $count, $council, $title, $params ) = @_;
- my $dt = DateTime->now() || $params->{dt};
+ my $dt = $params->{dt} || DateTime->now();
- my $user =
+ my $user = $params->{user} ||
FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test@example.com', name => 'Test User' } )
- or $params->{user};
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
delete $params->{user};
delete $params->{dt};