aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm91
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm91
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Root.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/Barnet.pm11
7 files changed, 103 insertions, 98 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 5d5832b08..a6717fc33 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
use DateTime::Format::HTTP;
+use Digest::SHA1 qw(sha1_hex);
use Path::Class;
=head1 NAME
@@ -136,6 +137,96 @@ sub _crop {
return $blobs[0];
}
+=head2 process_photo
+
+Handle the photo - either checking and storing it after an upload or retrieving
+it from the cache.
+
+Store any error message onto 'photo_error' in stash.
+=cut
+
+sub process_photo : Private {
+ my ( $self, $c ) = @_;
+
+ return
+ $c->forward('process_photo_upload')
+ || $c->forward('process_photo_cache')
+ || 1; # always return true
+}
+
+sub process_photo_upload : Private {
+ my ( $self, $c ) = @_;
+
+ # check for upload or return
+ my $upload = $c->req->upload('photo')
+ || return;
+
+ # check that the photo is a jpeg
+ my $ct = $upload->type;
+ $ct =~ s/x-citrix-//; # Thanks, Citrix
+ # Had a report of a JPEG from an Android 2.1 coming through as a byte stream
+ unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' || $ct eq 'application/octet-stream' ) {
+ $c->log->info('Bad photo tried to upload, type=' . $ct);
+ $c->stash->{photo_error} = _('Please upload a JPEG image only');
+ return;
+ }
+
+ # get the photo into a variable
+ my $photo_blob = eval {
+ my $filename = $upload->tempname;
+ my $out = `jhead -se -autorot $filename 2>&1`;
+ die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/;
+ my $photo = $upload->slurp;
+ return $photo;
+ };
+ if ( my $error = $@ ) {
+ my $format = _(
+"That image doesn't appear to have uploaded correctly (%s), please try again."
+ );
+ $c->stash->{photo_error} = sprintf( $format, $error );
+ return;
+ }
+
+ # we have an image we can use - save it to the upload dir for storage
+ my $cache_dir = dir( $c->config->{UPLOAD_DIR} );
+ $cache_dir->mkpath;
+ unless ( -d $cache_dir && -w $cache_dir ) {
+ warn "Can't find/write to photo cache directory '$cache_dir'";
+ return;
+ }
+
+ my $fileid = sha1_hex($photo_blob);
+ $upload->copy_to( file($cache_dir, $fileid . '.jpeg') );
+
+ # stick the hash on the stash, so don't have to reupload in case of error
+ $c->stash->{upload_fileid} = $fileid;
+
+ return 1;
+}
+
+=head2 process_photo_cache
+
+Look for the upload_fileid parameter and check it matches a file on disk. If it
+does return true and put fileid on stash, otherwise false.
+
+=cut
+
+sub process_photo_cache : Private {
+ my ( $self, $c ) = @_;
+
+ # get the fileid and make sure it is just a hex number
+ my $fileid = $c->req->param('upload_fileid') || '';
+ $fileid =~ s{[^0-9a-f]}{}gi;
+ return unless $fileid;
+
+ my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" );
+ return unless -e $file;
+
+ $c->stash->{upload_fileid} = $fileid;
+ return 1;
+}
+
+
=head1 AUTHOR
Struan Donald
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index 6ed7ddd9d..fe71f3fbb 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -244,7 +244,7 @@ sub process_questionnaire : Private {
push @errors, _('Please provide some explanation as to why you\'re reopening this report')
if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update};
- $c->forward('/report/new/process_photo');
+ $c->forward('/photo/process_photo');
push @errors, $c->stash->{photo_error}
if $c->stash->{photo_error};
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 4dac4d30f..5f067573b 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -5,7 +5,6 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Geocode;
-use Digest::SHA1 qw(sha1_hex);
use Encode;
use Image::Magick;
use List::MoreUtils qw(uniq);
@@ -99,7 +98,7 @@ sub report_new : Path : Args(0) {
return unless $c->forward('check_form_submitted');
$c->forward('process_user');
$c->forward('process_report');
- $c->forward('process_photo');
+ $c->forward('/photo/process_photo');
return unless $c->forward('check_for_errors');
$c->forward('save_user_and_report');
$c->forward('redirect_or_confirm_creation');
@@ -215,7 +214,7 @@ sub report_import : Path('/import') {
}
# handle the photo upload
- $c->forward( 'process_photo_upload' );
+ $c->forward( '/photo/process_photo_upload' );
my $fileid = $c->stash->{upload_fileid};
if ( my $error = $c->stash->{photo_error} ) {
push @errors, $error;
@@ -844,92 +843,6 @@ sub process_report : Private {
return 1;
}
-=head2 process_photo
-
-Handle the photo - either checking and storing it after an upload or retrieving
-it from the cache.
-
-Store any error message onto 'photo_error' in stash.
-=cut
-
-sub process_photo : Private {
- my ( $self, $c ) = @_;
-
- return
- $c->forward('process_photo_upload')
- || $c->forward('process_photo_cache')
- || 1; # always return true
-}
-
-sub process_photo_upload : Private {
- my ( $self, $c ) = @_;
-
- # check for upload or return
- my $upload = $c->req->upload('photo')
- || return;
-
- # check that the photo is a jpeg
- my $ct = $upload->type;
- unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) {
- $c->log->info('Bad photo tried to upload, type=' . $ct);
- $c->stash->{photo_error} = _('Please upload a JPEG image only');
- return;
- }
-
- # get the photo into a variable
- my $photo_blob = eval {
- my $filename = $upload->tempname;
- my $out = `jhead -se -autorot $filename`;
- my $photo = $upload->slurp;
- return $photo;
- };
- if ( my $error = $@ ) {
- my $format = _(
-"That image doesn't appear to have uploaded correctly (%s), please try again."
- );
- $c->stash->{photo_error} = sprintf( $format, $error );
- return;
- }
-
- # we have an image we can use - save it to the upload dir for storage
- my $cache_dir = dir( $c->config->{UPLOAD_DIR} );
- $cache_dir->mkpath;
- unless ( -d $cache_dir && -w $cache_dir ) {
- warn "Can't find/write to photo cache directory '$cache_dir'";
- return;
- }
-
- my $fileid = sha1_hex($photo_blob);
- $upload->copy_to( file($cache_dir, $fileid . '.jpeg') );
-
- # stick the hash on the stash, so don't have to reupload in case of error
- $c->stash->{upload_fileid} = $fileid;
-
- return 1;
-}
-
-=head2 process_photo_cache
-
-Look for the upload_fileid parameter and check it matches a file on disk. If it
-does return true and put fileid on stash, otherwise false.
-
-=cut
-
-sub process_photo_cache : Private {
- my ( $self, $c ) = @_;
-
- # get the fileid and make sure it is just a hex number
- my $fileid = $c->req->param('upload_fileid') || '';
- $fileid =~ s{[^0-9a-f]}{}gi;
- return unless $fileid;
-
- my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" );
- return unless -e $file;
-
- $c->stash->{upload_fileid} = $fileid;
- return 1;
-}
-
=head2 check_for_errors
Examine the user and the report for errors. If found put them on stash and
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 7542fbe96..5b0dad170 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -23,7 +23,7 @@ sub report_update : Path : Args(0) {
$c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] );
$c->forward('process_update');
$c->forward('process_user');
- $c->forward('/report/new/process_photo');
+ $c->forward('/photo/process_photo');
$c->forward('check_for_errors')
or $c->go( '/report/display', [ $c->req->param('id') ] );
diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm
index 9cdf0b523..7f7d7f5fd 100644
--- a/perllib/FixMyStreet/App/Controller/Root.pm
+++ b/perllib/FixMyStreet/App/Controller/Root.pm
@@ -68,7 +68,7 @@ Forward to the standard 404 error page
sub default : Path {
my ( $self, $c ) = @_;
- $c->detach('/page_error_404_not_found');
+ $c->detach('/page_error_404_not_found', []);
}
=head2 page_error_404_not_found, page_error_410_gone
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index b8aea8697..9cbaef6c2 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -578,7 +578,7 @@ 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 eq 'barnet') {
+ if ($self->external_id && $self->send_method_used && $self->send_method_used eq 'barnet') {
return 1;
}
return 0;
diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm
index 3eb8d2048..9a54dd91d 100644
--- a/perllib/FixMyStreet/SendReport/Barnet.pm
+++ b/perllib/FixMyStreet/SendReport/Barnet.pm
@@ -68,17 +68,18 @@ sub send {
my $interface = BarnetInterfaces::service::ZLBB_SERVICE_ORDER->new();
- my ($nearest_postcode, $nearest_street);
+ my ($nearest_postcode, $nearest_street) = ('', '');
for ($h{closest_address}) {
$nearest_postcode = sprintf("%-10s", $1) if /Nearest postcode [^:]+: ((\w{1,4}\s?\w+|\w+))/;
# use partial postcode or comma as delimiter, strip leading number (possible letter 221B) off too
# "99 Foo Street, London N11 1XX" becomes Foo Street
# "99 Foo Street N11 1XX" becomes Foo Street
- $nearest_street = sprintf("%-30s", $1) if /Nearest road [^:]+: (?:\d+\w? )?(.*?)(\b[A-Z]+\d|,|$)/m;
+ $nearest_street = $1 if /Nearest road [^:]+: (?:\d+\w? )?(.*?)(\b[A-Z]+\d|,|$)/m;
}
- my $postcode = $h{postcode} || $nearest_postcode; # use given postcode if available
+ my $postcode = mySociety::PostcodeUtil::is_valid_postcode($h{query})
+ ? $h{query} : $nearest_postcode; # use given postcode if available
- # note: endpoint can be of form 'https://username:password@:url'
+ # note: endpoint can be of form 'https://username:password@url'
my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => COUNCIL_ID_BARNET} )->first;
if ($council_config and $council_config->endpoint) {
$interface->set_proxy($council_config->endpoint);
@@ -116,7 +117,7 @@ sub send {
COUNTY => "", # char30
CITY => "", # char30
POSTALCODE => $postcode, # char10
- STREET => $nearest_street, # char30
+ STREET => truncate_string_with_entities(ent(encode_utf8($nearest_street)), 30), # char30
STREETNUMBER => "", # char5
GEOCODE => $geo_code, # char32
},