Commit 582bff2c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #9126 from Senorsen/master

Allow user to choose which email to be public
parents ae6d0aaa 7b28218f
...@@ -73,6 +73,7 @@ v 7.10.0 (unreleased) ...@@ -73,6 +73,7 @@ v 7.10.0 (unreleased)
- Automatically setup GitLab CI project for forks if origin project has GitLab CI enabled - Automatically setup GitLab CI project for forks if origin project has GitLab CI enabled
- Bust group page project list cache when namespace name or path changes. - Bust group page project list cache when namespace name or path changes.
- Explicitly set image alt-attribute to prevent graphical glitches if gravatars could not be loaded - Explicitly set image alt-attribute to prevent graphical glitches if gravatars could not be loaded
- Allow user to choose a public email to show on public profile
v 7.9.3 v 7.9.3
- Contains no changes - Contains no changes
......
...@@ -3,6 +3,7 @@ class Profiles::EmailsController < ApplicationController ...@@ -3,6 +3,7 @@ class Profiles::EmailsController < ApplicationController
def index def index
@primary = current_user.email @primary = current_user.email
@public_email = current_user.public_email
@emails = current_user.emails @emails = current_user.emails
end end
...@@ -19,7 +20,8 @@ class Profiles::EmailsController < ApplicationController ...@@ -19,7 +20,8 @@ class Profiles::EmailsController < ApplicationController
@email.destroy @email.destroy
current_user.set_notification_email current_user.set_notification_email
current_user.save if current_user.notification_email_changed? current_user.set_public_email
current_user.save if current_user.notification_email_changed? or current_user.public_email_changed?
respond_to do |format| respond_to do |format|
format.html { redirect_to profile_emails_url } format.html { redirect_to profile_emails_url }
......
...@@ -67,9 +67,10 @@ class ProfilesController < ApplicationController ...@@ -67,9 +67,10 @@ class ProfilesController < ApplicationController
def user_params def user_params
params.require(:user).permit( params.require(:user).permit(
:email, :password, :password_confirmation, :bio, :name, :username, :email, :password, :password_confirmation, :bio, :name,
:skype, :linkedin, :twitter, :website_url, :color_scheme_id, :theme_id, :username, :skype, :linkedin, :twitter, :website_url,
:avatar, :hide_no_ssh_key, :hide_no_password, :location :color_scheme_id, :theme_id, :avatar, :hide_no_ssh_key,
:hide_no_password, :location, :public_email
) )
end end
end end
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
# password_automatically_set :boolean default(FALSE) # password_automatically_set :boolean default(FALSE)
# bitbucket_access_token :string(255) # bitbucket_access_token :string(255)
# bitbucket_access_token_secret :string(255) # bitbucket_access_token_secret :string(255)
# public_email :string(255) default(""), not null
# #
require 'carrierwave/orm/activerecord' require 'carrierwave/orm/activerecord'
...@@ -123,6 +124,7 @@ class User < ActiveRecord::Base ...@@ -123,6 +124,7 @@ class User < ActiveRecord::Base
validates :name, presence: true validates :name, presence: true
validates :email, presence: true, email: { strict_mode: true }, uniqueness: true validates :email, presence: true, email: { strict_mode: true }, uniqueness: true
validates :notification_email, presence: true, email: { strict_mode: 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 :bio, length: { maximum: 255 }, allow_blank: true
validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :username, validates :username,
...@@ -142,6 +144,7 @@ class User < ActiveRecord::Base ...@@ -142,6 +144,7 @@ class User < ActiveRecord::Base
before_validation :generate_password, on: :create before_validation :generate_password, on: :create
before_validation :sanitize_attrs before_validation :sanitize_attrs
before_validation :set_notification_email, if: ->(user) { user.email_changed? } 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 before_save :ensure_authentication_token
after_save :ensure_namespace_correct after_save :ensure_namespace_correct
...@@ -443,6 +446,12 @@ class User < ActiveRecord::Base ...@@ -443,6 +446,12 @@ class User < ActiveRecord::Base
end end
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 def set_projects_limit
connection_default_value_defined = new_record? && !projects_limit_changed? connection_default_value_defined = new_record? && !projects_limit_changed?
return unless self.projects_limit.nil? || connection_default_value_defined return unless self.projects_limit.nil? || connection_default_value_defined
......
...@@ -20,9 +20,13 @@ ...@@ -20,9 +20,13 @@
%li %li
%strong= @primary %strong= @primary
%span.label.label-success Primary Email %span.label.label-success Primary Email
- if @primary === @public_email
%span.label.label-info Public Email
- @emails.each do |email| - @emails.each do |email|
%li %li
%strong= email.email %strong= email.email
- if email.email === @public_email
%span.label.label-info Public Email
%span.cgray %span.cgray
added #{time_ago_with_tooltip(email.created_at)} added #{time_ago_with_tooltip(email.created_at)}
= link_to 'Remove', profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-remove pull-right' = link_to 'Remove', profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-remove pull-right'
......
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
- else - else
%span.help-block We also use email for avatar detection if no avatar is uploaded. %span.help-block We also use email for avatar detection if no avatar is uploaded.
.form-group
= f.label :public_email, class: "control-label"
.col-sm-10
= f.select :public_email, options_for_select(@user.all_emails, selected: @user.public_email), {include_blank: 'Do not show in profile'}, class: "form-control"
%span.help-block This email will be displayed on your public profile.
.form-group .form-group
= f.label :skype, class: "control-label" = f.label :skype, class: "control-label"
.col-sm-10= f.text_field :skype, class: "form-control" .col-sm-10= f.text_field :skype, class: "form-control"
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
%li %li
%span.light Member since %span.light Member since
%strong= user.created_at.stamp("Aug 21, 2011") %strong= user.created_at.stamp("Aug 21, 2011")
- unless user.public_email.blank?
%li
%span.light E-mail:
%strong= link_to user.public_email, "mailto:#{user.public_email}"
- unless user.skype.blank? - unless user.skype.blank?
%li %li
%span.light Skype: %span.light Skype:
......
class AddPublicEmailToUsers < ActiveRecord::Migration
def change
add_column :users, :public_email, :string, default: "", null: false
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150411180045) do ActiveRecord::Schema.define(version: 20150413192223) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -476,6 +476,7 @@ ActiveRecord::Schema.define(version: 20150411180045) do ...@@ -476,6 +476,7 @@ ActiveRecord::Schema.define(version: 20150411180045) do
t.string "bitbucket_access_token" t.string "bitbucket_access_token"
t.string "bitbucket_access_token_secret" t.string "bitbucket_access_token_secret"
t.string "location" t.string "location"
t.string "public_email", default: "", null: false
end end
add_index "users", ["admin"], name: "index_users_on_admin", using: :btree add_index "users", ["admin"], name: "index_users_on_admin", using: :btree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment