Add mutation userAddOnAssignmentCreate
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.
How to set up and validate locally
- Check out the branch
- Create a new root group namespace
- 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)
- 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
}
}
- Check that response has no errors
errors: []
- Sending the same request again for assigned user will return empty error.
- Update the quantity so no seats are available:
add_on_purchase.update!(quantity: 1)
- Adding new users should respond:
{errors: ['NO_SEATS_AVAILABLE']}
- Create a guest user:
namespace.add_guest(guest_user)
- Sending
user_id
withguest_user
role in mutation results:{errors: ['INVALID_USER_MEMBERSHIP']}
To test remaining test scenarios:
- Setup the seed record again if needed
- Login with a user who has only a developer role in the group.
- Try to assign to other user, other than self. It will return errors
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #415584