Change add-on availability to use UserAssignment
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
- Enable the seat management FF (
Feature.enable(:hamilton_seat_management)
) - Create a new group
- 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')
- Check if your user has access to the add-on
group.owners.first.code_suggestions_add_on_available? => false
- Assign the add-on to your user
group.owners.first.assigned_add_ons.create!(add_on_purchase: purchase)
- 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.
-
I have evaluated the MR acceptance checklist for this MR.