Refactor organization user transfer concern to service
What does this MR do and why?
After looking at data we realize that we will have a significant number of users to migrate to organizations that do not belong to a top-level group. This MR moves the existing user transfer functionality from a concern to a proper service.
When the user transfer is called from the group transfer service we need to detect the presence of an existing transaction so we don't create nested transactions. This ensures if a failure occurs, the entire transfer operation, including group transfer, is rolled back to the original state.
The aim here is to make as few code changes as possible, and certainly to avoid any behavior changes. All update queries were previously vetted and approved by database. The very minimal changes to the group transfer service specs are a great indicator that we're not changing any behavior. These services are not in production use yet, either.
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
-
Enable the required feature flags
Feature.enable(:organization_scoped_paths) Feature.enable(:ui_for_organizations) Feature.enable(:organization_switching) -
Create a new organization, signed in as an instance admin. Click the
+menu,New organization. -
Create a new test user and test group. Add the user as a member of the group.
-
Initiate a transfer in the Rails console:
service = Organizations::Groups::TransferService.new( group: Group.last, new_organization: Organizations::Organization.last, current_user: User.first ) result = service.execute puts "Success: #{result.success?}" puts "Message: #{result.message}" if result.error? puts "Group org ID: #{group.reload.organization_id} (should be #{new_org.id})" puts "User org ID: #{user.reload.organization_id} (should be #{new_org.id})"
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.