Backport of 'update the active_add_on_purchase check to include self-managed check'
What does this MR do and why?
backport !200258 (merged) to 18-1
for self-managed instance the namespace id in AddOnPurchase table is nil which caused the check fail:
::GitlabSubscriptions::AddOnPurchase
.joins(:add_on)
.where(
namespace_id: self_and_ancestor_ids,
subscription_add_ons: { name: GitlabSubscriptions::AddOn.names[add_on] }
)
.active
.any?
Thus the self-managed customers can't use duo code review.
in this MR I added the check for self-managed instance
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch. -
The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes). -
The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post. -
Required labels have been applied to this merge request -
severity label and bug subtype labels (if applicable) -
If this MR fixes a bug that affects customers, the customer label has been applied.
-
-
Set the milestone of the merge request to match the target backport branch version. -
This MR has been approved by a maintainer (only one approval is required). -
Ensure the e2e:test-on-omnibus-eejob has either succeeded or been approved by a Software Engineer in Test.
Note to the merge request author and maintainer
If you have questions about the patch release process, please:
- Refer to the patch release runbook for engineers and maintainers for guidance.
- Ask questions on the
#releasesSlack channel (internal only). - Once the backport has been merged, the commit changes will be automatically deployed to a release environment that can be used for manual validation. See after merging runbook for details.
Screenshots or screen recordings
| Before | After |
|---|---|
With a valid AddOnPurchase record where the namespace_id is nil,
#<GitlabSubscriptions::AddOnPurchase:0x00000001652fb690
id: 1,
created_at: Tue, 22 Apr 2025 19:00:00.917180000 UTC +00:00,
updated_at: Fri, 22 Aug 2025 19:00:19.410037000 UTC +00:00,
subscription_add_on_id: 3,
namespace_id: nil,
quantity: 100,
expires_on: Sat, 22 Aug 2026,
purchase_xid: "C-00769226",
last_assigned_users_refreshed_at: Fri, 22 Aug 2025 00:00:13.701873000 UTC +00:00,
trial: false,
started_at: Tue, 10 Sep 2024,
organization_id: 1>]
in a self-managed instance:
[19] pry(main)> ::Gitlab::Saas.feature_available?(:gitlab_com_subscriptions)
=> false
Edited by Michael Kozono
