<commit_before>class SponsorsController < ApplicationController
  before_action :retrieve_petition
  before_action :validate_token_and_petition_match

  respond_to :html

  def show
    if @petition.hidden?
      raise ActiveRecord::RecordNotFound
    elsif @petition.rejected? || @petition.closed?
      redirect_to petition_url(@petition)
    elsif @petition.open?
      redirect_to sign_petition_signatures_url(@petition)
    elsif @petition.has_maximum_sponsors?
      redirect_to moderation_info_petition_url(@petition)
    else
      assign_stage
      @sponsor = @petition.sponsors.build
      @stage_manager = Staged::PetitionSigner.manage(signature_params_for_new, @petition, params[:stage], params[:move])
    end
  end

  def update
    assign_stage
    @stage_manager = Staged::PetitionSigner.manage(signature_params_for_create, @petition, params[:stage], params[:move])
    if @stage_manager.create_signature
      @signature = @stage_manager.signature
      @sponsor = @petition.sponsors.create(signature: @signature)
      send_email_to_sponsor(@sponsor)
      redirect_to thank_you_petition_sponsor_url(@petition, token: @petition.sponsor_token)
    else
      render :show
    end
  end

  def thank_you
  end

  def sponsored<commit_msg>Changed sponsor redirect to show rather than sign post moderation<commit_after>class SponsorsController < ApplicationController
  before_action :retrieve_petition
  before_action :validate_token_and_petition_match

  respond_to :html

  def show
    if @petition.hidden?
      raise ActiveRecord::RecordNotFound
    elsif @petition.rejected? || @petition.closed? || @petition.open?
      redirect_to petition_url(@petition)
    elsif @petition.has_maximum_sponsors?
      redirect_to moderation_info_petition_url(@petition)
    else
      assign_stage
      @sponsor = @petition.sponsors.build
      @stage_manager = Staged::PetitionSigner.manage(signature_params_for_new, @petition, params[:stage], params[:move])
    end
  end

  def update
    assign_stage
    @stage_manager = Staged::PetitionSigner.manage(signature_params_for_create, @petition, params[:stage], params[:move])
    if @stage_manager.create_signature
      @signature = @stage_manager.signature
      @sponsor = @petition.sponsors.create(signature: @signature)
      send_email_to_sponsor(@sponsor)
      redirect_to thank_you_petition_sponsor_url(@petition, token: @petition.sponsor_token)
    else
      render :show
    end
  end

  def thank_you
  end

  def sponsored
{'fraction_non_alphanumeric': 0.07969563476171405, 'fraction_numerical': 0.0, 'mean_word_length': 4.454148471615721, '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': '2633783', 'n_tokens_mistral': 799, 'n_tokens_neox': 718, 'n_words': 143}