<commit_before>class User < ActiveRecord::Base
  ROLES = %w{administrator moderator dynamizer}

  include Verification
  include PgSearch

  apply_simple_captcha
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :async

  acts_as_voter
  acts_as_paranoid column: :hidden_at
  include ActsAsParanoidAliases

  has_one :organization
  has_one :lock
  has_many :flags
  has_many :identities, dependent: :destroy
  has_many :debates, -> { with_hidden }, foreign_key: :author_id
  has_many :proposals, -> { with_hidden }, foreign_key: :author_id
  has_many :comments, -> { with_hidden }
  has_many :failed_census_calls
  has_many :notifications
  has_many :recommendations
  has_many :recommended_proposals, through: :recommendations, source: :proposal

  validates :username, presence: true, if: :username_required?
  validates :username, uniqueness: true, if: :username_required?
  validates :document_number, uniqueness: { scope: :document_type }, allow_nil: true

  validate :validate_username_length

  validates :official_level, inclusion: {in: 0..5}
  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  validates :locale, inclusion: {in: I18n.available_locales.map(&:to_s),
                                 allow_nil: true}

  validates_associated :organization, message: false

  accepts_nested_attributes_for :organization, update_only: true

  attr_accessor :skip_password_validation

  scope :administrators, -> { where.contains(roles: ['administrator']) }
  scope :moderators,     -> { where.contains(roles: ['moderator']) }
  scope :dynamizers,     -> { where.contains(roles: ['dynamizer']) }
  scope :organizations,  -> { joins(:organization) }
  scope :officials,      -> { where("official_level > 0") }
  scope :for_render,     -> { includes(:organization) }
  scope :by_document,    -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }<commit_msg>Allow document number to be blank instead of just nil<commit_after>class User < ActiveRecord::Base
  ROLES = %w{administrator moderator dynamizer}

  include Verification
  include PgSearch

  apply_simple_captcha
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :async

  acts_as_voter
  acts_as_paranoid column: :hidden_at
  include ActsAsParanoidAliases

  has_one :organization
  has_one :lock
  has_many :flags
  has_many :identities, dependent: :destroy
  has_many :debates, -> { with_hidden }, foreign_key: :author_id
  has_many :proposals, -> { with_hidden }, foreign_key: :author_id
  has_many :comments, -> { with_hidden }
  has_many :failed_census_calls
  has_many :notifications
  has_many :recommendations
  has_many :recommended_proposals, through: :recommendations, source: :proposal

  validates :username, presence: true, if: :username_required?
  validates :username, uniqueness: true, if: :username_required?
  validates :document_number, uniqueness: { scope: :document_type }, allow_blank: true

  validate :validate_username_length

  validates :official_level, inclusion: {in: 0..5}
  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  validates :locale, inclusion: {in: I18n.available_locales.map(&:to_s),
                                 allow_nil: true}

  validates_associated :organization, message: false

  accepts_nested_attributes_for :organization, update_only: true

  attr_accessor :skip_password_validation

  scope :administrators, -> { where.contains(roles: ['administrator']) }
  scope :moderators,     -> { where.contains(roles: ['moderator']) }
  scope :dynamizers,     -> { where.contains(roles: ['dynamizer']) }
  scope :organizations,  -> { joins(:organization) }
  scope :officials,      -> { where("official_level > 0") }
  scope :for_render,     -> { includes(:organization) }
  scope :by_document,    -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }
{'fraction_non_alphanumeric': 0.1054421768707483, 'fraction_numerical': 0.0024295432458697765, 'mean_word_length': 4.915229885057471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372444', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1257, 'n_words': 295}