Use more info for license add-on provisioning
What does this MR do and why?
Part of https://gitlab.com/gitlab-org/gitlab/-/issues/465546+
Prior to this change, only the quantity was used for the add-on provisioning. However, with the recently updated add-on structure within the license, all information should be used from the add-on structure for the provisioning.
This change starts using all provided information of an add-on within the license to provision it. This way, the created or updated add-on purchase record will be using more detailed information instead of using the general information from the license.
With these change, future dated add-ons can be supported in future changes.
Screenshots
Expand for example provision run
This subscription has three versions:
- Main product (Ultimate) with 100 seats and Duo Pro with 10 seats; effective contract date: 2024-08-22
- Add another Duo Pro product with 10 seats; effective contract date: 2024-08-27
- Update Duo Pro product from version 1 to have 15 seats; effective contract date: 2024-09-14 (future dated)
[12] pry(main)> License.create(data: "eyJkYXRhIjoiYWRoWjhmcER3TERGNGd5cW44eTd1bEdDQ25KVEV2dkFZd3cv
[...]
Zz09XG4iLCJpdiI6ImlXQnlrbzllcVJqVEdVM3kxR3lWUXc9PVxuIn0=
TRANSACTION (0.4ms) BEGIN
License Create (1.4ms) INSERT INTO "licenses" ("data", "created_at", "updated_at") VALUES ('eyJkYXRhIjoiYWRoWjhmcER3TERGNGd5cW44eTd1bEdDQ25KVEV2dkFZd3cv
[...]
Zz09XG4iLCJpdiI6ImlXQnlrbzllcVJqVEdVM3kxR3lWUXc9PVxuIn0=
', '2024-08-29 15:21:31.705072', '2024-08-29 15:21:31.705072') RETURNING "id"
TRANSACTION (0.2ms) COMMIT
=> #<License:0x000000015aee5790
id: 431,
data:
"eyJkYXRhIjoiYWRoWjhmcER3TERGNGd5cW44eTd1bEdDQ25KVEV2dkFZd3cv[...]Zz09XG4iLCJpdiI6ImlXQnlrbzllcVJqVEdVM3kxR3lWUXc9PVxuIn0=\n",
created_at: Thu, 29 Aug 2024 15:21:31.705072000 UTC +00:00,
updated_at: Thu, 29 Aug 2024 15:21:31.705072000 UTC +00:00,
cloud: false,
last_synced_at: nil>
[13] pry(main)> License.current.restrictions
License Load (1.0ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 100
=> {:id=>nil,
:previous_user_count=>nil,
:trueup_period_seat_count=>nil,
:trueup_quantity=>nil,
:trueup_from=>"2023-08-22",
:trueup_to=>"2024-08-22",
:active_user_count=>100,
:subscription_id=>"8a8aa366917eef3b01919eb229c6060c",
:subscription_name=>"A-S00199249",
:plan=>"ultimate",
:trial=>false,
:reconciliation_completed=>false,
:code_suggestions_seat_count=>30,
:add_on_products=>
{"duo_pro"=>
[{"quantity"=>10, "started_on"=>"2024-08-22", "expires_on"=>"2024-09-14", "purchase_xid"=>"C-00312988", "trial"=>false},
{"quantity"=>15, "started_on"=>"2024-09-14", "expires_on"=>"2025-08-22", "purchase_xid"=>"C-00312988", "trial"=>false},
{"quantity"=>15, "started_on"=>"2024-08-27", "expires_on"=>"2025-08-22", "purchase_xid"=>"C-00312990", "trial"=>false}]}}
[14] pry(main)> GitlabSubscriptions::AddOnPurchases::SelfManaged::ProvisionServices::Duo.new.execute
GitlabSubscriptions::AddOn Load (0.3ms) SELECT "subscription_add_ons".* FROM "subscription_add_ons" WHERE "subscription_add_ons"."name" = 3 LIMIT 1
GitlabSubscriptions::AddOn Load (1.2ms) SELECT "subscription_add_ons".* FROM "subscription_add_ons" WHERE "subscription_add_ons"."name" = 1 LIMIT 1
GitlabSubscriptions::AddOnPurchase Load (1.3ms) SELECT "subscription_add_on_purchases".* FROM "subscription_add_on_purchases" WHERE "subscription_add_on_purchases"."namespace_id" IS NULL AND "subscription_add_on_purchases"."subscription_add_on_id" IN (3, 1) LIMIT 1
GitlabSubscriptions::AddOn Load (3.6ms) SELECT "subscription_add_ons".* FROM "subscription_add_ons" WHERE "subscription_add_ons"."name" = 1 LIMIT 1
TRANSACTION (0.1ms) BEGIN
ApplicationSetting Load (7.6ms) SELECT "application_settings"."id", [...]
GitlabSubscriptions::AddOnPurchase Exists? (0.6ms) SELECT 1 AS one FROM "subscription_add_on_purchases" WHERE "subscription_add_on_purchases"."subscription_add_on_id" = 1 AND "subscription_add_on_purchases"."id" != 5 AND "subscription_add_on_purchases"."namespace_id" IS NULL LIMIT 1
TRANSACTION (0.3ms) COMMIT
=> #<ServiceResponse:0x000000016d3151a0
@http_status=:ok,
@message=nil,
@payload=
{:add_on_purchase=>
#<GitlabSubscriptions::AddOnPurchase:0x000000015aeab900
id: 5,
created_at: Mon, 15 Apr 2024 09:54:39.313610000 UTC +00:00,
updated_at: Thu, 29 Aug 2024 15:20:17.506813000 UTC +00:00,
subscription_add_on_id: 1,
namespace_id: nil,
quantity: 25,
expires_on: Fri, 22 Aug 2025,
purchase_xid: "C-00312988",
last_assigned_users_refreshed_at: Wed, 28 Aug 2024 13:08:45.598046000 UTC +00:00,
trial: false,
started_at: Thu, 22 Aug 2024,
organization_id: 1>},
@reason=nil,
@status=:success>
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
See verification above or reach out for the license key to test locally.