Class: Gitlab::Import::PlaceholderUserCreator

Inherits:
Object
  • Object
show all
Includes:
Gitlab::InternalEventsTracking
Defined in:
lib/gitlab/import/placeholder_user_creator.rb

Constant Summary collapse

PLACEHOLDER_EMAIL_REGEX =
::Gitlab::UntrustedRegexp.new(
  "_placeholder_[[:alnum:]]+@noreply.#{Settings.gitlab.host}"
)
LEGACY_PLACEHOLDER_EMAIL_REGEX =
::Gitlab::UntrustedRegexp.new(
  "(#{::Import::HasImportSource::IMPORT_SOURCES.except(:none).keys.join('|')})" \
    '(_[0-9A-Fa-f]+_[0-9]+' \
    "@#{Settings.gitlab.host})"
)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Constructor Details

#initialize(source_user) ⇒ PlaceholderUserCreator

Returns a new instance of PlaceholderUserCreator.



26
27
28
# File 'lib/gitlab/import/placeholder_user_creator.rb', line 26

def initialize(source_user)
  @source_user = source_user
end

Class Method Details

.placeholder_email?(email) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/gitlab/import/placeholder_user_creator.rb', line 21

def placeholder_email?(email)
  PLACEHOLDER_EMAIL_REGEX.match?(email) || LEGACY_PLACEHOLDER_EMAIL_REGEX.match?(email)
end

Instance Method Details

#executeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/import/placeholder_user_creator.rb', line 30

def execute
  user_params = {
    user_type: :placeholder,
    name: placeholder_name,
    username: username_and_email_generator.username,
    email: username_and_email_generator.email,
    organization_id: namespace.organization_id,
    skip_confirmation: true
  }

  user = Users::AuthorizedBuildService.new(nil, user_params).execute

  user.build_placeholder_user_detail(namespace: namespace, organization: namespace.organization)
  user.save!

  log_placeholder_user_creation(user)
  track_placeholder_user_creation(user)

  user
end

#placeholder_nameObject



51
52
53
54
55
56
# File 'lib/gitlab/import/placeholder_user_creator.rb', line 51

def placeholder_name
  # Some APIs don't expose users' names, so set a default if it's nil
  return "Placeholder #{import_type} Source User" unless source_name

  "Placeholder #{source_name.slice(0, 127)}"
end