Class: Gitlab::BitbucketServerImport::UserFinder
- Inherits:
-
Object
- Object
- Gitlab::BitbucketServerImport::UserFinder
- Defined in:
- lib/gitlab/bitbucket_server_import/user_finder.rb
Overview
Class that can be used for finding a GitLab user ID based on a BitBucket user
Constant Summary collapse
- CACHE_KEY =
'bitbucket_server-importer/user-finder/%{project_id}/%{by}/%{value}'- CACHE_USER_ID_NOT_FOUND =
-1
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #author_id(object) ⇒ Object
- #find_user_id(by:, value:) ⇒ Object
-
#initialize(project) ⇒ UserFinder
constructor
project - An instance of
Project. -
#uid(object) ⇒ Object
Object should behave as a object so we can remove object.is_a?(Hash) check This will be fixed in gitlab.com/gitlab-org/gitlab/-/issues/412328.
Constructor Details
#initialize(project) ⇒ UserFinder
project - An instance of Project
14 15 16 |
# File 'lib/gitlab/bitbucket_server_import/user_finder.rb', line 14 def initialize(project) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/gitlab/bitbucket_server_import/user_finder.rb', line 8 def project @project end |
Instance Method Details
#author_id(object) ⇒ Object
18 19 20 |
# File 'lib/gitlab/bitbucket_server_import/user_finder.rb', line 18 def (object) uid(object) || project.creator_id end |
#find_user_id(by:, value:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gitlab/bitbucket_server_import/user_finder.rb', line 38 def find_user_id(by:, value:) return unless value cache_key = build_cache_key(by, value) cached_id = cache.read_integer(cache_key) return if cached_id == CACHE_USER_ID_NOT_FOUND return cached_id if cached_id user = User.find_by_any_email(value, confirmed: true) user&.id.tap do |id| cache.write(cache_key, id || CACHE_USER_ID_NOT_FOUND) end end |
#uid(object) ⇒ Object
Object should behave as a object so we can remove object.is_a?(Hash) check This will be fixed in gitlab.com/gitlab-org/gitlab/-/issues/412328
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/bitbucket_server_import/user_finder.rb', line 24 def uid(object) # We want this to only match either placeholder or email # depending on the flag state. There should be no fall-through. if user_mapping_enabled?(project) return unless object[:username] return project.root_ancestor.owner_id if project.root_ancestor.user_namespace? (object).mapped_user_id else find_user_id(by: :email, value: object.is_a?(Hash) ? object[:author_email] : object.) end end |