<commit_before># encoding: utf-8
# == Schema Information
#
# Table name: users
#
#  id                :integer          not null, primary key
#  name              :string(32)
#  homesite          :string(100)
#  jabber_id         :string(32)
#  cached_slug       :string(32)
#  created_at        :datetime
#  updated_at        :datetime
#  avatar            :string(255)
#  signature         :string(255)
#  custom_avatar_url :string(255)
#


# The users are the public informations about the people who create contents.
# See accounts for the private ones, like authentication.
#
class User < ActiveRecord::Base
  has_one  :account, :dependent => :destroy, :inverse_of => :user
  has_many :nodes, :inverse_of => :user
  has_many :diaries, :dependent => :destroy, :inverse_of => :owner, :foreign_key => "owner_id"
  has_many :news_versions, :dependent => :nullify
  has_many :wiki_versions, :dependent => :nullify
  has_many :comments, :inverse_of => :user
  has_many :taggings, :dependent => :destroy, :include => :tag
  has_many :tags, :through => :taggings, :uniq => true

  attr_accessible :name, :homesite, :jabber_id, :signature, :avatar, :custom_avatar_url

### SEO ###

  extend FriendlyId
  friendly_id :login

  def login
    account ? account.login : name
  end

  def name=(name)
    super name.present? ? name : account.login
  end

### Avatar ###

  mount_uploader :avatar, AvatarUploader

  def custom_avatar_url=(url)
    if url.present?
      remove_avatar!
      self["custom_avatar_url"] = Image.new(url, "", "").src("avatars")
    else
      self["custom_avatar_url"] = nil
    end
    url
  end

  def avatar_url
    if avatar.present?
      url = avatar.url
    elsif custom_avatar_url.present?
      custom_avatar_url
    else
      url = AvatarUploader::DEFAULT_AVATAR_URL
    end
  end

end<commit_msg>accept only avatar_url beginning with //<commit_after># encoding: utf-8
# == Schema Information
#
# Table name: users
#
#  id                :integer          not null, primary key
#  name              :string(32)
#  homesite          :string(100)
#  jabber_id         :string(32)
#  cached_slug       :string(32)
#  created_at        :datetime
#  updated_at        :datetime
#  avatar            :string(255)
#  signature         :string(255)
#  custom_avatar_url :string(255)
#


# The users are the public informations about the people who create contents.
# See accounts for the private ones, like authentication.
#
class User < ActiveRecord::Base
  has_one  :account, :dependent => :destroy, :inverse_of => :user
  has_many :nodes, :inverse_of => :user
  has_many :diaries, :dependent => :destroy, :inverse_of => :owner, :foreign_key => "owner_id"
  has_many :news_versions, :dependent => :nullify
  has_many :wiki_versions, :dependent => :nullify
  has_many :comments, :inverse_of => :user
  has_many :taggings, :dependent => :destroy, :include => :tag
  has_many :tags, :through => :taggings, :uniq => true

  attr_accessible :name, :homesite, :jabber_id, :signature, :avatar, :custom_avatar_url

### SEO ###

  extend FriendlyId
  friendly_id :login

  def login
    account ? account.login : name
  end

  def name=(name)
    super name.present? ? name : account.login
  end

### Avatar ###

  mount_uploader :avatar, AvatarUploader

  def custom_avatar_url=(url)
    if url.present?
      remove_avatar!
      self["custom_avatar_url"] = Image.new(url, "", "").src("avatars")
    else
      self["custom_avatar_url"] = nil
    end
    url
  end

  before_validation :validate_url
  def validate_url
    return if custom_avatar_url.blank?
    return if custom_avatar_url.starts_with?("//")
    errors.add(:url, "Adresse de téléchargement d'avatar non valide")
  end

  def avatar_url
    if avatar.present?
      url = avatar.url
    elsif custom_avatar_url.present?
      custom_avatar_url
    else
      url = AvatarUploader::DEFAULT_AVATAR_URL
    end
  end

end
{'fraction_non_alphanumeric': 0.11150986926429121, 'fraction_numerical': 0.009741092027685208, 'mean_word_length': 3.159914712153518, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '4288381', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1284, 'n_words': 332}