<commit_before>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable

  # Concerns
  include Deletable, TokenAuthenticatable

  # Callbacks
  before_save :ensure_authentication_token

  # Named Scopes
  scope :aug_members, -> { current.where(aug_member: true) }
  scope :core_members, -> { current.where(core_member: true) }
  scope :system_admins, -> { current.where(system_admin: true) }
  scope :search, -> (arg) { where('LOWER(first_name) LIKE ? or LOWER(last_name) LIKE ? or LOWER(email) LIKE ?', arg.to_s.downcase.gsub(/^| |$/, '%'), arg.to_s.downcase.gsub(/^| |$/, '%'), arg.to_s.downcase.gsub(/^| |$/, '%')) }
  scope :with_name, -> (arg) { where("(users.first_name || ' ' || users.last_name) IN (?) or users.username IN (?)", arg, arg) }

  def self.aug_or_core_members
    current.where('aug_member = ? or core_member = ?', true, true)
  end

  def self.regular_members
    current.where(aug_member: false, core_member: false)
  end

  # Model Validation
  validates :first_name, :last_name, presence: true
  validates :username, uniqueness: { case_sensitive: false }, format: { with: /\A[a-z]\w*\Z/i }, allow_blank: true

  # Model Relationships
  has_many :agreements, -> { where deleted: false }
  has_many :agreement_events
  has_many :answers
  has_many :broadcasts, -> { current }
  has_many :challenges, -> { where deleted: false }
  has_many :comments, -> { where deleted: false }
  has_many :community_tools, -> { current }
  has_many :datasets, -> { where deleted: false }
  has_many :dataset_file_audits
  has_many :hosting_requests, -> { current }
  has_many :images
  has_many :reviews
  has_many :tags, -> { where deleted: false }
  has_many :tools
  has_many :topics, -> { where deleted: false }
  has_many :subscriptions

  # User Methods

  def all_topics
    if system_admin?
      Topic.current
    else
      topics
    end
  end

  def all_comments
    if system_admin?
      Comment.current
    else
      comments
    end
  end

  def all_agreements
    if system_admin?
      Agreement.current
    else
      agreements
    end
  end

  def all_agreement_events
    if system_admin?
      AgreementEvent.all
    else
      agreement_events
    end
  end

  def reviewable_agreements
    Agreement.current.where('agreements.id IN (select requests.agreement_id from requests where requests.dataset_id IN (?))', all_reviewable_datasets.select(:id))
  end

  def all_datasets
    Dataset.current.with_editor(id)
  end

  def all_reviewable_datasets
    Dataset.current.with_reviewer(id)
  end

  def all_viewable_datasets
    Dataset.current.with_viewer_or_editor(id)
  end

  def all_viewable_challenges
    if system_admin?
      Challenge.current
    else
      Challenge.current.where(public: true)
    end
  end

  def all_challenges
    if system_admin?
      Challenge.current
    else
      challenges
    end
  end

  def all_tools
    Tool.current.with_editor(id)
  end

  def all_viewable_tools
    Tool.current.with_viewer_or_editor(id)
  end

  def avatar_url(size = 80, default = 'mm')
    gravatar_id = Digest::MD5.hexdigest(email.to_s.downcase)
    "//gravatar.com/avatar/#{gravatar_id}.png?&s=#{size}&r=pg&d=#{default}"
  end

  def can_post_links?
    aug_member? || core_member?
  end<commit_msg>Allow members to post links and images<commit_after>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable

  # Concerns
  include Deletable, TokenAuthenticatable

  # Callbacks
  before_save :ensure_authentication_token

  # Named Scopes
  scope :aug_members, -> { current.where(aug_member: true) }
  scope :core_members, -> { current.where(core_member: true) }
  scope :system_admins, -> { current.where(system_admin: true) }
  scope :search, -> (arg) { where('LOWER(first_name) LIKE ? or LOWER(last_name) LIKE ? or LOWER(email) LIKE ?', arg.to_s.downcase.gsub(/^| |$/, '%'), arg.to_s.downcase.gsub(/^| |$/, '%'), arg.to_s.downcase.gsub(/^| |$/, '%')) }
  scope :with_name, -> (arg) { where("(users.first_name || ' ' || users.last_name) IN (?) or users.username IN (?)", arg, arg) }

  def self.aug_or_core_members
    current.where('aug_member = ? or core_member = ?', true, true)
  end

  def self.regular_members
    current.where(aug_member: false, core_member: false)
  end

  # Model Validation
  validates :first_name, :last_name, presence: true
  validates :username, uniqueness: { case_sensitive: false }, format: { with: /\A[a-z]\w*\Z/i }, allow_blank: true

  # Model Relationships
  has_many :agreements, -> { where deleted: false }
  has_many :agreement_events
  has_many :answers
  has_many :broadcasts, -> { current }
  has_many :challenges, -> { where deleted: false }
  has_many :comments, -> { where deleted: false }
  has_many :community_tools, -> { current }
  has_many :datasets, -> { where deleted: false }
  has_many :dataset_file_audits
  has_many :hosting_requests, -> { current }
  has_many :images
  has_many :reviews
  has_many :tags, -> { where deleted: false }
  has_many :tools
  has_many :topics, -> { where deleted: false }
  has_many :subscriptions

  # User Methods

  def all_topics
    if system_admin?
      Topic.current
    else
      topics
    end
  end

  def all_comments
    if system_admin?
      Comment.current
    else
      comments
    end
  end

  def all_agreements
    if system_admin?
      Agreement.current
    else
      agreements
    end
  end

  def all_agreement_events
    if system_admin?
      AgreementEvent.all
    else
      agreement_events
    end
  end

  def reviewable_agreements
    Agreement.current.where('agreements.id IN (select requests.agreement_id from requests where requests.dataset_id IN (?))', all_reviewable_datasets.select(:id))
  end

  def all_datasets
    Dataset.current.with_editor(id)
  end

  def all_reviewable_datasets
    Dataset.current.with_reviewer(id)
  end

  def all_viewable_datasets
    Dataset.current.with_viewer_or_editor(id)
  end

  def all_viewable_challenges
    if system_admin?
      Challenge.current
    else
      Challenge.current.where(public: true)
    end
  end

  def all_challenges
    if system_admin?
      Challenge.current
    else
      challenges
    end
  end

  def all_tools
    Tool.current.with_editor(id)
  end

  def all_viewable_tools
    Tool.current.with_viewer_or_editor(id)
  end

  def avatar_url(size = 80, default = 'mm')
    gravatar_id = Digest::MD5.hexdigest(email.to_s.downcase)
    "//gravatar.com/avatar/#{gravatar_id}.png?&s=#{size}&r=pg&d=#{default}"
  end

  def can_post_links?
    # aug_member? || core_member?
    true
  end
{'fraction_non_alphanumeric': 0.1089835876763605, 'fraction_numerical': 0.0008638065073423554, 'mean_word_length': 3.490627020038785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '720998', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2332, 'n_words': 524}