aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm28
-rw-r--r--t/cobrand/zurich-logo_portal.x.jpgbin0 -> 365 bytes
-rw-r--r--t/cobrand/zurich.t51
-rw-r--r--t/cobrand/zurich_attachments.txt53
4 files changed, 130 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index ca92470f2..3c1baaa48 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -670,6 +670,32 @@ sub _admin_send_email {
} );
}
+sub munge_sendreport_params {
+ my ($self, $c, $row, $h, $params) = @_;
+ if ($row->state =~ /^(closed|investigating)$/ && $row->get_extra_metadata('publish_photo')) {
+ # we attach images to reports sent to external bodies
+ my $photoset = $row->get_photoset($c);
+ my @images = $photoset->all_images
+ or return;
+ my $index = 0;
+ my $id = $row->id;
+ my @attachments = map {
+ my $i = $index++;
+ {
+ body => $_->[1],
+ attributes => {
+ filename => "$id.$i.jpeg",
+ content_type => 'image/jpeg',
+ encoding => 'base64',
+ # quoted-printable ends up with newlines corrupting binary data
+ name => "$id.$i.jpeg",
+ },
+ }
+ } @images;
+ $params->{attachments} = \@attachments;
+ }
+}
+
sub admin_fetch_all_bodies {
my ( $self, @bodies ) = @_;
@@ -761,7 +787,7 @@ sub admin_stats {
# replace newlines with HTML <br/> element
$detail =~ s{\r?\n}{ <br/> }g;
- $public_response =~ s{\r?\n}{ <br/> }g;
+ $public_response =~ s{\r?\n}{ <br/> }g if $public_response;
# Assemble photo URL, if report has a photo
my $media_url = $report->get_photo_params->{url} ? ($c->cobrand->base_url . $report->get_photo_params->{url}) : '';
diff --git a/t/cobrand/zurich-logo_portal.x.jpg b/t/cobrand/zurich-logo_portal.x.jpg
new file mode 100644
index 000000000..c0cfef240
--- /dev/null
+++ b/t/cobrand/zurich-logo_portal.x.jpg
Binary files differ
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index ffee28259..02f502d31 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -5,6 +5,7 @@ use strict;
use warnings;
use DateTime;
use Test::More;
+use Test::LongString;
use JSON;
use Path::Tiny;
@@ -29,7 +30,10 @@ my $sample_photo = $sample_file->slurp_raw;
# This is a helper method that will send the reports but with the config
# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true.
sub send_reports_for_zurich {
- FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub {
+ FixMyStreet::override_config {
+ SEND_REPORTS_ON_STAGING => 1,
+ ALLOWED_COBRANDS => ['zurich']
+ }, sub {
# Actually send the report
$c->model('DB::Problem')->send_reports('zurich');
};
@@ -41,6 +45,7 @@ sub reset_report_state {
delete $extra->{moderated_overdue};
delete $extra->{subdiv_overdue};
delete $extra->{closed_overdue};
+ $report->whensent(undef);
$report->update({
extra => { %$extra },
state => 'unconfirmed',
@@ -715,6 +720,50 @@ subtest "test admin_log" => sub {
is $entries[-1]->action, 'state change to hidden', 'State change logged as expected';
};
+subtest 'email images to external partners' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ reset_report_state($report);
+
+ my $photo = path(__FILE__)->parent->child('zurich-logo_portal.x.jpg')->slurp_raw;
+ my $photoset = FixMyStreet::App::Model::PhotoSet->new({
+ c => $c,
+ data_items => [ $photo ],
+ });
+ my $fileid = $photoset->data;
+
+ $report->set_extra_metadata('publish_photo' => 1);
+ $report->update({
+ state => 'closed',
+ photo => $fileid,
+ external_body => $external_body->id,
+ });
+
+ $mech->clear_emails_ok;
+ send_reports_for_zurich();
+
+ my @emails = $mech->get_email;
+ my $email_as_string = $mech->get_first_email(@emails);
+ my ($boundary) = $email_as_string =~ /boundary="([A-Za-z0-9.]*)"/ms;
+ my $changes = $email_as_string =~ s{$boundary}{}g;
+ is $changes, 4, '4 boundaries'; # header + 3 around the 2x parts (text + 1 image)
+
+ my $expected_email_content = path(__FILE__)->parent->child('zurich_attachments.txt')->slurp;
+
+ my $REPORT_ID = $report->id;
+ $expected_email_content =~ s{REPORT_ID}{$REPORT_ID}g;
+
+ is_string $email_as_string, $expected_email_content, 'MIME email text ok'
+ or do {
+ (my $test_name = $0) =~ s{/}{_}g;
+ my $path = path("test-output-$test_name.tmp");
+ $path->spew($email_as_string);
+ diag "Saved output in $path";
+ };
+ };
+};
+
END {
$mech->delete_body($subdivision);
$mech->delete_body($division);
diff --git a/t/cobrand/zurich_attachments.txt b/t/cobrand/zurich_attachments.txt
new file mode 100644
index 000000000..dc3b64d45
--- /dev/null
+++ b/t/cobrand/zurich_attachments.txt
@@ -0,0 +1,53 @@
+MIME-Version: 1.0
+Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
+Content-Type: multipart/mixed; boundary=""
+To: "External Body" <external_body@example.org>
+Content-Transfer-Encoding: 7bit
+From: FixMyStreet <division@example.org>
+
+
+--
+MIME-Version: 1.0
+Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
+Content-Type: text/plain; charset="iso-8859-1"
+To: "External Body" <external_body@example.org>
+Content-Transfer-Encoding: quoted-printable
+From: FixMyStreet <division@example.org>
+
+Gr=FCezi External Body,
+
+Die folgende Meldung wurde auf
+http://www.stadt-zuerich.ch/zueriwieneu erfasst:
+
+=D6ffentliche URL: http://www.example.org/report/REPORT_ID
+
+"Z=FCri wie neu" ist eine Dienstleistung der Stadt Z=FCrich zum Thema
+B=FCrgerbeteiligung. Auf dieser Plattform kann die Bev=F6lkerung auf
+Sch=E4den und M=E4ngel an der st=E4dtischen Infrastruktur hinweisen. Diese
+Meldung wurde Ihnen von der Stadt Z=FCrich gesendet, da es Ihr
+Zust=E4ndigkeitsgebiet betreffen k=F6nnte.
+
+Bei Fragen zu "Z=FCri wie neu" wenden Sie sich bitte an
+gis-zentrum@zuerich.ch.
+
+Freundliche Gr=FCsse
+
+Ihre Stadt Z=FCrich=20=
+
+
+
+--
+MIME-Version: 1.0
+Content-Type: image/jpeg; name="REPORT_ID.0.jpeg"
+Content-Disposition: inline; filename="REPORT_ID.0.jpeg"
+Content-Transfer-Encoding: base64
+
+/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP
+ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e
+Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABTAAEDAREA
+AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAIIB//EAB8QAQAABAcAAAAAAAAAAAAAAAADBAbT
+BxcYVVaUpf/EABcBAQEBAQAAAAAAAAAAAAAAAAAFBgT/xAAgEQEAAAQHAQAAAAAAAAAAAAAAAwQV
+UgECFlNhodGx/9oADAMBAAIRAxEAPwCywAIozyxS5R58tbbujSW33j6zFRj3fGbKbjAGAgAACs9N
+FCbtUfYg2mO1BM25e/V+lQeW3ISo/9k=
+
+----