<commit_before>require 'net/http'
require 'action_controller/railtie'
require 'cancan'
require 'pavlov'

class ApplicationController < ActionController::Base

  include Pavlov::Helpers
  include Devise::Controllers::Rememberable

  DEFAULT_LAYOUT = 'frontend'

  def pavlov_options
    Util::PavlovContextSerialization.pavlov_context_by_user current_user, current_ability
  end

  def params_for_interactor(interactor_class)
    needed = (interactor_class.attribute_set.to_a.map(&:name) - [:pavlov_options]).map(&:to_s)
    Hash[params.select {|k,_| needed.include? k}]
  end

  def self.pavlov_action name, interactor_class
    define_method(name) do
      interactor_params = params_for_interactor(interactor_class).merge(pavlov_options: pavlov_options)

      render json: interactor_class.new(interactor_params).call
    end
  end

  # expose query to views, so we can rewrite inline
  # retrieval to proper queries. The queries should
  # be pulled back to controllers, and then to interactors
  helper_method :query, :interactor # TODO: remove me ASAP

  rescue_from CanCan::AccessDenied, Pavlov::AccessDenied do |exception|
    respond_to do |format|
      if not current_user
        format.html do
          flash[:alert] = t('devise.failure.unauthenticated')
          redirect_to root_path(return_to: request.original_url)
        end
      end

      format.json { render json: {error: "You don't have the correct credentials to execute this operation", code: 'login'}, status: :forbidden }
      format.any  { fail exception }
    end
  end

  protect_from_forgery

  helper :all

  after_filter :set_access_control

  def seen_the_tour user
    view_context.tour_steps.last.to_s == user.seen_tour_step
  end

  def start_the_tour_path
    step = current_user.seen_tour_step || view_context.first_real_tour_step

    send(:"#{step}_path")<commit_msg>We don't need queries/interactors in views anymore<commit_after>require 'net/http'
require 'action_controller/railtie'
require 'cancan'
require 'pavlov'

class ApplicationController < ActionController::Base

  include Pavlov::Helpers
  include Devise::Controllers::Rememberable

  DEFAULT_LAYOUT = 'frontend'

  def pavlov_options
    Util::PavlovContextSerialization.pavlov_context_by_user current_user, current_ability
  end

  def params_for_interactor(interactor_class)
    needed = (interactor_class.attribute_set.to_a.map(&:name) - [:pavlov_options]).map(&:to_s)
    Hash[params.select {|k,_| needed.include? k}]
  end

  def self.pavlov_action name, interactor_class
    define_method(name) do
      interactor_params = params_for_interactor(interactor_class).merge(pavlov_options: pavlov_options)

      render json: interactor_class.new(interactor_params).call
    end
  end

  rescue_from CanCan::AccessDenied, Pavlov::AccessDenied do |exception|
    respond_to do |format|
      if not current_user
        format.html do
          flash[:alert] = t('devise.failure.unauthenticated')
          redirect_to root_path(return_to: request.original_url)
        end
      end

      format.json { render json: {error: "You don't have the correct credentials to execute this operation", code: 'login'}, status: :forbidden }
      format.any  { fail exception }
    end
  end

  protect_from_forgery

  helper :all

  after_filter :set_access_control

  def seen_the_tour user
    view_context.tour_steps.last.to_s == user.seen_tour_step
  end

  def start_the_tour_path
    step = current_user.seen_tour_step || view_context.first_real_tour_step

    send(:"#{step}_path")
{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.0, 'mean_word_length': 4.300898203592815, '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': '6072617', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1104, 'n_words': 251}