Skip to content

Add mutation userAddOnAssignmentCreate

Bishwa Hang Rai requested to merge 415584-assign-user-add-on-mutation into master

What does this MR do and why?

Add mutation userAddOnAssignmentCreate

This MR adds a new graphql mutation userAddOnAssignmentCreate. This mutation is used to assign user to add_on_purchase provided all the authorization and validation satisfy.

The feature is behind the feature flag: hamilton_seat_management.

Follow up MR

This MR has 3 skipped test with xcontext. This validation will be added in follow up MR (!127051 (closed)). I am still looking for efficient way to check if a user is a member of any of the subgroups/projects of the namespace belonging to add_on_purchase, and has a access_level higher than guest. Any help appreciated.

It may be similar to the response of billable_members endpoint, which uses Namespaces::BillableUsersFinder. However, instead of getting all the billable_members, we need to just find if a user is part of the billed_members.

There is existing member? method. But, it does not support children lookups on sub_groups and project.

The mutation is labelled alpha, and is behind the feature flag hamilton_seat_management, so I guess it is okay to split in in Iteration with smaller MR review.

Follow up commit: !126964 (8de1ef4d)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Screenshot_2023-07-19_at_12.33.35

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"
namespace.users.first.to_global_id.to_s # "gid://gitlab/User/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 query and variables

mutation {
  userAddOnAssignmentCreate(
    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 error.
  3. Update the quantity so no seats are available: add_on_purchase.update!(quantity: 1)
  4. Adding new users should respond: {errors: ['NO_SEATS_AVAILABLE']}
  5. Create a guest user: namespace.add_guest(guest_user)
  6. Sending user_id with guest_user role in mutation results: {errors: ['INVALID_USER_MEMBERSHIP']}

To test remaining test scenarios:

  1. Setup the seed record again if needed
  2. Login with a user who has only a developer role in the group.
  3. Try to assign to other user, other than self. It will return errors
  4. Assigning to self will be success.

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

Edited by Bishwa Hang Rai

Merge request reports