Draft: Consolidate Code Suggestions permission checks
What does this MR do and why?
This MR consolidates Code Suggestions permission checks into a single source of truth in the global policy, addressing duplicate permission logic and fixing Amazon Q licensing inconsistency identified in #560766.
Problem
Code Suggestions currently has duplicate permission checks that can lead to inconsistent behavior:
-
Global Policy: Uses
allowed_to_use?(:code_suggestions)with defaultlicensed_feature: :ai_features -
API Controller: Uses
allowed_to_use?(:code_suggestions, licensed_feature: task.licensed_feature)which can be:amazon_qfor Amazon Q
This creates a scenario where the same user and feature are evaluated with different licensing parameters, potentially causing access violations.
Solution
-
Enhanced Global Policy: Made the
code_suggestions_enabled_for_usercondition context-aware to handle Amazon Q licensing - Simplified API Controller: Removed duplicate permission check, relying solely on the policy
-
Consistent Licensing: Policy now determines the appropriate
licensed_feature(:amazon_qor:ai_features) based on context
References
Screenshots or screen recordings
Not applicable - backend permission logic changes
How to set up and validate locally
TODO
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.
Related to #560766