1class Admin::TakeDownController < Admin::AdminController
 
2  before_action :fetch_petition
 
3
 
4  def show
 
5    render 'admin/petitions/show'
 
6  end
 
7
 
8  def update
 
 9    if @petition.reject(rejection_params[:rejection])
 
10      send_notifications
 
11      redirect_to [:admin, @petition]
 
12    else
 
13      render 'admin/petitions/show'
 
14    end
 
15  end
 
 
17  private
 
 
19  def fetch_petition
 
20    @petition = Petition.find(params[:petition_id])
 
21  end
 
 
23  def rejection_params
 
24    params.require(:petition).permit(rejection: [:code, :details])
 
25  end
 
 
27  def send_notifications
 
28    if send_email_to_creator_and_sponsors?
 
29      NotifyEveryoneOfModerationDecisionJob.perform_later(@petition)
 
30    end
 
31  end
 
 
33  def send_email_to_creator_and_sponsors?
 
34    params.key?(:save_and_email)
 
35  end
 
36end