Skip to content

Add mutation userAddOnAssignmentRemove

Bishwa Hang Rai requested to merge 415585-unassign-user-add-on-mutation into master

What does this MR do and why?

Add mutation userAddOnAssignmentRemove

This MR adds new mutation to remove a user's add_on assignment corresponding to add_on_purchase.

It is dependent on: !126964 (merged) to be merged first.

Screenshots or screen recordings

Success

Screenshot_2023-07-24_at_23.25.57

Error

Screenshot_2023-07-24_at_23.25.45

How to set up and validate locally

  1. Check out the branch
  2. Create a new root group namespace
  3. Setup some seed records
namespace = Namespace.last
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(
  add_on: add_on, namespace: namespace, expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001'
)
add_on_purchase.to_global_id.to_s # "gid://gitlab/GitlabSubscriptions::AddOnPurchase/9"

# create some assignments
add_on_purchase.assigned_users.create!(user: (User.find 85))

# enable the feature flag
Feature.enable(:hamilton_seat_management)
  1. Go to graphql explorer (logged in as owner/admin): http://gdk.test:3000/-/graphql-explorer, and use following mutation:

mutation {
  userAddOnAssignmentRemove(
    input: {
      userId: "gid://gitlab/User/85",
      addOnPurchaseId: "gid://gitlab/GitlabSubscriptions::AddOnPurchase/9",
    }) {
    errors
  }
}
  1. Check that response has no errors errors: []
  2. Sending the same request again for assigned user will return empty response.
  3. Setup the seed record again if needed
  4. Login with a user who has only a developer role in the group.
  5. When trying to remove user assignment, other than self, it will return error.
  6. When removing self (logged in user with developer role) from assignment, it should return success.
  7. Update the add_on_purchase to expire: add_on_purchase.update!(expires_on: 1.day.ago).
  8. Trying to remove any assignment will return error.

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 #415585

Edited by Bishwa Hang Rai

Merge request reports

Loading