diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-04-22 09:02:42 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-05-04 16:39:19 +0100 |
commit | 63df5a61f7be9da0498a036a18f8b01e69f103cf (patch) | |
tree | 1b23db349f1cad37d815a075ed340015c2ec7e4b /perllib | |
parent | dfdfa76375e39274d6b8ff2a06954b4d5530586d (diff) |
Allow template to be an initial update on reports.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 69d20171a..fc1a78cd5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -158,7 +158,7 @@ sub report_new_ajax : Path('mobile') : Args(0) { my $report = $c->stash->{report}; if ( $report->confirmed ) { - $c->forward( 'create_reporter_alert' ); + $c->forward( 'create_related_things' ); $c->stash->{ json_response } = { success => 1, report => $report->id }; } else { $c->forward( 'send_problem_confirm_email' ); @@ -1363,7 +1363,7 @@ sub process_confirmation : Private { ); # Subscribe problem reporter to email updates - $c->forward( '/report/new/create_reporter_alert' ); + $c->forward( '/report/new/create_related_things' ); # log the problem creation user in to the site if ( $data->{name} || $data->{password} ) { @@ -1623,7 +1623,7 @@ sub redirect_or_confirm_creation : Private { # If confirmed send the user straight there. if ( $report->confirmed ) { # Subscribe problem reporter to email updates - $c->forward( 'create_reporter_alert' ); + $c->forward( 'create_related_things' ); if ($c->stash->{contributing_as_another_user} && $report->user->email && $report->user->id != $c->user->id && !$c->cobrand->report_sent_confirmation_email) { @@ -1665,13 +1665,51 @@ sub redirect_or_confirm_creation : Private { $c->log->info($report->user->id . ' created ' . $report->id . ", $thing sent, " . ($c->stash->{token_data}->{password} ? 'password set' : 'password not set')); } -sub create_reporter_alert : Private { +sub create_related_things : Private { my ( $self, $c ) = @_; + my $problem = $c->stash->{report}; + + # If there is a special template, create a comment using that + foreach my $body (values %{$problem->bodies}) { + my $user = $body->comment_user or next; + + my %open311_conf = ( + endpoint => $body->endpoint || '', + api_key => $body->api_key || '', + jurisdiction => $body->jurisdiction || '', + extended_statuses => $body->send_extended_statuses, + ); + + my $cobrand = $body->get_cobrand_handler; + $cobrand->call_hook(open311_config_updates => \%open311_conf) + if $cobrand; + + my $open311 = Open311->new(%open311_conf); + my $updates = Open311::GetServiceRequestUpdates->new( + system_user => $user, + current_open311 => $open311, + current_body => $body, + blank_updates_permitted => 1, + ); + + my $description = $updates->comment_text_for_request({}, $problem, 'confirmed', 'dummy', '', ''); + next unless $description; + + my $request = { + service_request_id => $problem->id, + update_id => 'auto-internal', + comment_time => DateTime->now, + status => 'open', + description => $description, + }; + $updates->process_update($request, $problem); + } + + # And now the reporter alert return if $c->stash->{no_reporter_alert}; return if $c->cobrand->call_hook('suppress_reporter_alerts'); - my $problem = $c->stash->{report}; my $alert = $c->model('DB::Alert')->find_or_create( { user => $problem->user, alert_type => 'new_updates', |