<commit_before>module RailsRole::Controller

  def self.prepended(controller)
    controller.helper_method :rails_role_user
  end

  def require_role(the_params = params['id'])
    if rails_role_user.has_role? controller_path, action_name, the_params
      return true
    end

    role_access_denied
  end

  private
  def role_access_denied
    access_denied_method = RailsRole.config.access_denied_method
    return send(access_denied_method) if access_denied_method && respond_to?(access_denied_method)

    default_access_denied_response
  end

  def default_access_denied_response
    access_denied_msg = I18n.t(:access_denied, scope: :rails_role)

    if request.xhr?
      render file: RailsRole::Engine.root + 'app/views/rails_role_admin/base/errors.js.erb', status: 403
    elsif request.format.json?
      raise ActionController::ForbiddenError
    else
      redirect_back fallback_location: root_url, flash: { error: access_denied_msg }
    end
  end

  def rails_role_user
    defined?(current_user) && current_user
  end

end

ActionController::Base.prepend RailsRole::Controller<commit_msg>rails role controller<commit_after>module RailsRole::Controller
  extend ActiveSupport::Concern
  included do
    helper_method :rails_role_user
  end

  def require_role(the_params = params['id'])
    if rails_role_user.has_role? controller_path, action_name, the_params
      return true
    end

    role_access_denied
  end

  private
  def role_access_denied
    access_denied_method = RailsRole.config.access_denied_method
    return send(access_denied_method) if access_denied_method && respond_to?(access_denied_method)

    default_access_denied_response
  end

  def default_access_denied_response
    access_denied_msg = I18n.t(:access_denied, scope: :rails_role)

    if request.xhr?
      render file: RailsRole::Engine.root + 'app/views/rails_role_admin/base/errors.js.erb', status: 403
    elsif request.format.json?
      raise ActionController::ForbiddenError
    else
      redirect_back fallback_location: root_url, flash: { error: access_denied_msg }
    end
  end

  def rails_role_user
    defined?(current_user) && current_user
  end

end
{'fraction_non_alphanumeric': 0.06783571758191048, 'fraction_numerical': 0.0046146746654360865, 'mean_word_length': 4.447236180904523, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2965099', 'n_tokens_mistral': 725, 'n_tokens_neox': 687, 'n_words': 135}