diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/models/user.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index c735f20b92c..b4ec6064ff8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,7 +31,7 @@ class User < ApplicationRecord INSTANCE_ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT = 10 - BLOCKED_PENDING_APPROVAL_STATE = 'blocked_pending_approval'.freeze + BLOCKED_PENDING_APPROVAL_STATE = 'blocked_pending_approval' add_authentication_token_field :incoming_email_token, token_generator: -> { SecureRandom.hex.to_i(16).to_s(36) } add_authentication_token_field :feed_token @@ -1358,6 +1358,7 @@ class User < ApplicationRecord def hook_attrs { + id: id, name: name, username: username, avatar_url: avatar_url(only_path: false), @@ -1377,7 +1378,14 @@ class User < ApplicationRecord def set_username_errors namespace_path_errors = self.errors.delete(:"namespace.path") - self.errors[:username].concat(namespace_path_errors) if namespace_path_errors + + return unless namespace_path_errors&.any? + + if namespace_path_errors.include?('has already been taken') && !User.exists?(username: username) + self.errors.add(:base, :username_exists_as_a_different_namespace) + else + self.errors[:username].concat(namespace_path_errors) + end end def username_changed_hook @@ -1564,6 +1572,12 @@ class User < ApplicationRecord end end + def review_requested_open_merge_requests_count(force: false) + Rails.cache.fetch(['users', id, 'review_requested_open_merge_requests_count'], force: force, expires_in: 20.minutes) do + MergeRequestsFinder.new(self, reviewer_id: id, state: 'opened', non_archived: true).execute.count + end + end + def assigned_open_issues_count(force: false) Rails.cache.fetch(['users', id, 'assigned_open_issues_count'], force: force, expires_in: 20.minutes) do IssuesFinder.new(self, assignee_id: self.id, state: 'opened', non_archived: true).execute.count @@ -1607,6 +1621,7 @@ class User < ApplicationRecord def invalidate_merge_request_cache_counts Rails.cache.delete(['users', id, 'assigned_open_merge_requests_count']) + Rails.cache.delete(['users', id, 'review_requested_open_merge_requests_count']) end def invalidate_todos_done_count |