<commit_before># frozen_string_literal: true

class PlansController < ApplicationController

  include ConditionalUserMailer
  helper PaginableHelper
  helper SettingsTemplateHelper

  after_action :verify_authorized, except: [:overview]

  def index
    authorize Plan
    @plans = Plan.active(current_user).page(1)
    @organisationally_or_publicly_visible =
      Plan.organisationally_or_publicly_visible(current_user).page(1)
  end

  # GET /plans/new
  def new
    @plan = Plan.new
    authorize @plan

    # Get all of the available funders and non-funder orgs
    @funders = Org.funder
                  .joins(:templates)
                  .where(templates: { published: true }).uniq.sort(&:name)
    @orgs = (Org.organisation + Org.institution + Org.managing_orgs).flatten
                                                                    .uniq.sort(&:name)

    # Get the current user's org
    @default_org = current_user.org if @orgs.include?(current_user.org)

    if params.key?(:test)
      flash[:notice] = "#{_('This is a')} <strong>#{_('test plan')}</strong>"
    end
    @is_test = params[:test] ||= false
    respond_to :html
  end

  # POST /plans
  def create
    @plan = Plan.new
    authorize @plan<commit_msg>Fix sorting in plans controller<commit_after># frozen_string_literal: true

class PlansController < ApplicationController

  include ConditionalUserMailer
  helper PaginableHelper
  helper SettingsTemplateHelper

  after_action :verify_authorized, except: [:overview]

  def index
    authorize Plan
    @plans = Plan.active(current_user).page(1)
    @organisationally_or_publicly_visible =
      Plan.organisationally_or_publicly_visible(current_user).page(1)
  end

  # GET /plans/new
  def new
    @plan = Plan.new
    authorize @plan

    # Get all of the available funders and non-funder orgs
    @funders = Org.funder
                  .joins(:templates)
                  .where(templates: { published: true }).uniq.sort_by(&:name)
    @orgs = (Org.organisation + Org.institution + Org.managing_orgs).flatten
                                                                    .uniq.sort_by(&:name)

    # Get the current user's org
    @default_org = current_user.org if @orgs.include?(current_user.org)

    if params.key?(:test)
      flash[:notice] = "#{_('This is a')} <strong>#{_('test plan')}</strong>"
    end
    @is_test = params[:test] ||= false
    respond_to :html
  end

  # POST /plans
  def create
    @plan = Plan.new
    authorize @plan
{'fraction_non_alphanumeric': 0.10328262610088071, 'fraction_numerical': 0.0016012810248198558, 'mean_word_length': 2.6481751824817517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6941332', 'n_tokens_mistral': 790, 'n_tokens_neox': 762, 'n_words': 175}