From 5f08830090fb6d56a14bd4aaca107b99e2b0975b Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 21 Nov 2018 12:17:14 +0100 Subject: Set the name of a user-namespace to the user name Instead of setting the name of the namespace to the user's username, set it to the user's name. This is more consistent with how we name the routes: The route-name of a namespace is the human name of the routable. In the case of a user-namespace, this is the owner's name. When we change a user's name (both on create and update), we now also update the namespace-name to the user's name. This will make sure that if we also correctly update all the nested routes. --- app/models/user.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 26be197209a..02637b70f03 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1117,9 +1117,10 @@ class User < ApplicationRecord def ensure_namespace_correct if namespace - namespace.path = namespace.name = username if username_changed? + namespace.path = username if username_changed? + namespace.name = name if name_changed? else - build_namespace(path: username, name: username) + build_namespace(path: username, name: name) end end -- cgit v1.2.1 From 4959d8fd4967e5769c8c81bf37e18ea13f607e2b Mon Sep 17 00:00:00 2001 From: Adam Hegyi Date: Mon, 15 Jul 2019 21:07:54 +0000 Subject: Migrate null values for users.private_profile - Background migration for changing null values to false - Set false as default value for private_profile DB column --- app/models/user.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 02637b70f03..0fd3daa3383 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -185,6 +185,7 @@ class User < ApplicationRecord before_validation :set_notification_email, if: :new_record? before_validation :set_public_email, if: :public_email_changed? before_validation :set_commit_email, if: :commit_email_changed? + before_save :default_private_profile_to_false before_save :set_public_email, if: :public_email_changed? # in case validation is skipped before_save :set_commit_email, if: :commit_email_changed? # in case validation is skipped before_save :ensure_incoming_email_token @@ -1491,6 +1492,12 @@ class User < ApplicationRecord private + def default_private_profile_to_false + return unless private_profile_changed? && private_profile.nil? + + self.private_profile = false + end + def has_current_license? false end -- cgit v1.2.1 From 40d6d5e2d0123f1417bb5d3d1ead47bd525f8dac Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Fri, 19 Jul 2019 01:04:43 +0800 Subject: Make pipeline emails respect group email setting When a user's notification email is set for a group, we should use that for pipeline emails --- app/models/user.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 0fd3daa3383..b439d1c0c16 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1259,6 +1259,11 @@ class User < ApplicationRecord end end + def notification_email_for(notification_group) + # Return group-specific email address if present, otherwise return global notification email address + notification_group&.notification_email_for(self) || notification_email + end + def notification_settings_for(source) if notification_settings.loaded? notification_settings.find do |notification| -- cgit v1.2.1 From 0c0232e623ab8d6d8cf3b4e7268d1a28d2c5f40b Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 1 Aug 2019 16:09:30 +0100 Subject: Fix a bug in User#accessible_deploy_keys --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index b439d1c0c16..74bb66d1371 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -942,7 +942,7 @@ class User < ApplicationRecord def accessible_deploy_keys @accessible_deploy_keys ||= begin - key_ids = project_deploy_keys.pluck(:id) + key_ids = project_deploy_keys.pluck(:deploy_key_id) key_ids.push(*DeployKey.are_public.pluck(:id)) DeployKey.where(id: key_ids) end -- cgit v1.2.1 From ded3b7574dbd6e1b3249c9e5bbcc61090c733142 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 1 Aug 2019 16:22:56 +0100 Subject: Stop using pluck to get deploy keys for a user --- app/models/user.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 74bb66d1371..4630552e02e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -933,7 +933,7 @@ class User < ApplicationRecord end def project_deploy_keys - DeployKey.unscoped.in_projects(authorized_projects.pluck(:id)).distinct(:id) + DeployKey.in_projects(authorized_projects.select(:id)).distinct(:id) end def highest_role @@ -941,11 +941,10 @@ class User < ApplicationRecord end def accessible_deploy_keys - @accessible_deploy_keys ||= begin - key_ids = project_deploy_keys.pluck(:deploy_key_id) - key_ids.push(*DeployKey.are_public.pluck(:id)) - DeployKey.where(id: key_ids) - end + DeployKey.from_union([ + DeployKey.where(id: project_deploy_keys.select(:deploy_key_id)), + DeployKey.are_public + ]) end def created_by -- cgit v1.2.1 From 59976090b52d401dc4d23b726b2168186524f269 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 25 Jan 2019 21:53:00 +0100 Subject: Add /starrers view for projects --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 4630552e02e..f772e3f6907 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,6 +282,7 @@ class User < ApplicationRecord scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :with_emails, -> { preload(:emails) } scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } + scope :has_starred, ->(project) { joins(:users_star_projects).where('users_star_projects.project_id': project.id) } # Limits the users to those that have TODOs, optionally in the given state. # -- cgit v1.2.1 From 6baff6504b234e209a5e1d78349dbd2589d5d7e8 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 28 Jan 2019 13:19:53 +0100 Subject: Change sorting options for starrers: name (asc/desc), most/least recent star --- app/models/user.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index f772e3f6907..4630552e02e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,7 +282,6 @@ class User < ApplicationRecord scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :with_emails, -> { preload(:emails) } scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } - scope :has_starred, ->(project) { joins(:users_star_projects).where('users_star_projects.project_id': project.id) } # Limits the users to those that have TODOs, optionally in the given state. # -- cgit v1.2.1 From e8bdcdf0f89d88463f6fb8a67e85f315e6a9097d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 2 Feb 2019 20:48:27 +0100 Subject: Expose time since starring on project/:id/starrers API endpoint; exclude private profiles here as well --- app/models/user.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 4630552e02e..d671c291ec5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,6 +282,15 @@ class User < ApplicationRecord scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :with_emails, -> { preload(:emails) } scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } + scope :with_visible_profile, -> (user) { + if user.nil? + where(private_profile: [false, nil]) + elsif user.admin? + all + else + where(private_profile: [false, nil]).or where(id: user.id) + end + } # Limits the users to those that have TODOs, optionally in the given state. # -- cgit v1.2.1 From 4f76331ddcfcaf32a868b6e814474fbac6c343eb Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 8 Feb 2019 15:05:22 +0100 Subject: Make users.private_profile default false (previously had no default value) --- app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index d671c291ec5..cfb8cd3819d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -284,11 +284,11 @@ class User < ApplicationRecord scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } scope :with_visible_profile, -> (user) { if user.nil? - where(private_profile: [false, nil]) + where(private_profile: false) elsif user.admin? all else - where(private_profile: [false, nil]).or where(id: user.id) + where(private_profile: false).or where(id: user.id) end } -- cgit v1.2.1 From e726ed5e128893158f102b87e1407ec0a36fc3ce Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 3 Aug 2019 12:57:33 +0200 Subject: Handle reviewer comments on !24690 --- app/models/user.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index cfb8cd3819d..ac83c8e3256 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,15 +282,17 @@ class User < ApplicationRecord scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :with_emails, -> { preload(:emails) } scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } - scope :with_visible_profile, -> (user) { - if user.nil? - where(private_profile: false) - elsif user.admin? + scope :with_public_profile, -> { where(private_profile: false) } + + def self.with_visible_profile(user) + return with_public_profile if user.nil? + + if user.admin? all else - where(private_profile: false).or where(id: user.id) + with_public_profile.or(where(id: user.id)) end - } + end # Limits the users to those that have TODOs, optionally in the given state. # -- cgit v1.2.1 From 5cbe16c3d2a3a3667021fb8c81f743308aefbdae Mon Sep 17 00:00:00 2001 From: Alex Buijs Date: Wed, 31 Jul 2019 16:48:38 +0200 Subject: Set Devise's allow_unconfirmed_access_for to 30 days --- app/models/user.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index ac83c8e3256..4adc44a9375 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1505,6 +1505,13 @@ class User < ApplicationRecord super end + # override from Devise::Confirmable + def confirmation_period_valid? + return false if Feature.disabled?(:soft_email_confirmation) + + super + end + private def default_private_profile_to_false -- cgit v1.2.1 From 2f8709fb53137c2f53409f2400cd85083b06d6f6 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 7 Aug 2019 22:22:02 +0200 Subject: Fix deprecation warning for dangerous order usage --- app/models/user.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index ac83c8e3256..374e00987c5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -438,18 +438,20 @@ class User < ApplicationRecord order = <<~SQL CASE - WHEN users.name = %{query} THEN 0 - WHEN users.username = %{query} THEN 1 - WHEN users.email = %{query} THEN 2 + WHEN users.name = :query THEN 0 + WHEN users.username = :query THEN 1 + WHEN users.email = :query THEN 2 ELSE 3 END SQL + sanitized_order_sql = Arel.sql(sanitize_sql_array([order, query: query])) + where( fuzzy_arel_match(:name, query, lower_exact_match: true) .or(fuzzy_arel_match(:username, query, lower_exact_match: true)) .or(arel_table[:email].eq(query)) - ).reorder(order % { query: ApplicationRecord.connection.quote(query) }, :name) + ).reorder(sanitized_order_sql, :name) end # Limits the result set to users _not_ in the given query/list of IDs. -- cgit v1.2.1 From a06410d995e1200c7734b2d50e68506320d13dd0 Mon Sep 17 00:00:00 2001 From: Aishwarya Subramanian Date: Mon, 26 Aug 2019 18:20:18 +0000 Subject: Using before_save method instead of setter Removed unused method for name setter method --- app/models/user.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index 6131a8dc710..6107aaa7fca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,6 +161,8 @@ class User < ApplicationRecord # # Note: devise :validatable above adds validations for :email and :password validates :name, presence: true, length: { maximum: 128 } + validates :first_name, length: { maximum: 255 } + validates :last_name, length: { maximum: 255 } validates :email, confirmation: true validates :notification_email, presence: true validates :notification_email, devise_email: true, if: ->(user) { user.notification_email != user.email } @@ -881,7 +883,15 @@ class User < ApplicationRecord end def first_name - name.split.first unless name.blank? + read_attribute(:first_name) || begin + name.split(' ').first unless name.blank? + end + end + + def last_name + read_attribute(:last_name) || begin + name.split(' ').drop(1).join(' ') unless name.blank? + end end def projects_limit_left -- cgit v1.2.1