<commit_before># frozen_string_literal: true

class RewardPolicy < ApplicationPolicy
  def create?
    done_by_owner_or_admin?
  end

  def update?
    done_by_owner_or_admin?
  end

  def sort?
    done_by_owner_or_admin?
  end

  def toggle_survey_finish?
    done_by_owner_or_admin?
  end

  def destroy?
    done_by_owner_or_admin? && !record.any_sold?
  end

  def permitted_attributes
    attributes = record.attribute_names.map(&:to_sym)
    attributes << { shipping_fees_attributes: %i[_destroy id value destination] }
    attributes.delete(:minimum_value) if record.persisted? && record.any_sold?
    attributes.delete(:deliver_at) if record.persisted? && project_finished?
    attributes
  end

  protected

  def project_finished?
    record.project.failed? || record.project.successful?
  end

  def done_by_owner_or_admin?
    record.project.user == user || user.try(:admin?)
  end
end
<commit_msg>allow admin to edit rewards[#159796591]<commit_after># frozen_string_literal: true

class RewardPolicy < ApplicationPolicy
  def create?
    done_by_owner_or_admin?
  end

  def update?
    done_by_owner_or_admin?
  end

  def sort?
    done_by_owner_or_admin?
  end

  def toggle_survey_finish?
    done_by_owner_or_admin?
  end

  def destroy?
    done_by_owner_or_admin? && !record.any_sold?
  end

  def permitted_attributes
    attributes = record.attribute_names.map(&:to_sym)
    attributes << { shipping_fees_attributes: %i[_destroy id value destination] }
    unless user.try(:admin?)
      attributes.delete(:minimum_value) if record.persisted? && record.any_sold?
      attributes.delete(:deliver_at) if record.persisted? && project_finished?
    end
    attributes
  end

  protected

  def project_finished?
    record.project.failed? || record.project.successful?
  end

  def done_by_owner_or_admin?
    record.project.user == user || user.try(:admin?)
  end
end

{'fraction_non_alphanumeric': 0.08470089994706194, 'fraction_numerical': 0.004764425622022234, 'mean_word_length': 4.04, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2335299', 'n_tokens_mistral': 642, 'n_tokens_neox': 616, 'n_words': 127}