Skip to content

User mapping - Placeholder User Type

Sam Word requested to merge 443533-user-mapping-placeholder-user-type into master

What does this MR do and why?

This MR adds a new internal user user_type: :placeholder. It also adds a new model, Imports::SourceUser and corresponding database table: import_source_users. This will be the model we use to map import user contributions to internal GitLab users, allowing real users to accept the import mapping and have their contributions from the source mapped to them in GitLab. Imports::SourceUsers can also be mapped to migration users if the limit on placeholder users has been reached for the namespace (not implemented yet).

The new service, Gitlab::Imports::SourceUserMapper checks if an Imports::SourceUser exists for the current import and source_user_identifier. If a source_user exists, it returns its placeholder user or real reassigned user. If it does not exist, it creates a source user and an associated placeholder user. The placeholder user is created with the following attributes:

  • name "Placeholder #{source_name}". If source_name is nil, it defaults to "#{import_type} Source User"
  • username "#{source_username}_placeholder_user_#{unique_number}". If source_username is nil, it defaults to "#{import_type}_source_username"
  • email "#{source_username}_placeholder_user_#{unique_number}@gitlab.com"

Gitlab::Utils::Uniquify is used to generate unique_number to avoid super long UUID strings. Otherwise, this MR does not address username, name, or email validation concerns.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

No UI changes in this MR.

How to set up and validate locally

This MR only creates placeholder users, a service to create placeholder users and Imports::SourceUsers, but it's not implemented in any importer yet. The best way to test this MR locally is to either run the specs, or open a Rails console and call Import::SourceUsers::CreateService manually:

namespace_id = Namespace.first
source_hostname = 'github.com'
import_type = 'github'
source_user_identifier = '1234'
source_username = 'a_pry_contributor'
source_name = 'Pry Contributor'

service = Gitlab::Imports::SourceUserMapper.new(namespace: namespace, import_type: import_type, source_hostname: source_hostname)
service.find_or_create_internal_user(source_name: source_name, source_username: source_username, source_user_identifier: source_user_identifier)

Then verify that the service created a new User with user_type: :placeholder, and the correct name, email and username attributes. Repeat the process with an existing source user to show that no new users were created and the existing placeholder was returned. And you can repeat it again with a manually created a source user with a real, reassigned user to show that it returns the reassigned user.

Related to #443533

Edited by Sam Word

Merge request reports