Seat assignment removal worker
What does this MR do and why?
Summary
This Merge Request adds a worker that removes seat assignments from an old root namespace after a namespace transfer (group or project).
Details
- It compares the users in the transferred namespace against the members of the old root namespace.
- If any of those users are no longer members of the old namespace hierarchy, their seat assignments are deleted from it.
- This ensures that seat assignments remain accurate and do not persist for users who no longer belong in the original namespace.
Context
This MR is part of a larger effort to correctly handle seat assignment creation and deletion during group or project transfers. Specifically, it is 1 of 4 MRs addressing:
- Creation of seat assignments in the new namespace
- Deletion of outdated seat assignments <- Here
- Add create seats worker to group and project after update hooks (needs 1).
- Add remove outdated seats worker to group and project after update hooks (needs 2).
References
How to set up and validate locally
It is difficult to test this functionality outside the context of a project or group transfer since it needs
- a namespace to transfer (N)
- and the old root namespace (R), namely N's parent before the transfer
Prerequisites
- R must have outdated seat assignments after transfer (S)
- N must have members
- Some or all members of N must no longer be members of R
Test 01:
- Verify the number of outdated seats in R with
GitlabSubscriptions::SeatAssignment.by_namespace(R). The outdated seats must belong to the users being transferred in N. - In the rails console, type
GitlabSubscriptions::SeatAssignments::MemberTransfers::RemoveSeatsWorker.perfom_async(R.root_namespace.id, N). - Verify the number of seats again with
GitlabSubscriptions::SeatAssignment.by_namespace(R). - Notice that the outdated seat assignments in (1) are no longer there.
Query plans
::GitlabSubscriptions::SeatAssignment.where(namespace_id: namespace.id, user_id: batch).delete_all
SQL Example:
DELETE FROM "subscription_seat_assignments" WHERE "subscription_seat_assignments"."namespace_id" = 728 AND "subscription_seat_assignments"."user_id" IN (230, 231)
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.
Edited by Jorge Cook