<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]

  has_many :interests, dependent: :destroy
  has_many :participants, through: :interests
  has_many :stewardships, dependent: :destroy
  has_many :races, 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)
    self.admin? | (self.id == resource.created_by)
  end

  def authorized_to_claim?(participant)
    return true if self.admin?
    return true if self.full_name == participant.full_name
    true # TODO future fuzzy match algorithm; also provide for admin contact and override
  end

  def authorized_for_live?(resource)
    self.admin? | (self.id == resource.created_by) | resource.race.stewards.include?(self)
  end

  def full_name
    first_name + " " + last_name
  end

  def has_no_avatar?
    avatar.nil?
  end<commit_msg>Fix nil handling bug in user.authorized_for_live? method.<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]

  has_many :interests, dependent: :destroy
  has_many :participants, through: :interests
  has_many :stewardships, dependent: :destroy
  has_many :races, 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)
    self.admin? | (self.id == resource.created_by)
  end

  def authorized_to_claim?(participant)
    return true if self.admin?
    return true if self.full_name == participant.full_name
    true # TODO future fuzzy match algorithm; also provide for admin contact and override
  end

  def authorized_for_live?(resource)
    self.admin? | (self.id == resource.created_by) | (resource.race && resource.race.stewards.include?(self))
  end

  def full_name
    first_name + " " + last_name
  end

  def has_no_avatar?
    avatar.nil?
  end
{'fraction_non_alphanumeric': 0.10218171775752555, 'fraction_numerical': 0.0, 'mean_word_length': 4.002762430939226, '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': '7203767', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1166, 'n_words': 302}