<commit_before>class Users::ContributionsController < ApplicationController
  inherit_resources
  defaults resource_class: Contribution
  belongs_to :user
  actions :index

  def request_refund
    authorize! :request_refund, resource
    if resource.value > resource.user.user_total.credits
      flash.alert = I18n.t('controllers.users.contributions.request_refund.insufficient_credits')
    elsif can?(:request_refund, resource) && resource.can_request_refund?
      resource.request_refund!
      flash.notice = I18n.t('controllers.users.contributions.request_refund.refunded')
    end

    redirect_to credits_user_path(parent)
  end

  protected
  def collection
    @contributions ||= end_of_association_chain.available_to_display.order("created_at DESC, confirmed_at DESC")
    @contributions = @contributions.not_anonymous.with_state('confirmed') unless can? :manage, @user
    @contributions = @contributions.includes(:user, :reward, project: [:user, :category, :project_total])
  end
end<commit_msg>Migrate user contributions controller to pundit<commit_after>class Users::ContributionsController < ApplicationController
  after_filter :verify_authorized, except: [:index]
  after_filter :verify_policy_scoped, only: [:index]
  inherit_resources
  defaults resource_class: Contribution
  belongs_to :user
  actions :index

  def request_refund
    authorize resource
    authorize! :request_refund, resource
    if resource.value > resource.user.user_total.credits || !resource.request_refund
      flash.alert = I18n.t('controllers.users.contributions.request_refund.insufficient_credits')
    else
      flash.notice = I18n.t('controllers.users.contributions.request_refund.refunded')
    end

    redirect_to credits_user_path(parent)
  end

  protected
  def policy_scope(scope)
    @_policy_scoped = true
    ContributionPolicy::UserScope.new(current_user, parent, scope).resolve
  end

  def collection
    @contributions ||= policy_scope(end_of_association_chain).
      order("created_at DESC, confirmed_at DESC").
      includes(:user, :reward, project: [:user, :category, :project_total]).
      page(params[:page]).per(10)
  end
end
{'fraction_non_alphanumeric': 0.09238625812441968, 'fraction_numerical': 0.004642525533890436, 'mean_word_length': 5.122159090909091, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5100848', 'n_tokens_mistral': 671, 'n_tokens_neox': 648, 'n_words': 124}