<commit_before>class Admin::EditionsController < ApplicationController
  before_filter :authenticate!

  def index
    @editions = Edition.drafts
  end

  def show
    @edition = Edition.find(params[:id])
  end

  def new
    @edition = Edition.new
  end

  def create
    @edition = current_user.editions.build(params[:edition].merge(:policy => Policy.new))
    if @edition.save
      redirect_to edit_admin_edition_path(@edition), notice: 'The policy has been saved'
    else
      flash.now[:alert] = 'There are some problems with the policy'
      render action: 'new'
    end
  end

  def edit
    @edition = Edition.find(params[:id])
  end

  def update
    @edition = Edition.find(params[:id])
    if @edition.submitted?
      @edition.update_attributes(params[:edition])
      redirect_to submitted_admin_editions_path
    else
      if @edition.update_attributes(params[:edition])
        if @edition.submitted?
          redirect_to admin_editions_path,
            notice: 'Your policy has been submitted to your second pair of eyes'
        else
          redirect_to edit_admin_edition_path(@edition),
            notice: 'The policy has been saved'
        end
      else
        flash.now[:alert] = 'There are some problems with the policy'
        render action: 'edit'
      end
    end
  rescue ActiveRecord::StaleObjectError
    flash.now[:alert] = %{This policy has been saved since you opened it. You probably want to copy your changes into a text editor and <a href="#{edit_admin_edition_path(@edition)}">load the latest version</a>.}
    render action: 'edit'
  end

  def publish
    edition = Edition.find(params[:id])
    if edition.publish_as!(current_user, params[:edition][:lock_version])
      redirect_to submitted_admin_editions_path
    else
      redirect_to admin_edition_path(edition), alert: edition.errors.full_messages.to_sentence
    end
  rescue ActiveRecord::StaleObjectError
    redirect_to admin_edition_path(edition), alert: "This policy has been edited since you viewed it; you are now viewing the latest version"
  end

  def submitted
    @editions = Edition.submitted
  end

  def published
    @editions = Edition.published
  end
end<commit_msg>Group index actions together in admin/editions<commit_after>class Admin::EditionsController < ApplicationController
  before_filter :authenticate!

  def index
    @editions = Edition.drafts
  end

  def submitted
    @editions = Edition.submitted
  end

  def published
    @editions = Edition.published
  end

  def show
    @edition = Edition.find(params[:id])
  end

  def new
    @edition = Edition.new
  end

  def create
    @edition = current_user.editions.build(params[:edition].merge(:policy => Policy.new))
    if @edition.save
      redirect_to edit_admin_edition_path(@edition), notice: 'The policy has been saved'
    else
      flash.now[:alert] = 'There are some problems with the policy'
      render action: 'new'
    end
  end

  def edit
    @edition = Edition.find(params[:id])
  end

  def update
    @edition = Edition.find(params[:id])
    if @edition.submitted?
      @edition.update_attributes(params[:edition])
      redirect_to submitted_admin_editions_path
    else
      if @edition.update_attributes(params[:edition])
        if @edition.submitted?
          redirect_to admin_editions_path,
            notice: 'Your policy has been submitted to your second pair of eyes'
        else
          redirect_to edit_admin_edition_path(@edition),
            notice: 'The policy has been saved'
        end
      else
        flash.now[:alert] = 'There are some problems with the policy'
        render action: 'edit'
      end
    end
  rescue ActiveRecord::StaleObjectError
    flash.now[:alert] = %{This policy has been saved since you opened it. You probably want to copy your changes into a text editor and <a href="#{edit_admin_edition_path(@edition)}">load the latest version</a>.}
    render action: 'edit'
  end

  def publish
    edition = Edition.find(params[:id])
    if edition.publish_as!(current_user, params[:edition][:lock_version])
      redirect_to submitted_admin_editions_path
    else
      redirect_to admin_edition_path(edition), alert: edition.errors.full_messages.to_sentence
    end
  rescue ActiveRecord::StaleObjectError
    redirect_to admin_edition_path(edition), alert: "This policy has been edited since you viewed it; you are now viewing the latest version"
  end
end
{'fraction_non_alphanumeric': 0.08297535609314945, 'fraction_numerical': 0.0, 'mean_word_length': 3.341511285574092, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3390412', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1284, 'n_words': 378}