<commit_before>class ApplicationController < ActionController::Base
  include Pundit
  protect_from_forgery with: :exception

  helper_method :current_user
  before_action :authenticate_user!, unless: proc { pages_controller? || repos_api? }
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

  before_action :_set_current_session

  protected
    def _set_current_session
      accessor = instance_variable_get(:@_request)
      ActiveRecord::Base.send(:define_method, "session", proc { accessor.session })
      Course.current = Course.find(session[:course_id]) if session[:course_id].present?
    end

    def verify_name
      if !current_user.name.present? || current_user.name.strip.empty?
        flash[:alert] = "Por favor, utilizá tu nombre completo en el perfil. Podés hacerlo desde la barra de menú"
      end
    end

    def verify_pending_solutions
      if session[:course_id] && current_user.solutions.detect { |s| s.finished_at == nil }
        flash[:info] = "Tenés un ejercicio en curso. Si lo olvidaste, podés accederlo y finalizarlo. O eliminarlo"
      end
    end

  private

    def user_not_authorized
      flash[:alert] = "No estás autorizado a realizar esa acción"
      redirect_to(request.referrer || profile_path)
    end

    def authenticate_user!
      unless current_user
        redirect_to root_path
      end
    end

    def pages_controller?
      controller_path.starts_with?("pages") || controller_path.starts_with?("sessions")
    end

    def repos_api?
      controller_path.starts_with?("repos")
    end

    def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
end<commit_msg>Fixed permissions issue<commit_after>class ApplicationController < ActionController::Base
  include Pundit
  protect_from_forgery with: :exception

  helper_method :current_user
  before_action :authenticate_user!, unless: proc { pages_controller? || repos_api? }
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

  before_action :_set_current_session

  protected
    def _set_current_session
      accessor = instance_variable_get(:@_request)
      ActiveRecord::Base.send(:define_method, "session", proc { accessor.session })
      Course.current = Course.find(session[:course_id]) if session[:course_id].present?
    end

    def verify_name
      if !current_user.name.present? || current_user.name.strip.empty?
        flash[:alert] = "Por favor, utilizá tu nombre completo en el perfil. Podés hacerlo desde la barra de menú"
      end
    end

    def verify_pending_solutions
      if session[:course_id] && current_user.solutions.detect { |s| s.finished_at == nil }
        flash[:info] = "Tenés un ejercicio en curso. Si lo olvidaste, podés accederlo y finalizarlo. O eliminarlo"
      end
    end

  private

    def user_not_authorized
      flash[:alert] = "No estás autorizado a realizar esa acción"
      redirect_to(request.referrer || profile_path)
    end

    def authenticate_user!
      unless current_user
        redirect_to root_path
      end
    end

    def pages_controller?
      controller_path.starts_with?("pages") || controller_path.starts_with?("sessions")
    end

    def repos_api?
      controller_path.starts_with?("api")
    end

    def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
end
{'fraction_non_alphanumeric': 0.0851063829787234, 'fraction_numerical': 0.0, 'mean_word_length': 3.656121045392022, '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': '3618075', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1028, 'n_words': 249}