aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm36
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm8
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm7
-rw-r--r--perllib/FixMyStreet/SendReport/Zurich.pm53
6 files changed, 95 insertions, 21 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 0a2a8830c..848871f69 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -312,7 +312,7 @@ sub update_contacts : Private {
my ( $self, $c ) = @_;
my $posted = $c->req->param('posted');
- my $editor = $c->req->remote_user || ($c->user && $c->user->name) || _('*unknown*');
+ my $editor = $c->forward('get_user');
if ( $posted eq 'new' ) {
$c->forward('check_token');
@@ -590,11 +590,7 @@ sub report_edit : Path('report_edit') : Args(1) {
my $site_restriction = $c->cobrand->site_restriction;
- my $problem = $c->cobrand->problems->search(
- {
- id => $id,
- }
- )->first;
+ my $problem = $c->cobrand->problems->search( { id => $id } )->first;
$c->detach( '/page_error_404_not_found' )
unless $problem;
@@ -603,6 +599,11 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->forward('get_token');
+ if ( $c->req->param('rotate_photo') ) {
+ $c->forward('rotate_photo');
+ return 1;
+ }
+
if ( $c->cobrand->moniker eq 'zurich' ) {
my $done = $c->cobrand->admin_report_edit();
return if $done;
@@ -636,9 +637,6 @@ sub report_edit : Path('report_edit') : Args(1) {
elsif ( $c->req->param('banuser') ) {
$c->forward('ban_user');
}
- elsif ( $c->req->param('rotate_photo') ) {
- $c->forward('rotate_photo');
- }
elsif ( $c->req->param('submit') ) {
$c->forward('check_token');
@@ -1061,6 +1059,16 @@ sub set_allowed_pages : Private {
return 1;
}
+sub get_user : Private {
+ my ( $self, $c ) = @_;
+
+ my $user = $c->req->remote_user();
+ $user ||= ($c->user && $c->user->name);
+ $user ||= '';
+
+ return $user;
+}
+
=item get_token
Generate a token based on user and secret
@@ -1071,12 +1079,8 @@ sub get_token : Private {
my ( $self, $c ) = @_;
my $secret = $c->model('DB::Secret')->search()->first;
-
- my $user = $c->req->remote_user();
- $user ||= '';
-
+ my $user = $c->forward('get_user');
my $token = md5_hex(($user . $secret->secret));
-
$c->stash->{token} = $token;
return 1;
@@ -1103,7 +1107,7 @@ sub check_token : Private {
$c->forward( 'log_edit', [ $object_id, $object_type, $action_performed ] );
-Adds an entry into the admin_log table using the current remote_user.
+Adds an entry into the admin_log table using the current user.
=cut
@@ -1111,7 +1115,7 @@ sub log_edit : Private {
my ( $self, $c, $id, $object_type, $action ) = @_;
$c->model('DB::AdminLog')->create(
{
- admin_user => ( $c->req->remote_user() || '' ),
+ admin_user => $c->forward('get_user'),
object_type => $object_type,
action => $action,
object_id => $id,
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 3a6986134..5b53c5dbf 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -147,7 +147,7 @@ sub report_new_ajax : Path('mobile') : Args(0) {
} else {
$c->stash->{token_url} = $c->uri_for_email( '/P', $token->token );
$c->send_email( 'problem-confirm.txt', {
- to => [ [ $report->user->email, $report->name ] ],
+ to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ],
} );
$c->stash->{ json_response } = { success => 1 };
}
@@ -1125,7 +1125,7 @@ sub redirect_or_confirm_creation : Private {
} );
$c->stash->{token_url} = $c->uri_for_email( '/P', $token->token );
$c->send_email( 'problem-confirm.txt', {
- to => [ [ $report->user->email, $report->name ] ],
+ to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ],
} );
# tell user that they've been sent an email
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index d70e785d7..4857dde03 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -38,6 +38,11 @@ sub show_unconfirmed_reports {
1;
}
+sub get_body_sender {
+ my ( $self, $body, $category ) = @_;
+ return { method => 'Zurich' };
+}
+
# Specific administrative displays
sub admin_pages {
@@ -186,6 +191,8 @@ sub admin_report_edit {
$extra->{internal_notes} = $c->req->param('internal_notes');
$extra->{publish_photo} = $c->req->params->{publish_photo} || 0;
$extra->{third_personal} = $c->req->params->{third_personal} || 0;
+ # Make sure we have a copy of the original detail field
+ $extra->{original_detail} = $problem->detail unless $extra->{original_detail};
$problem->extra( { %$extra } );
# Workflow things
@@ -293,6 +300,7 @@ sub admin_report_edit {
# If they clicked the no more updates button, we're done.
if ($c->req->param('no_more_updates')) {
$problem->bodies_str( $body->parent->id );
+ $problem->whensent( undef );
$problem->state( 'planned' );
$problem->update;
# log here
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 6cecdea7e..897a7e732 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -222,8 +222,10 @@ sub send_reports {
my $base_url = mySociety::Config::get('BASE_URL');
my $site = CronFns::site($base_url);
+ my $states = [ 'confirmed', 'fixed' ];
+ $states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed' ] if $site eq 'zurich';
my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
- state => [ 'confirmed', 'fixed' ],
+ state => $states,
whensent => undef,
bodies_str => { '!=', undef },
} );
@@ -252,10 +254,12 @@ sub send_reports {
my $email_base_url = $cobrand->base_url_for_report($row);
my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/;
map { $h{$_} = $row->user->$_ } qw/email phone/;
- $h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) );
+ $h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) )
+ if $row->confirmed;
$h{query} = $row->postcode;
$h{url} = $email_base_url . $row->url;
+ $h{admin_url} = $cobrand->admin_base_url . 'report_edit/' . $row->id;
$h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : '';
if ($row->photo) {
$h{has_photo} = _("This web page also contains a photo of the problem, provided by the user.") . "\n\n";
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index b7c15a643..2a580c0d5 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -55,6 +55,11 @@ sub get_template {
return $template;
}
+sub send_from {
+ my ( $self, $row ) = @_;
+ return [ $row->user->email, $row->name ];
+}
+
sub send {
my $self = shift;
my ( $row, $h ) = @_;
@@ -77,7 +82,7 @@ sub send {
_template_ => $self->get_template( $row ),
_parameters_ => $h,
To => $self->to,
- From => [ $row->user->email, $row->name ],
+ From => $self->send_from( $row ),
},
mySociety::Config::get('CONTACT_EMAIL'),
\@recips,
diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm
new file mode 100644
index 000000000..7bf6fe1a3
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Zurich.pm
@@ -0,0 +1,53 @@
+package FixMyStreet::SendReport::Zurich;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport::Email'; }
+
+sub build_recipient_list {
+ my ( $self, $row, $h ) = @_;
+
+ # Only one body ever, most of the time with an email endpoint
+ my $body = @{ $self->bodies }[0];
+ my $body_email = $body->endpoint;
+
+ my @bodies = $body->bodies;
+ if ($body->parent && @bodies) {
+ # Division, might have an individual contact email address
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ body_id => $body->id,
+ category => $row->category
+ } );
+ $body_email = $contact->email if $contact->email;
+ }
+
+ push @{ $self->to }, [ $body_email, $body->name ];
+ return $body_email;
+}
+
+sub get_template {
+ my ( $self, $row ) = @_;
+
+ my $template;
+ if ( $row->state eq 'unconfirmed' || $row->state eq 'confirmed' ) {
+ $template = 'submit.txt';
+ } elsif ( $row->state eq 'in progress' ) {
+ $template = 'submit-in-progress.txt';
+ } elsif ( $row->state eq 'planned' ) {
+ $template = 'submit-feedback-pending.txt';
+ } elsif ( $row->state eq 'closed' ) {
+ $template = 'submit-external.txt';
+ }
+
+ my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify;
+ $template = Utils::read_file( $template_path );
+ return $template;
+}
+
+# Zurich emails come from the site itself
+sub send_from {
+ my ( $self, $row ) = @_;
+ return [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ];
+}
+
+1;