diff options
author | Senorsen <sen@senorsen.com> | 2015-04-14 00:28:49 +0800 |
---|---|---|
committer | Senorsen <sen@senorsen.com> | 2015-04-14 19:42:48 +0800 |
commit | 7b28218f96d14c9650484a183ffab3b2132b05db (patch) | |
tree | a79cbd394f52a00ba69b1d9b9f192d7ce0b35082 /app/models | |
parent | ae6d0aaae0d8f6251b30a8e5243a98f083f0cac9 (diff) | |
download | gitlab-ce-7b28218f96d14c9650484a183ffab3b2132b05db.tar.gz |
Allow user to choose which email to be public
This commit allows user to show one of their emails in profile page,
or don't show email in this page.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index a40111e62dd..d6b93afe739 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,6 +49,7 @@ # password_automatically_set :boolean default(FALSE) # bitbucket_access_token :string(255) # bitbucket_access_token_secret :string(255) +# public_email :string(255) default(""), not null # require 'carrierwave/orm/activerecord' @@ -123,6 +124,7 @@ class User < ActiveRecord::Base validates :name, presence: true validates :email, presence: true, email: { strict_mode: true }, uniqueness: true validates :notification_email, presence: true, email: { strict_mode: true } + validates :public_email, presence: true, email: { strict_mode: true }, allow_blank: true, uniqueness: true validates :bio, length: { maximum: 255 }, allow_blank: true validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :username, @@ -142,6 +144,7 @@ class User < ActiveRecord::Base before_validation :generate_password, on: :create before_validation :sanitize_attrs before_validation :set_notification_email, if: ->(user) { user.email_changed? } + before_validation :set_public_email, if: ->(user) { user.public_email_changed? } before_save :ensure_authentication_token after_save :ensure_namespace_correct @@ -443,6 +446,12 @@ class User < ActiveRecord::Base end end + def set_public_email + if self.public_email.blank? || !self.all_emails.include?(self.public_email) + self.public_email = '' + end + end + def set_projects_limit connection_default_value_defined = new_record? && !projects_limit_changed? return unless self.projects_limit.nil? || connection_default_value_defined |