Move Duo Code Review availability out of models

What does this MR do and why?

Project, Namespace and ApplicationSetting each carry their own copy of the "is Duo Code Review available here?" check. These are omniscient classes, and Duo Code Review rules do not belong in them.

This MR moves that check into Gitlab::Duo::CodeReview::Availability, with one class per container type (project, namespace, instance). Callers use Gitlab::Duo::CodeReview.available?(container). The model methods that used the old check now call the new entry point, so behavior does not change.

This is the first MR of the extraction. It only moves duo_code_review_available?, and sets the pattern for the other Duo Code Review availability methods (auto_duo_code_review_settings_available?, duo_code_review_decisions_available?, duo_code_review_dap_available?, duo_code_review_approval_counts?). Each of those will move in its own MR.

References

Screenshots or screen recordings

Not applicable. No UI change.

How to set up and validate locally

The settings below must show and hide exactly as they do on master.

  1. Make sure your GDK has an active Duo Enterprise add-on, and Duo features are on for the gitlab-duo group.
  2. Go to gitlab-duo/test > Settings > Merge requests. The Duo Code Review settings (automatic reviews and, with the duo_code_review_decisions flag on, review decisions) show.
  3. Go to the gitlab-duo group > Settings > General > Merge requests. The same settings show.
  4. Go to Admin > Settings > General. The Duo Code Review settings show.
  5. Check the REST API also exposes the setting:
    curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/projects/gitlab-duo%2Ftest" | jq '.auto_duo_code_review_enabled'
    It returns true or false, not null.
  6. Turn off GitLab Duo for the gitlab-duo group (Settings > GitLab Duo). Reload the project and group pages from steps 2 and 3. The Duo Code Review settings no longer show, and the API field from step 5 is gone.

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.

Merge request reports

Loading
Loading