Skip to content

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:

  1. Parameter Renaming: Update method signatures from service_name to unit_primitive_name across the codebase
  2. Unit Primitive Integration: Add support for fetching unit primitives from Gitlab::CloudConnector::DataModel::UnitPrimitive catalog
  3. Feature Flag Protection: Implement changes behind use_unit_primitives_in_user_authorizable feature flag for safe rollout
  4. Backward Compatibility: Maintain support for existing AvailableServices when feature flag is disabled
  5. Self-hosted Models Support: Add special handling for self-hosted models unit primitive
  6. 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

  1. Unit Tests: Cover both feature flag enabled/disabled scenarios
  2. Self-hosted Models: Specific testing for self-hosted models flow

Related Issues

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