Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb57
1 files changed, 35 insertions, 22 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 0eb58baae11..8ee0421e45f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -35,6 +35,9 @@ class User < ApplicationRecord
COUNT_CACHE_VALIDITY_PERIOD = 24.hours
+ MAX_USERNAME_LENGTH = 255
+ MIN_USERNAME_LENGTH = 2
+
add_authentication_token_field :incoming_email_token, token_generator: -> { SecureRandom.hex.to_i(16).to_s(36) }
add_authentication_token_field :feed_token
add_authentication_token_field :static_object_token
@@ -96,12 +99,6 @@ class User < ApplicationRecord
# Virtual attribute for impersonator
attr_accessor :impersonator
- attr_writer :max_access_for_group
-
- def max_access_for_group
- @max_access_for_group ||= {}
- end
-
#
# Relations
#
@@ -111,7 +108,7 @@ class User < ApplicationRecord
# Profile
has_many :keys, -> { regular_keys }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
- has_many :expired_today_and_unnotified_keys, -> { expired_today_and_not_notified }, class_name: 'Key'
+ has_many :expired_and_unnotified_keys, -> { expired_and_not_notified }, class_name: 'Key'
has_many :expiring_soon_and_unnotified_keys, -> { expiring_soon_and_not_notified }, class_name: 'Key'
has_many :deploy_keys, -> { where(type: 'DeployKey') }, dependent: :nullify # rubocop:disable Cop/ActiveRecordDependent
has_many :group_deploy_keys
@@ -315,10 +312,11 @@ class User < ApplicationRecord
delegate :other_role, :other_role=, to: :user_detail, allow_nil: true
delegate :bio, :bio=, :bio_html, to: :user_detail, allow_nil: true
delegate :webauthn_xid, :webauthn_xid=, to: :user_detail, allow_nil: true
+ delegate :pronouns, :pronouns=, to: :user_detail, allow_nil: true
accepts_nested_attributes_for :user_preference, update_only: true
accepts_nested_attributes_for :user_detail, update_only: true
- accepts_nested_attributes_for :credit_card_validation, update_only: true
+ accepts_nested_attributes_for :credit_card_validation, update_only: true, allow_destroy: true
state_machine :state, initial: :active do
event :block do
@@ -414,14 +412,7 @@ class User < ApplicationRecord
.without_impersonation
.expired_today_and_not_notified)
end
- scope :with_ssh_key_expired_today, -> do
- includes(:expired_today_and_unnotified_keys)
- .where('EXISTS (?)',
- ::Key
- .select(1)
- .where('keys.user_id = users.id')
- .expired_today_and_not_notified)
- end
+
scope :with_ssh_key_expiring_soon, -> do
includes(:expiring_soon_and_unnotified_keys)
.where('EXISTS (?)',
@@ -791,6 +782,16 @@ class User < ApplicationRecord
end
end
+ def automation_bot
+ email_pattern = "automation%s@#{Settings.gitlab.host}"
+
+ unique_internal(where(user_type: :automation_bot), 'automation-bot', email_pattern) do |u|
+ u.bio = 'The GitLab automation bot used for automated workflows and tasks'
+ u.name = 'GitLab Automation Bot'
+ u.avatar = bot_avatar(image: 'support-bot.png') # todo: add an avatar for automation-bot
+ end
+ end
+
# Return true if there is only single non-internal user in the deployment,
# ghost user is ignored.
def single_user?
@@ -1703,12 +1704,6 @@ class User < ApplicationRecord
def invalidate_issue_cache_counts
Rails.cache.delete(['users', id, 'assigned_open_issues_count'])
-
- if Feature.enabled?(:assigned_open_issues_cache, default_enabled: :yaml)
- run_after_commit do
- Users::UpdateOpenIssueCountWorker.perform_async(self.id)
- end
- end
end
def invalidate_merge_request_cache_counts
@@ -1928,6 +1923,20 @@ class User < ApplicationRecord
confirmed? && !blocked? && !ghost?
end
+ # This attribute hosts a Ci::JobToken::Scope object which is set when
+ # the user is authenticated successfully via CI_JOB_TOKEN.
+ def ci_job_token_scope
+ Gitlab::SafeRequestStore[ci_job_token_scope_cache_key]
+ end
+
+ def set_ci_job_token_scope!(job)
+ Gitlab::SafeRequestStore[ci_job_token_scope_cache_key] = Ci::JobToken::Scope.new(job.project)
+ end
+
+ def from_ci_job_token?
+ ci_job_token_scope.present?
+ end
+
protected
# override, from Devise::Validatable
@@ -2091,6 +2100,10 @@ class User < ApplicationRecord
def update_highest_role_attribute
id
end
+
+ def ci_job_token_scope_cache_key
+ "users:#{id}:ci:job_token_scope"
+ end
end
User.prepend_mod_with('User')