aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-04-27 07:29:48 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-04-28 13:29:39 +0100
commitf76f140d7dedbb9009e40e216da1f6d337f440e0 (patch)
tree74e8858f6db6243333c0711f4fdd304d6b270278
parent4edf5a8a9b46311b3889a5382dfd05f7caf1d792 (diff)
Error page when submitting /import with web param.
If the web param is used, show an error web page rather than the normal plain text output. Also do the normal remember/show uploaded photos feature, and hide the inputs better if unneeded.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm21
-rw-r--r--templates/web/base/report/new/report_import.html46
3 files changed, 44 insertions, 24 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3fb3a88ed..c0fdc6d42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@
- Move summary failures to a separate script.
- Add script to export/import body data.
- Add fetch script that does combined job of fetch-comments and fetch-reports.
+ - Show error page when submitting with web param to /import.
- Open311 improvements:
- match response templates on external status code over state
- Add flag to protect category/group names from Open311 overwrite.
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 516752b89..69d20171a 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -358,8 +358,7 @@ sub report_import : Path('/import') {
# If this is not a POST then just print out instructions for using page
return unless $c->req->method eq 'POST';
- # anything else we return is plain text
- $c->res->content_type('text/plain; charset=utf-8');
+ my $format = $c->get_param('web') ? 'web' : 'text';
my %input =
map { $_ => $c->get_param($_) || '' } (
@@ -412,8 +411,14 @@ sub report_import : Path('/import') {
# if we have errors then we should bail out
if (@errors) {
- my $body = join '', map { "ERROR:$_\n" } @errors;
- $c->res->body($body);
+ if ($format eq 'web') {
+ $c->stash->{input} = \%input;
+ $c->stash->{errors} = \@errors;
+ } else {
+ my $body = join '', map { "ERROR:$_\n" } @errors;
+ $c->res->content_type('text/plain; charset=utf-8');
+ $c->res->body($body);
+ }
return;
}
@@ -469,13 +474,13 @@ sub report_import : Path('/import') {
$c->send_email( 'partial.txt', { to => $report->user->email, } );
- if ( $c->get_param('web') ) {
- $c->res->content_type('text/html; charset=utf-8');
+ if ($format eq 'web') {
$c->stash->{template} = 'email_sent.html';
$c->stash->{email_type} = 'problem';
- return 1;
+ } else {
+ $c->res->content_type('text/plain; charset=utf-8');
+ $c->res->body('SUCCESS');
}
- $c->res->body('SUCCESS');
return 1;
}
diff --git a/templates/web/base/report/new/report_import.html b/templates/web/base/report/new/report_import.html
index f2ead081b..f68e21301 100644
--- a/templates/web/base/report/new/report_import.html
+++ b/templates/web/base/report/new/report_import.html
@@ -2,6 +2,8 @@
<h1>External import</h1>
+[% INCLUDE 'errors.html' %]
+
<p>You may inject problem reports into FixMyStreet programatically using this
simple interface. Upon receipt, an email will be sent to the address given,
with a link the user must click in order to check the details of their report,
@@ -14,12 +16,14 @@ line each starting with <samp>ERROR:</samp>.
<p>You may submit the following information by POST to this URL
(i.e. <samp>[% c.uri_for('/import') %]</samp> ):</p>
+[% IF NOT errors AND NOT c.req.params.web %]
<style type="text/css" media="screen">
input {
/* Hide the form elements - they are just here for simpler testing */
- display: none;
+ display: none !important;
}
</style>
+[% END %]
<form method="POST" action="/import" enctype="multipart/form-data">
@@ -28,66 +32,76 @@ line each starting with <samp>ERROR:</samp>.
<dd>
<em>Required</em>.
Name of application/service using this interface.
- <input type="text" name="service" />
+ <input type="text" name="service" value="[% input.service %]">
</dd>
<dt>id</dt>
<dd>
Unique ID of a user/device, for possible future use.<br>
<small>(e.g. used by Flickr import to know which accounts to look at)</small>
- <input type="text" name="id" />
+ <input type="text" name="id" value="[% input.id %]">
</dd>
<dt>subject</dt>
<dd>
<em>Required</em>. Subject of problem report.
- <input type="text" name="subject" />
+ <input type="text" name="subject" value="[% input.subject %]">
</dd>
<dt>detail</dt>
<dd>
Main body and details of problem report.
- <input type="text" name="detail" />
+ <input type="text" name="detail" value="[% input.detail %]">
</dd>
<dt>name</dt>
<dd>
<em>Required</em>. Name of problem reporter.
- <input type="text" name="name" />
+ <input type="text" name="name" value="[% input.name %]">
</dd>
<dt>email</dt>
<dd>
<em>Required</em>. Email address of problem reporter.
- <input type="text" name="email" />
+ <input type="text" name="email" value="[% input.email %]">
</dd>
<dt>phone</dt>
<dd>
Telephone number of problem reporter.
- <input type="text" name="phone" />
+ <input type="text" name="phone" value="[% input.phone %]">
</dd>
<dt>easting / northing</dt>
<dt>lat / lon</dt>
<dd>
Location of problem report. You can either supply eastings/northings, or WGS84 latitude/longitude.
- <input type="text" name="easting" />
- <input type="text" name="northing" />
- <input type="text" name="lat" />
- <input type="text" name="lon" />
+ <input type="text" name="easting" value="[% input.easting %]">
+ <input type="text" name="northing" value="[% input.northing %]">
+ <input type="text" name="lat" value="[% input.lat %]">
+ <input type="text" name="lon" value="[% input.lon %]">
</dd>
+ [% IF c.cobrand.allow_photo_upload %]
+ <input type="hidden" name="upload_fileid" value="[% upload_fileid %]">
+ [% IF upload_fileid %]
+ [% FOREACH id IN upload_fileid.split(',') %]
+ <img align="right" src="/photo/temp.[% id %]" alt="">
+ [% END %]
+ [% END %]
+
<dt>photo</dt>
<dd>
- Photo of problem (JPEG only).
+ Photo of problem.
<input type="file" name="photo" />
</dd>
+ [% END %]
+
</dl>
-<input type="hidden" name="web" value="0">
-<input type="submit" />
+<input type="hidden" name="web" value="[% c.req.params.web ? 1 : 0 %]">
+<input type="submit" value="[% loc('Submit') %]">
</form>
-[% INCLUDE 'footer.html' %] \ No newline at end of file
+[% INCLUDE 'footer.html' %]