Refactor UserAddOnAssignments and the GQL API
What does this MR do and why?
This MR is a component of the MVC epic, aimed at enabling UserAddOnAssignments
for Code Suggestions seat management on a Self-Managed instance.
Here, we are allowing the admin to assign all users who are human, excluding bots, blocked, banned, and pending_approval users
.
Related to #432212
In this MR, we: Refactor UserAddOnAssignments and the GQL API for self-managed use
- Refactor UserAddOnAssignments to be a base service
- Introduce new service architecture
- Introduce UserAddOnAssignments for self-managed
- Introduce eligible_for_self_managed_code_suggestions
- Cover changes with specs
Screenshots or screen recordings
How to set up and validate locally
Note: Access is limited to admins
Note: Make sure you are running a self-managed installation: gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=0 gdk rails s
-
Pick or create a group and add guests, developers, owners, bots, and banned, and blocked users.
-
Visit localhost:3000/graphql-explorer and add the specified query below.
-
Setup
AddOnPurchase
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, expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001'
)
add_on_purchase.to_global_id.to_s # "gid://gitlab/GitlabSubscriptions::AddOnPurchase/4"
Feature.enable(:hamilton_seat_management) # enable the feature flag
- Go to GraphQL explorer (logged in as admin): http://gdk.test:3000/-/graphql-explorer, and use the following query:
mutation {
userAddOnAssignmentCreate(
input: {
userId: "gid://gitlab/User/ID",
addOnPurchaseId: "gid://gitlab/GitlabSubscriptions::AddOnPurchase/ID"
}) {
addOnPurchase {
id
name
purchasedQuantity
assignedQuantity
}
errors
}
}
- Check that the response has no errors
errors: []
- Sending the same request again for the assigned user will return the user and an 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']}
- Sending
user_id
with theguest_user
role in mutation results should be successful and raise no errors. - Sending
user_id
withblocked/banned/bot/inactive, etc.. user
role in mutation results:{errors: ['INVALID_USER_MEMBERSHIP']}
To test the denied add test scenarios:
- Setup the seed record again if needed
- Login with a user who is not an admin.
- Try to assign any user. It will return errors.
Verify SaaS previously merged work is not broken:
gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=1 gdk rails s
- Follow the docs for SaaS setup/test !126964 (merged)
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 #432212