<commit_before>module MessageTrainSupport
  extend ActiveSupport::Concern

  included do

    # Last in first out
    prepend_before_filter :load_collective_boxes,
                          :load_box,
                          :load_collective,
                          :load_division,
                          :load_box_user,
                          unless: :devise_controller?
    before_filter :load_objects
    before_action :set_locale

    helper MessageTrain::ApplicationHelper
    helper MessageTrain::BoxesHelper
    helper MessageTrain::CollectivesHelper
    helper MessageTrain::ConversationsHelper
    helper MessageTrain::MessagesHelper
    helper MessageTrain::AttachmentsHelper

    rescue_from ActiveRecord::RecordNotFound do
      render '404', status: :not_found
    end

  end

protected

  def require_authentication
    redirect_to url_for(MessageTrain.configuration.user_sign_in_path), flash: { notice: :you_must_sign_in_or_sign_up_to_continue.l }
  end

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end

  def load_box_user
    @box_user = send(MessageTrain.configuration.current_user_method) || require_authentication
  end

  def load_division
    @division = (params[:division] || params[:box_division] || 'in').to_sym
  end

  def load_collective
    if params[:collective_id].present?
      collective_table, collective_id = params[:collective_id].split(':')
      collective_class_name = MessageTrain.configuration.recipient_tables[collective_table.to_sym]
      collective_model = collective_class_name.constantize
      slug_column = MessageTrain.configuration.slug_columns[collective_table.to_sym]
      @collective = collective_model.find_by!(slug_column => collective_id)

      unless @collective.allows_receiving_by?(@box_user) || @collective.allows_sending_by?(@box_user)
        flash[:error] = :access_to_that_box_denied.l
        redirect_to main_app.root_url
        return
      end

      case @division
        when :in, :ignored
          unless @collective.allows_receiving_by? @box_user
            flash[:error] = :access_to_that_box_denied.l
            redirect_to message_train.collective_box_url(@collective.path_part, :sent)
          end
        when :sent, :drafts
          unless @collective.allows_sending_by? @box_user
            flash[:error] = :access_to_that_box_denied.l<commit_msg>Fixed another place where the slug column was not defaulting to :slug, fixed it.<commit_after>module MessageTrainSupport
  extend ActiveSupport::Concern

  included do

    # Last in first out
    prepend_before_filter :load_collective_boxes,
                          :load_box,
                          :load_collective,
                          :load_division,
                          :load_box_user,
                          unless: :devise_controller?
    before_filter :load_objects
    before_action :set_locale

    helper MessageTrain::ApplicationHelper
    helper MessageTrain::BoxesHelper
    helper MessageTrain::CollectivesHelper
    helper MessageTrain::ConversationsHelper
    helper MessageTrain::MessagesHelper
    helper MessageTrain::AttachmentsHelper

    rescue_from ActiveRecord::RecordNotFound do
      render '404', status: :not_found
    end

  end

protected

  def require_authentication
    redirect_to url_for(MessageTrain.configuration.user_sign_in_path), flash: { notice: :you_must_sign_in_or_sign_up_to_continue.l }
  end

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end

  def load_box_user
    @box_user = send(MessageTrain.configuration.current_user_method) || require_authentication
  end

  def load_division
    @division = (params[:division] || params[:box_division] || 'in').to_sym
  end

  def load_collective
    if params[:collective_id].present?
      collective_table, collective_id = params[:collective_id].split(':')
      collective_class_name = MessageTrain.configuration.recipient_tables[collective_table.to_sym]
      collective_model = collective_class_name.constantize
      slug_column = MessageTrain.configuration.slug_columns[collective_table.to_sym] || :slug
      @collective = collective_model.find_by!(slug_column => collective_id)

      unless @collective.allows_receiving_by?(@box_user) || @collective.allows_sending_by?(@box_user)
        flash[:error] = :access_to_that_box_denied.l
        redirect_to main_app.root_url
        return
      end

      case @division
        when :in, :ignored
          unless @collective.allows_receiving_by? @box_user
            flash[:error] = :access_to_that_box_denied.l
            redirect_to message_train.collective_box_url(@collective.path_part, :sent)
          end
        when :sent, :drafts
          unless @collective.allows_sending_by? @box_user
            flash[:error] = :access_to_that_box_denied.l
{'fraction_non_alphanumeric': 0.07441091360066143, 'fraction_numerical': 0.0028937577511368336, 'mean_word_length': 3.2559366754617414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '408325', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1399, 'n_words': 249}