<commit_before>module Shopping
  class ApiController < ApplicationController
    include JSONAPI::ActsAsResourceController
    protect_from_forgery with: :null_session
    rescue_from Shopping::NotAuthorizedError, with: :reject_forbidden_request

    # before_action :verify_content_type_header

    # before_action :doorkeeper_authorize!
    # if this is inheriting from the host ApplicationController
    # does it have access to current user?

    def reject_forbidden_request(e)
      type = e.resource_klass.name.underscore.humanize(capitalize: false)
      action = params[:action].humanize(capitalize: false)
      error = JSONAPI::Error.new(
        code: JSONAPI::FORBIDDEN,
        status: :forbidden,
        title: "#{action.titleize} Forbidden",
        detail: "You don't have permission to #{action} this #{type}.",
      )

      render json: { errors: [error] }, status: 403
    end

    def context
      { resource_owner: resource_owner }
    end

    def resource_owner
      if Shopping.config.current_user_method.respond_to?(:call)
        Shopping.config.current_user_method.call
      elsif Shopping.config.current_user_method.is_a?(Symbol)
        send(Shopping.config.current_user_method)
      else
        nil
      end
    end 
  end
end
<commit_msg>Remove CSRF check and comments<commit_after>module Shopping
  class ApiController < ApplicationController
    include JSONAPI::ActsAsResourceController
    rescue_from Shopping::NotAuthorizedError, with: :reject_forbidden_request

    def reject_forbidden_request(e)
      type = e.resource_klass.name.underscore.humanize(capitalize: false)
      action = params[:action].humanize(capitalize: false)
      error = JSONAPI::Error.new(
        code: JSONAPI::FORBIDDEN,
        status: :forbidden,
        title: "#{action.titleize} Forbidden",
        detail: "You don't have permission to #{action} this #{type}.",
      )

      render json: { errors: [error] }, status: 403
    end

    def context
      { resource_owner: resource_owner }
    end

    def resource_owner
      if Shopping.config.current_user_method.respond_to?(:call)
        Shopping.config.current_user_method.call
      elsif Shopping.config.current_user_method.is_a?(Symbol)
        send(Shopping.config.current_user_method)
      else
        nil
      end
    end 
  end
end

{'fraction_non_alphanumeric': 0.08412017167381974, 'fraction_numerical': 0.002575107296137339, 'mean_word_length': 3.2459016393442623, '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': '2638486', 'n_tokens_mistral': 702, 'n_tokens_neox': 689, 'n_words': 152}