<commit_before>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
  enum role: [:user, :admin]
  enum pref_distance_unit: [:miles, :kilometers]
  enum pref_elevation_unit: [:feet, :meters]
  include Searchable

  has_many :connections, dependent: :destroy
  has_many :interests, through: :connections, source: :participant
  has_many :stewardships, dependent: :destroy
  has_many :organizations, through: :stewardships
  has_one :avatar, class_name: 'Participant'

  validates_presence_of :first_name, :last_name

  after_initialize :set_default_role, if: :new_record?

  def set_default_role
    self.role ||= :user
  end

  def self.current
    Thread.current[:current_user]
  end

  def self.current=(user)
    Thread.current[:current_user] = user
  end

  def self.create_with_omniauth(auth)
    create! do |user|
      user.provider = auth['provider']
      user.uid = auth['uid']
      if auth['info']
        user.last_name = auth['info']['name'] || "" # TODO: figure out how to use oath with first_name/last_name model
      end
    end
  end

  def authorized_to_edit?(resource)
    admin? | (id == resource.created_by) | resource.new_record?
  end

  def authorized_to_claim?(participant)
    return false if self.has_avatar?
    admin? | (last_name == participant.last_name) | (first_name == participant.first_name)
  end

  def authorized_for_live?(resource)
    admin? | (id == resource.created_by) | steward_of?(resource) | resource.new_record?
  end

  def authorized_to_edit_personal?(effort)
    admin? | (effort.participant ? (avatar == effort.participant) : authorized_to_edit?(effort))
  end

  def steward_of?(resource)
    resource.organization && resource.organization.stewards.include?(self)
  end

  def full_name
    [first_name, last_name].join(' ')
  end

  def has_no_avatar?
    avatar.nil?
  end

  def has_avatar?
    avatar.present?
  end

  def interested_in?(participant)
    interests.include?(participant)
  end

  def add_interest(participant)
    interests << participant
  end
<commit_msg>Optimize User policy methods by substituting `||` for `|` to avoid evaluation of later components.<commit_after>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
  enum role: [:user, :admin]
  enum pref_distance_unit: [:miles, :kilometers]
  enum pref_elevation_unit: [:feet, :meters]
  include Searchable

  has_many :connections, dependent: :destroy
  has_many :interests, through: :connections, source: :participant
  has_many :stewardships, dependent: :destroy
  has_many :organizations, through: :stewardships
  has_one :avatar, class_name: 'Participant'

  validates_presence_of :first_name, :last_name

  after_initialize :set_default_role, if: :new_record?

  def set_default_role
    self.role ||= :user
  end

  def self.current
    Thread.current[:current_user]
  end

  def self.current=(user)
    Thread.current[:current_user] = user
  end

  def self.create_with_omniauth(auth)
    create! do |user|
      user.provider = auth['provider']
      user.uid = auth['uid']
      if auth['info']
        user.last_name = auth['info']['name'] || "" # TODO: figure out how to use oath with first_name/last_name model
      end
    end
  end

  def authorized_to_edit?(resource)
    admin? || (id == resource.created_by) || resource.new_record?
  end

  def authorized_to_claim?(participant)
    return false if self.has_avatar?
    admin? || (last_name == participant.last_name) || (first_name == participant.first_name)
  end

  def authorized_for_live?(resource)
    admin? || (id == resource.created_by) || steward_of?(resource) || resource.new_record?
  end

  def authorized_to_edit_personal?(effort)
    admin? || (effort.participant ? (avatar == effort.participant) : authorized_to_edit?(effort))
  end

  def steward_of?(resource)
    resource.organization && resource.organization.stewards.include?(self)
  end

  def full_name
    [first_name, last_name].join(' ')
  end

  def has_no_avatar?
    avatar.nil?
  end

  def has_avatar?
    avatar.present?
  end

  def interested_in?(participant)
    interests.include?(participant)
  end

  def add_interest(participant)
    interests << participant
  end

{'fraction_non_alphanumeric': 0.10749399169761853, 'fraction_numerical': 0.0, 'mean_word_length': 4.226027397260274, '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': '2083806', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1475, 'n_words': 346}