<commit_before>class Admin::FactCheckRequestsController < Admin::BaseController
  before_filter :load_fact_check_request, only: [:show, :edit, :update]
  before_filter :load_edition, only: [:create]
  before_filter :enforce_permissions!, only: [:create]
  before_filter :check_edition_availability, only: [:show, :edit]
  skip_before_filter :authenticate_user!, except: [:create]
  skip_before_filter :require_signin_permission!, except: [:create]

  def load_edition
    @edition = Edition.unscoped.find(params[:edition_id])
  end

  def enforce_permissions!
    enforce_permission!(:make_fact_check, @edition)
  end

  def show
  end

  def create
    unless @edition.accessible_by?(current_user)
      render "admin/editions/forbidden", status: 403
      return
    end
    attributes = params[:fact_check_request].merge(requestor: current_user)
    fact_check_request = @edition.fact_check_requests.build(attributes)
    if @edition.deleted?
      render "edition_unavailable"
    elsif fact_check_request.save
      Notifications.fact_check_request(fact_check_request, mailer_url_options).deliver
      notice = "The policy has been sent to #{fact_check_request.email_address}"
      redirect_to admin_edition_path(@edition), notice: notice
    else
      alert = "There was a problem: #{fact_check_request.errors.full_messages.to_sentence}"
      redirect_to admin_edition_path(@edition), alert: alert
    end
  end

  def edit
  end

  def update
    if @fact_check_request.update_attributes(params[:fact_check_request])
      if @fact_check_request.requestor_contactable?
        Notifications.fact_check_response(@fact_check_request, mailer_url_options).deliver
      end
      notice = "Your feedback has been saved"
      redirect_to admin_fact_check_request_path(@fact_check_request), notice: notice
    else
      render "edition_unavailable"
    end
  end

  private

  def mailer_url_options
    options = { host: request.host }<commit_msg>Update fact check message to be more generic<commit_after>class Admin::FactCheckRequestsController < Admin::BaseController
  before_filter :load_fact_check_request, only: [:show, :edit, :update]
  before_filter :load_edition, only: [:create]
  before_filter :enforce_permissions!, only: [:create]
  before_filter :check_edition_availability, only: [:show, :edit]
  skip_before_filter :authenticate_user!, except: [:create]
  skip_before_filter :require_signin_permission!, except: [:create]

  def load_edition
    @edition = Edition.unscoped.find(params[:edition_id])
  end

  def enforce_permissions!
    enforce_permission!(:make_fact_check, @edition)
  end

  def show
  end

  def create
    unless @edition.accessible_by?(current_user)
      render "admin/editions/forbidden", status: 403
      return
    end
    attributes = params[:fact_check_request].merge(requestor: current_user)
    fact_check_request = @edition.fact_check_requests.build(attributes)
    if @edition.deleted?
      render "edition_unavailable"
    elsif fact_check_request.save
      Notifications.fact_check_request(fact_check_request, mailer_url_options).deliver
      notice = "The document has been sent to #{fact_check_request.email_address}"
      redirect_to admin_edition_path(@edition), notice: notice
    else
      alert = "There was a problem: #{fact_check_request.errors.full_messages.to_sentence}"
      redirect_to admin_edition_path(@edition), alert: alert
    end
  end

  def edit
  end

  def update
    if @fact_check_request.update_attributes(params[:fact_check_request])
      if @fact_check_request.requestor_contactable?
        Notifications.fact_check_response(@fact_check_request, mailer_url_options).deliver
      end
      notice = "Your feedback has been saved"
      redirect_to admin_fact_check_request_path(@fact_check_request), notice: notice
    else
      render "edition_unavailable"
    end
  end

  private

  def mailer_url_options
    options = { host: request.host }
{'fraction_non_alphanumeric': 0.08267816383464367, 'fraction_numerical': 0.001521683996956632, 'mean_word_length': 4.666666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6716423', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1211, 'n_words': 255}