Skip to content

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:

  1. Parameter Renaming: Updated method signatures from service_name to unit_primitive_name across the codebase
  2. Unit Primitive Integration: Added support for fetching unit primitives from Gitlab::CloudConnector::DataModel::UnitPrimitive catalog
  3. Feature Flag Protection: Changes are behind use_unit_primitives_in_user_authorizable feature flag for safe rollout
  4. Backward Compatibility: Maintains support for existing AvailableServices when feature flag is disabled
  5. Self-hosted Models Support: Added special handling for self-hosted models unit primitive
  6. Add-on Purchase Logic: Updated to handle both old service-based and new unit primitive-based add-on structures

References

Screenshots or screen recordings

N/A - Backend refactoring with no UI changes

How to set up and validate locally

  1. Enable the feature flag in Rails console:

      Feature.enable(:use_unit_primitives_in_user_authorizable)
  2. Test AI feature authorization:

      user = User.find_by(username: 'your_username')
      user.allowed_to_use?(:duo_chat, unit_primitive_name: :duo_chat)
  3. 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:

  • SelfHostedModels flow, as this change is affecting it as well. The steps are the same, but SHM needs to be configured.
  • generate_description feature, as we moved to UP called generate_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

Merge request reports

Loading