diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-07 11:00:21 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-07 12:24:14 +0000 |
commit | c239452b47f2819e3ed2fdaf4679737b3e1a456e (patch) | |
tree | bfaee22cd6c0f180faa2a9f83a97375efd804fff /app/models | |
parent | c81d4a65a255146619ccf52ece16757c7db622ae (diff) | |
download | gitlab-ce-c239452b47f2819e3ed2fdaf4679737b3e1a456e.tar.gz |
User can keep their commit email private43521-keep-personal-emails-private
The private commit email is automatically generated in the format:
id-username@noreply.HOSTNAME
GitLab instance admins are able to change the HOSTNAME portion,
that defaults to Gitlab's hostname, to whatever they prefer.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 13 | ||||
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 30 |
3 files changed, 41 insertions, 4 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 704310f53f0..207ffae873a 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -187,6 +187,8 @@ class ApplicationSetting < ActiveRecord::Base validates :user_default_internal_regex, js_regex: true, allow_nil: true + validates :commit_email_hostname, format: { with: /\A[^@]+\z/ } + validates :archive_builds_in_seconds, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 1.day.seconds } @@ -299,10 +301,15 @@ class ApplicationSetting < ActiveRecord::Base user_default_internal_regex: nil, user_show_add_ssh_key_message: true, usage_stats_set_by_user_id: nil, - diff_max_patch_bytes: Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES + diff_max_patch_bytes: Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES, + commit_email_hostname: default_commit_email_hostname } end + def self.default_commit_email_hostname + "users.noreply.#{Gitlab.config.gitlab.host}" + end + def self.create_from_defaults create(defaults) end @@ -358,6 +365,10 @@ class ApplicationSetting < ActiveRecord::Base Array(read_attribute(:repository_storages)) end + def commit_email_hostname + super.presence || self.class.default_commit_email_hostname + end + def default_project_visibility=(level) super(Gitlab::VisibilityLevel.level_value(level)) end diff --git a/app/models/commit.rb b/app/models/commit.rb index a61ed03cf35..9dd0cbacd9e 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -260,7 +260,7 @@ class Commit request_cache(:author) { author_email.downcase } def committer - @committer ||= User.find_by_any_email(committer_email.downcase) + @committer ||= User.find_by_any_email(committer_email) end def parents diff --git a/app/models/user.rb b/app/models/user.rb index 039a3854edb..a400058e87e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -347,7 +347,11 @@ class User < ActiveRecord::Base # Find a User by their primary email or any associated secondary email def find_by_any_email(email, confirmed: false) - by_any_email(email, confirmed: confirmed).take + return unless email + + downcased = email.downcase + + find_by_private_commit_email(downcased) || by_any_email(downcased, confirmed: confirmed).take end # Returns a relation containing all the users for the given Email address @@ -361,6 +365,12 @@ class User < ActiveRecord::Base from_union([users, emails]) end + def find_by_private_commit_email(email) + user_id = Gitlab::PrivateCommitEmail.user_id_for_email(email) + + find_by(id: user_id) + end + def filter(filter_name) case filter_name when 'admins' @@ -633,6 +643,10 @@ class User < ActiveRecord::Base def commit_email return self.email unless has_attribute?(:commit_email) + if super == Gitlab::PrivateCommitEmail::TOKEN + return private_commit_email + end + # The commit email is the same as the primary email if undefined super.presence || self.email end @@ -645,6 +659,10 @@ class User < ActiveRecord::Base has_attribute?(:commit_email) && super end + def private_commit_email + Gitlab::PrivateCommitEmail.for_user(self) + end + # see if the new email is already a verified secondary email def check_for_verified_email skip_reconfirmation! if emails.confirmed.where(email: self.email).any? @@ -1020,13 +1038,21 @@ class User < ActiveRecord::Base def verified_emails verified_emails = [] verified_emails << email if primary_email_verified? + verified_emails << private_commit_email verified_emails.concat(emails.confirmed.pluck(:email)) verified_emails end def verified_email?(check_email) downcased = check_email.downcase - email == downcased ? primary_email_verified? : emails.confirmed.where(email: downcased).exists? + + if email == downcased + primary_email_verified? + else + user_id = Gitlab::PrivateCommitEmail.user_id_for_email(downcased) + + user_id == id || emails.confirmed.where(email: downcased).exists? + end end def hook_attrs |