Skip to content

Add ability to assign and unassign code suggestions add-on

Vamsi Vempati requested to merge 411949-add-ability-to-assign-and-unassign into master

What does this MR do and why?

Adds ability to assign and un-assign code suggestions add-on on usage quotas page.

This MR is the first of the work needed for #420010.

Description MR
Add ability to assign and un-assign code suggestions add-on 👈 You are here
Handle errors when assigning and un-assigning !128320 (merged)
Update code suggestions statistics card with latest counts when assigning and un-assigning add-ons 🚧

All changes are behind enable_hamilton_in_usage_quotas_ui feature flag.

Note: When assigning and un-assigning add-ons, the state is not persisted on refresh. This is because the current add-on assignment status comes from billable_members API and the changes needed to send the add-on status in the billable members list is in progress, so the add-on status is always in OFF state on page load for now.

Related to #420010

Screenshots or screen recordings

Scenario Screenshot
Assigning and un-assigning code suggestions add-on
Screen recordingScreen_Recording_2023-08-02_at_2.34.15_PM
Loading state while assigning
ScreenshotScreenshot_2023-08-02_at_2.36.31_PM
Loading state while un-assigning
ScreenshotScreenshot_2023-08-02_at_2.36.40_PM

How to set up and validate locally

  1. Customers Dot needs to be setup in order to view the billing page for a group

  2. Start GDK in SaaS mode GITLAB_SIMULATE_SAAS=1 gdk start

  3. Create a Group

  4. Enable enable_hamilton_in_usage_quotas_ui FF (globally, or for your group)

  5. Buy a Subscription for your group from Settings > Billing

  6. Visit /groups/<your-namespace-name>/-/usage_quotas#seats-quota-tab

  7. Purchase add-on for namespace

    # Get the desired namespace
    namespace = Namespace.last
    # Create an add-on
    add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
    # Purchase add-ons for the namespace
    add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(
      add_on: add_on, namespace: namespace, expires_on: 1.month.from_now, quantity: 2, purchase_xid: 'A-S0001'
    )
  8. Add this snippet here to enable add-on assignment. This enables the add-on assignment for the first 2 users in the list (as per assignable value).

     state.members[0].add_ons = { assigned: [], assignable: [{ name: 'CODE_SUGGESTIONS' }] };
     state.members[1].add_ons = { assigned: [], assignable: [{ name: 'CODE_SUGGESTIONS' }] };
     state.members[2].add_ons = { assigned: [], assignable: [] };

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vamsi Vempati

Merge request reports