Skip to content

Draft: Add membershipType argument

Bishwa Hang Rai requested to merge 415584-add-on-assignment-membership-type into master

What does this MR do and why?

This MR adds membershipType argument to the userAddOnAssignmentCreate.

Following up on the discussion, this addition will help us reduce the check for valid billable membership of user to be assigned from at most 4 to 1.

There are 4 types of billable membership type that we support:

  1. group_member
  2. project_member
  3. group_invite
  4. project_invite

frontend will send the correct membership type of the user to be assigned based on the response fetched from billable_members endpoint.

Screenshots or screen recordings

Success

Click to expand Screenshot_2023-07-25_at_22.10.37

Failure

Click to expand Screenshot_2023-07-25_at_22.11.22

How to set up and validate locally

  1. Check out the branch
  2. Create a new root group namespace: "root-group"
  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"

# enable the feature flag
Feature.enable(:hamilton_seat_management)
  1. Create a subgroup for the namespace: "sub-group"
  2. Go to Left Panel Settings -> Manage -> Members -> Invite Members
  3. Add a user with developer role (or any role higher than guest)
  4. Go to graphql explorer (logged in as owner/admin): http://gdk.test:3000/-/graphql-explorer, and use following mutation with newly added user's id.

mutation {
  userAddOnAssignmentCreate(
    input: {
      userId: "gid://gitlab/User/85",
      addOnPurchaseId: "gid://gitlab/GitlabSubscriptions::AddOnPurchase/9",
      membershipType: "project_member"
    }) {
    errors
  }
}
  1. Check that response should be failure: "errors": ["INVALID_USER_MEMBERSHIP"]
  2. Change the membership_type of mutation input to correct one: "group_member"



mutation {
  userAddOnAssignmentCreate(
    input: {
      userId: "gid://gitlab/User/85",
      addOnPurchaseId: "gid://gitlab/GitlabSubscriptions::AddOnPurchase/9",
      membershipType: "group_member"
    }) {
    errors
  }
}
  1. The response should be success: errors: []

We can continue similar test for other scenarios too:

  1. 
Create a new project named "project-1" for the namespace, and add a new member with role greater than guest
  2. Run the GraphQL mutation for the new added user with membershipType: "group_member" first, and then membershipType: "project_member"
  3. The response should be failure first, and then success, respectively.
  4. Invite an existing group, say "invited-group-1" to the "sub-group" with role greater than guest
  5. Get the user_id of one of the member of "invited-group-1", and run the mutation with membershipType: "group_invite"
  6. It should return success
  7. Invite an existing group, say "invited-group-2" to the "project-1" with role greater than guest
  8. Get the user_id of member of "invited-group-2", and run the mutation with membershipType: "project_invite"
  9. It should return 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