Skip to content

Change add-on availability to use UserAssignment

Josianne Hyson requested to merge jh/use_assignments_for_eligibility into master

What does this MR do and why?

Addresses: https://gitlab.com/gitlab-org/gitlab/-/issues/419667+

Change add-on availability to use UserAssignment

We want users have access to the code suggestions add on only when they've been assigned a seat by an admin. When the seat-management FF is enabled, check that this user has been assigned a seat to determine their eligibility.

How to set up and validate locally

  1. Enable the seat management FF (Feature.enable(:hamilton_seat_management))
  2. Create a new group
  3. Create an add-on purchase for the group
    group = Group.last
    purchase = GitlabSubscriptions::AddOnPurchase.create!(add_on: GitlabSubscriptions::AddOn.find_or_create_by_name(:code_suggestions), namespace: group, quantity: 10, expires_on: 1.year.from_now, purchase_xid: 'A-12345')
  4. Check if your user has access to the add-on
    group.owners.first.code_suggestions_add_on_available?
    => false
  5. Assign the add-on to your user
    group.owners.first.assigned_add_ons.create!(add_on_purchase: purchase)
  6. Check if your user has access to the add-on
    group.owners.first.code_suggestions_add_on_available?
    => true

SQL Queries

Two queries are made when code_suggestions_add_on_available? is called:

Find the Code Suggestions add-on

Production query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/22955/commands/74002

Local query plan with data: https://explain.depesz.com/s/akdw

SELECT
    "subscription_add_ons"."id"
FROM
    "subscription_add_ons"
WHERE
    "subscription_add_ons"."name" = 1
LIMIT 1;

Find an assignment to the add-on for a user

Production query plan (for my GitLab user without an assignment): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/22955/commands/74003

Local query plan for a user with lots of assignment data: https://explain.depesz.com/s/gUgQ

SELECT
    1 AS one
FROM
    "subscription_user_add_on_assignments"
    INNER JOIN "subscription_add_on_purchases" ON "subscription_add_on_purchases"."id" = "subscription_user_add_on_assignments"."add_on_purchase_id"
WHERE
    "subscription_user_add_on_assignments"."user_id" = 4981524
    AND (expires_on >= '2023-10-10')
    AND "subscription_add_on_purchases"."subscription_add_on_id" = 1
LIMIT 1;

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 Josianne Hyson

Merge request reports

Loading