Skip to content

Use active and correct add_on_purchase

Bishwa Hang Rai requested to merge fix-logic-for-active-add-on into master

What does this MR do and why?

While I was looking into the code for user#code_suggestions_add_on_available? again, I found out that we are only checking for user_add_on_assignment presence. However, it would be better if we checked this for correct add_on_purchase, i.e., if the purchase was for code_suggestion as add_on, and if the purchase is still active.

      GitlabSubscriptions::UserAddOnAssignment.by_user(self).for_active_code_suggestions_purchase.any?

Related MR: Code suggestions: Update condition to check cut... (!138334 - merged)

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.

How to set up and validate locally

  1. Make sure that GDK is run as self-managed instance, i.e., GITLAB_SIMULATE_SAAS=0
  2. Open up a rails console GITLAB_SIMULATE_SAAS=0 gdk rails c
  3. Create a new AddOnPurchase record for testing:
# cleanup any existing old test records
::GitlabSubscriptions::AddOnPurchase.destroy_all
# create a add_on record if not already created
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
# create a EXPIRED add_on_purchase record without the namespace, mimicking SM instance
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(add_on: add_on, expires_on: 1.day.ago, quantity: 10, purchase_xid: 'A-12345')
user = User.first
add_on_purchase.assigned_users.create!(user: user)

# when on master branch
user.code_suggestions_add_on_available? # true

# when on this MR branch
user.code_suggestions_add_on_available? # false
Edited by Bishwa Hang Rai

Merge request reports