Add Ai::FileAttachments.allowed? to workflow_type and duo_chat_data

What does this MR do and why?

Updates the workflow_type file_attachments_allowed and duo_chat_data methods to return the new ::Ai::FileAttachments.allowed?

workflow_type should work the same as it does today for .com (only respect feature flag), on SM it should now return the new duo_workflow_file_attachments_enabled instance level setting added in !268881 (merged).

Currently, nothing consumes the value added to duo_chat_data, but the frontend will use this to apply the same logic to the icon display !269284 (merged).

The .com route will be fixed with !269571, but was removed from this MR to allow it to be merged before the API and UI changes are applied to the group settings, this was done as this MR is blocking several others.

References

Admin setting issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/633198

File upload epic: &20481

Database

A single new query was added to retrieve the instance settings, and the same request ::Ai::Setting.for_current_or_default_organization appears several times in the rest of the code base already

SELECT
    "ai_settings"."id",
    "ai_settings"."created_at",
    "ai_settings"."updated_at",
    "ai_settings"."amazon_q_oauth_application_id",
    "ai_settings"."amazon_q_service_account_user_id",
    "ai_settings"."amazon_q_ready",
    "ai_settings"."amazon_q_role_arn",
    "ai_settings"."duo_workflow_service_account_user_id",
    "ai_settings"."duo_workflow_oauth_application_id",
    "ai_settings"."duo_core_features_enabled",
    "ai_settings"."foundational_agents_default_enabled",
    "ai_settings"."minimum_access_level_execute",
    "ai_settings"."minimum_access_level_manage",
    "ai_settings"."minimum_access_level_enable_on_projects",
    "ai_settings"."minimum_access_level_execute_async",
    "ai_settings"."feature_settings",
    "ai_settings"."include_recommended_allowed",
    "ai_settings"."allow_all_unix_sockets",
    "ai_settings"."enforce_on_local_clients",
    "ai_settings"."allow_project_extension",
    "ai_settings"."allowed_domains",
    "ai_settings"."denied_domains",
    "ai_settings"."organization_id",
    "ai_settings"."require_sandbox"
FROM
    "ai_settings"
WHERE
    "ai_settings"."organization_id" = 1
LIMIT 1

https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/85104/commands/192037

How to set up and validate locally

Workflow query

query {
  duoWorkflowWorkflows(last: 1) {
    nodes {
      id
      projectId
      namespaceId
      fileAttachmentsAllowed
    }
  }
}

Browser console test:

const html = await (await fetch(location.href)).text();
const panel = new DOMParser().parseFromString(html, 'text/html').querySelector('#duo-chat-panel');
panel.dataset.fileAttachmentsAllowed
  1. In SM
    1. GITLAB_SIMULATE_SAAS: '0' in gdk.yml
    2. gdk reconfigure; gdk restart
  2. In gdk rails c enable the feature flag
    1. Feature.enable(:dap_web_chat_file_attachments)
  3. Start an agentic chat by sending any message
  4. Open graphql-explorer http://gdk.test:8080/-/graphql-explorer and the Workflow query (should return false)
  5. In the browser console run the Browser console test, it should return false
  6. In gdk rails c run
    1. Ai::Setting.for_organization(Organizations::Organization.default_organization).update!(duo_workflow_file_attachments_enabled: true)
  7. Run the GraphQL again, and it should return true
  8. Run the browser console test again, it should return true
  9. In SaaS
    1. GITLAB_SIMULATE_SAAS: '1' in gdk.yml
    2. gdk reconfigure; gdk restart
  10. run the query and the browser test again, it should return true
  11. In gdk rails c disable the flag and wait a minute
    1. Feature.disable(:dap_web_chat_file_attachments)
  12. run the query and the browser test again, it should return false

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.

Edited by Kaveh Nejad

Merge request reports

Loading
Loading