Refactor UserAuthorizable
What does this MR do and why?
This MR refactors the UserAuthorizable module to transition from using CloudConnector::AvailableServices to the new UnitPrimitive API. This change is part of a larger effort to consolidate and modernize the AI feature authorization system.
Key Changes:
-
Parameter Renaming: Updated method signatures from
service_nametounit_primitive_nameacross the codebase -
Unit Primitive Integration: Added support for fetching unit primitives from
Gitlab::CloudConnector::DataModel::UnitPrimitivecatalog -
Feature Flag Protection: Changes are behind
use_unit_primitives_in_user_authorizablefeature flag for safe rollout -
Backward Compatibility: Maintains support for existing
AvailableServiceswhen feature flag is disabled - Self-hosted Models Support: Added special handling for self-hosted models unit primitive
- Add-on Purchase Logic: Updated to handle both old service-based and new unit primitive-based add-on structures
References
- Feature Issue: #562379 (closed)
- Rollout Issue: #562380 (closed)
Screenshots or screen recordings
N/A - Backend refactoring with no UI changes
How to set up and validate locally
-
Enable the feature flag in Rails console:
Feature.enable(:use_unit_primitives_in_user_authorizable) -
Test AI feature authorization:
user = User.find_by(username: 'your_username') user.allowed_to_use?(:duo_chat, unit_primitive_name: :duo_chat) -
Verify both code paths work:
# Test with feature flag enabled (new unit primitive path) Feature.enable(:use_unit_primitives_in_user_authorizable) user.allowed_to_use?(:duo_chat) # Test with feature flag disabled (legacy service path) Feature.disable(:use_unit_primitives_in_user_authorizable) user.allowed_to_use?(:duo_chat)
Note: We need to test:
-
SelfHostedModelsflow, as this change is affecting it as well. The steps are the same, but SHM needs to be configured. -
generate_descriptionfeature, as we moved to UP calledgenerate_issue_description
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
-
Feature flag added for safe rollout -
Backward compatibility maintained -
Comprehensive test coverage updated -
No breaking changes to existing API -
Performance impact minimal (same authorization logic, different data source)
Edited by Nikola Milojevic