Skip to content

Fix UserAddOnAssignmentsResolver for SM

What does this MR do and why?

This MR fix the UserAddOnAssignmentsResolver bug and resolves https://gitlab.com/gitlab-org/gitlab/-/issues/434920

How to set up and validate locally

On Master, verify that the bug exists:

  • git checkout master
  • GITLAB_SIMULATE_SAAS=0 rails c
  • Feature.enable(:self_managed_code_suggestions)
  • GitlabSubscriptions::AddOnPurchase.destroy_all
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(A-S0001'
  add_on: add_on, expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001'
) # No Namespace to simulate SM
add_on_purchase_id = add_on_purchase.to_global_id.to_s
  • Run a SM server gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=0 gdk rails s
  • Fetch eligible users, go to http://gdk.test:3000/-/graphql-explorer and run:
{
  selfManagedAddOnEligibleUsers(
    addOnType: CODE_SUGGESTIONS
    first: 20
  ) {
    nodes {
      id
      username
      name
      publicEmail
      avatarUrl
      webUrl
      lastActivityOn
      lastLoginAt
      addOnAssignments(
        addOnPurchaseIds: ["gid://gitlab/GitlabSubscriptions::AddOnPurchase/5"]
      ) {
        nodes {
          addOnPurchase {
            name
          }
        }
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}
  • Pick any user and assign them:

mutation {
  userAddOnAssignmentCreate(
    input: {
      userId: "gid://gitlab/User/_USER_ID_",
      addOnPurchaseId: "gid://gitlab/GitlabSubscriptions::AddOnPurchase/_AddOnPurchase_ID_", # add_on_purchase_id variable above
    }) {
    errors
  }
}
{
  selfManagedAddOnEligibleUsers(
    addOnType: CODE_SUGGESTIONS
    first: 20
  ) {
    nodes {
      id
      username
      name
      publicEmail
      avatarUrl
      webUrl
      lastActivityOn
      lastLoginAt
      addOnAssignments(
        addOnPurchaseIds: ["gid://gitlab/GitlabSubscriptions::AddOnPurchase/5"]
      ) {
        nodes {
          addOnPurchase {
            name
          }
        }
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

🔴 You should get the same previous error In https://gitlab.com/gitlab-org/gitlab/-/issues/434920

🍏 To verify the fix:

  • git checkout 434920-mhamda-fix-UserAddOnAssignmentsResolver
  • DO THE SAME STEPS WE HAD IN THE RERPRODUCE PART 🔝
  • Verify that the bug does not exist anymore and that the users are listed

MR acceptance checklist

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

Related to #434920

Edited by Alper Akgun

Merge request reports