|
1class Admin::Archived::GovernmentResponseController < Admin::AdminController
|
|
2 before_action :fetch_petition
|
|
3 before_action :fetch_government_response
|
|
|
|
5 rescue_from ActiveRecord::RecordNotUnique do
|
|
6 @government_response = @petition.government_response(true) and update
|
|
|
|
|
|
|
|
10 render 'admin/archived/petitions/show'
|
|
|
|
|
|
|
|
14 if @government_response.update(government_response_params)
|
|
15 if send_email_to_petitioners?
|
|
16 ::Archived::EmailThresholdResponseJob.run_later_tonight(petition: @petition)
|
|
17 message = :email_sent_overnight
|
|
|
|
19 message = :government_response_updated
|
|
|
|
|
|
22 redirect_to admin_archived_petition_url(@petition), notice: message
|
|
|
|
24 render 'admin/archived/petitions/show'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 @petition = ::Archived::Petition.moderated.find(params[:petition_id])
|
|
|
|
|
|
34 def fetch_government_response
|
|
35 @government_response = @petition.government_response || @petition.build_government_response
|
|
|
|
|
|
38 def government_response_params
|
|
39 params.require(:archived_government_response).permit(:responded_on, :summary, :details)
|
|
|
|
|
|
42 def send_email_to_petitioners?
|
|
43 params.key?(:save_and_email)
|
|
|
|
|