Prevent multiple users from a source being mapped to the same user on destination

About

Currently, a group owner can assign the same real user to multiple placeholder user contributions. This makes one real user on the destination become the owner of more than one user's contributions from the source.

Problem

This can lead to errors in some situations where the table enforces unique user ID constraints.

Proposal

The same real user should be allowed to be assigned contributions from 2 Direct Transfer imports within the same top-level namespace so long as they were from different source hosts.

But they should not be allowed to be assigned contributions from 2 Direct Transfer imports within the same top-level namespace that were from the same source host.

We need to account for the situation where:

For example, a unique user ID constraint error can happen if a user manually adds themselves as a reviewer of a merge request, which also has a placeholder user as a reviewer. Later, the group owner reassigns the placeholder user contribution to the same user, which will result in the reassign process, adding the user twice as a reviewer.

So, since the user is already a reviewer, the reassign process should ignore the reassignment of such a contribution.

Technical proposal

When assigning source users to real users, we want to ensure that the Import::SourceUser#assigned_to_user_id (the ID of the real user) is unique across these properties:

  • namespace_id
  • import_type
  • source_hostname

We can do this through a model validation, plus database constraint (optional, but most likely recommended).

Note: In addition to adding the validation, make sure the ReassignMutation returns a proper error and that reassignment via CSV also handles such a case.

Edited by Rodrigo Tomonari