Added event and worker to apply outstanding member promotions

Context

  • As part of &13328 (closed) we are working on Adding controls for Admins/Owners to manage Billable Members promotion/addition in Groups and Projects (still a WIP feature).
  • When PromotionManagement conditions are applicable(code)(primarily when user is non-billable and the current change would make them billable), we queue the User/Member Addition/Promotion request if that addition/promotion will increase the Billable count for the SM instance (We will bring this to SaaS eventually)
  • We allow admins to promote members to billable role, but when that happens we want to ensure any outstanding pending promotion for the user also gets applied async.
  • PS: this feature is behind a disabled feature flag and setting, so it isnt available on prod.

What does this MR do and why?

When admin promotes/adds/updates a member on a billable role, and if the feature is enabled

  • An event is triggered to signify MembershipModifiedByAdminEvent
    • This event is only triggered if
      • it is SM instance
      • current user is admin
      • promotion management feature is enabled
      • members new role is a billable role
  • A worker is listening for this event, and when the event is received
    • It returns early if feature isn't enabled, or if there are no pending promotions for the user
    • It triggers ProcessUserBillablePromotionService to apply pending promotions for the user.

ref: #470661 (closed)

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

OutstandingPendingPromotions.mov

How to set up and validate locally

  1. Have an Ultimate License, and simulate Ultimate Self Managed setup (export GITLAB_SIMULATE_SAAS=0 gdk restart)
  2. Enable the Setting `Gitlab::CurrentSettings.update!(enable_member_promotion_management: true)
  3. Enable the Feature Flag Feature.enable(:member_promotion_management)
  4. Create promotion requests:
    1. Visit a group/project as an owner (e.g. https://gdk.test:3443/groups/gitlab-org/-/group_members)
    2. Click on invite members button
    3. Find a member. This member should have GUEST as the highest role in the hole instance. See !149094 (comment 1869616221) for details
    4. Invite them as any role higher then GUEST
    5. Check the Promotion tab and find the user listed.
  5. Login as Admin
    1. Promote the user queued in the previous step to a billable role
    2. Verify that the user got promoted, here as well as in the previous group/project
Edited by Suraj Tripathi

Merge request reports

Loading