Refactor UserAuthorizable module to use new UnitPrimitive API
Summary
Refactor 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.
Problem
The current UserAuthorizable
module relies on CloudConnector::AvailableServices
for AI feature authorization. As part of the broader AI infrastructure modernization, we need to migrate to the new UnitPrimitive
API to:
- Consolidate authorization logic under a unified system
- Improve maintainability and consistency
- Support future AI feature expansions
- Align with the new data model architecture
Proposed Solution
Key Changes Required:
-
Parameter Renaming: Update method signatures from
service_name
tounit_primitive_name
across the codebase -
Unit Primitive Integration: Add support for fetching unit primitives from
Gitlab::CloudConnector::DataModel::UnitPrimitive
catalog -
Feature Flag Protection: Implement changes behind
use_unit_primitives_in_user_authorizable
feature flag for safe rollout -
Backward Compatibility: Maintain support for existing
AvailableServices
when feature flag is disabled - Self-hosted Models Support: Add special handling for self-hosted models unit primitive
- Add-on Purchase Logic: Update to handle both old service-based and new unit primitive-based add-on structures
Implementation Approach:
- Use feature flag
use_unit_primitives_in_user_authorizable
to control the rollout - Maintain dual code paths during transition period
- Ensure no breaking changes to existing API
- Update all related tests to cover both scenarios
Acceptance Criteria
-
Feature flag use_unit_primitives_in_user_authorizable
controls which API is used -
When feature flag is enabled, authorization uses UnitPrimitive
API -
When feature flag is disabled, authorization falls back to AvailableServices
API -
Self-hosted models unit primitive is properly handled (feature is overriden to :self_hosted_models) -
Add-on purchase logic works with both old and new structures -
All existing tests pass -
New tests cover both code paths -
No performance regression -
No breaking changes to public API
Testing Strategy
- Unit Tests: Cover both feature flag enabled/disabled scenarios
- Self-hosted Models: Specific testing for self-hosted models flow
Related Issues
- Rollout Issue: #562380 (closed)
Technical Notes
- Changes affect the core authorization logic for AI features
- Special attention needed for self-hosted models integration
- Backward compatibility is critical during transition period
- Performance impact should be minimal (same logic, different data source)
Edited by Nikola Milojevic