Skip to content
Snippets Groups Projects

Draft: Add membershipType argument

Closed 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

Merged results pipeline #945919329 passed

Merged results pipeline passed for 4a8b9dd6

Test coverage 82.39% (15.79%) from 2 jobs
Approval is optional

Closed by Bishwa Hang RaiBishwa Hang Rai 1 year ago (Jul 31, 2023 2:34pm UTC)

Merge details

  • The changes were not merged into .

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
12 12 argument :user_id, ::Types::GlobalIDType[::User],
13 13 required: true, description: 'Global ID of user to be assigned.'
14 14
15 argument :membership_type, GraphQL::Types::String,
  • Bishwa Hang Rai requested review from @ghinfey

    requested review from @ghinfey

  • Bishwa Hang Rai marked this merge request as ready

    marked this merge request as ready

  • Contributor

    Allure report

    allure-report-publisher generated test report!

    e2e-test-on-gdk: :exclamation: test report for 22c0eea1

    expand test summary
    +------------------------------------------------------------------+
    |                          suites summary                          |
    +-------------+--------+--------+---------+-------+-------+--------+
    |             | passed | failed | skipped | flaky | total | result |
    +-------------+--------+--------+---------+-------+-------+--------+
    | Plan        | 47     | 0      | 0       | 40    | 47    | ❗     |
    | Create      | 19     | 0      | 0       | 18    | 19    | ❗     |
    | Data Stores | 20     | 0      | 0       | 15    | 20    | ❗     |
    | Govern      | 19     | 0      | 0       | 15    | 19    | ❗     |
    | Verify      | 8      | 0      | 0       | 8     | 8     | ❗     |
    | Manage      | 12     | 0      | 1       | 12    | 13    | ❗     |
    +-------------+--------+--------+---------+-------+-------+--------+
    | Total       | 125    | 0      | 1       | 108   | 126   | ❗     |
    +-------------+--------+--------+---------+-------+-------+--------+
  • Gavin Hinfey approved this merge request

    approved this merge request

  • :wave: @ghinfey, thanks for approving this merge request.

    This is the first time the merge request is approved. To ensure full test coverage, a new pipeline will be started shortly.

    For more info, please refer to the following links:

  • Gavin Hinfey requested review from @eurie and removed review request for @ghinfey

    requested review from @eurie and removed review request for @ghinfey

  • A deleted user added documentation label

    added documentation label

  • Bishwa Hang Rai marked this merge request as draft

    marked this merge request as draft

  • Bishwa Hang Rai removed review request for @eurie

    removed review request for @eurie

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading