Accept and expose duo_workflow_file_attachments_enabled in the groups API
What does this MR do and why?
Adds API endpoints for groups to display and update duo_workflow_file_attachments_enabled added in !268282 (merged).
This setting will allow admins to gate the file upload feature to Duo agentic chat.
Please view question about not returning the value for sub groups !268538 (comment 4176761112) and !268538 (comment 4177802453)
References
Admin setting issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/633198
File upload epic: &20481
Depends on: !268282 (merged)
Frontend created in: !268362 (merged)
Full PoC: !268274
How to set up and validate locally
API only.
- Check that calls to
/groups/#{group.id}"only returnduo_workflow_file_attachments_enabledinai_settingsfor top level SaaS groups. - Check that
put "/groups/#{group.id}"only updatesduo_workflow_file_attachments_enabledfor top level SaaS groups.
I have created a script to:
- Create a top level group, and a sub group (deletes them by name to ensure unique)
- View if the field is returned
- Attempt to update the field
- Print and check the values returned/updated
Script
# frozen_string_literal: true
# Exercises https://gitlab.com/gitlab-org/gitlab/-/merge_requests/268538.
# Reading and updating duo_workflow_file_attachments_enabled goes through the REST API, as a user would.
# Rails handles setup and teardown: the token, the groups and their plan.
# Run: cd /home/kaveh/gdk/gitlab && bundle exec rails runner /home/kaveh/gdk/kaveh/test_group_file_attachments.rb
require 'net/http'
SETTING = 'duo_workflow_file_attachments_enabled'
TOP_PATH = 'kaveh-file-attachments-top'
SUB_PATH = 'kaveh-file-attachments-sub'
user = User.find_by_username!('root')
organization = Organizations::Organization.default_organization
saas = Gitlab::Saas.feature_available?(:gitlab_com_subscriptions)
token = PersonalAccessTokens::CreateService.new(
current_user: user,
target_user: user,
organization_id: organization.id,
params: { name: 'kaveh-file-attachments-test', scopes: [:api], expires_at: 1.day.from_now }
).execute.payload[:personal_access_token]
raise 'token not created' unless token
TOKEN = token.token
API_URL = "#{Gitlab.config.gitlab.url}/api/v4"
def log(message)
return
puts("kaveh-log #{message}")
end
def request(method, path, body = nil)
uri = URI("#{API_URL}#{path}")
request = Net::HTTP.const_get(method.to_s.capitalize).new(uri)
request['PRIVATE-TOKEN'] = TOKEN
request['Content-Type'] = 'application/json'
request.body = body.to_json if body
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
parsed = response.body.present? ? Gitlab::Json.parse(response.body) : nil
log("#{method.upcase} #{path} -> #{response.code}")
[response.code.to_i, parsed]
end
# Also catches groups earlier API runs marked for deletion and renamed to <path>-deletion_scheduled-<id>
def delete_test_groups(user)
Group.where(parent_id: nil).where('path LIKE ?', "#{TOP_PATH}%").find_each do |group|
Groups::DestroyService.new(group, user).execute
end
end
# A) Remove leftovers, then create the top-level group
delete_test_groups(user)
top = Groups::CreateService.new(
user, name: TOP_PATH, path: TOP_PATH, organization_id: organization.id, visibility_level: Gitlab::VisibilityLevel::PRIVATE
).execute[:group]
raise "top-level group not created: #{top.errors.full_messages}" unless top.persisted?
# On SaaS, licensed features come from the group's plan; a new group is Free, so the API hides ai_settings.
# Stand in for a purchase by putting the group on Ultimate.
if saas
subscription = GitlabSubscription.find_or_initialize_by(namespace_id: top.id)
subscription.update!(hosted_plan: Plan.find_or_create_by!(name: Plan::ULTIMATE), seats: 10)
end
# B) Create the subgroup
sub = Groups::CreateService.new(
user, name: SUB_PATH, path: SUB_PATH, parent_id: top.id, organization_id: organization.id
).execute[:group]
raise "subgroup not created: #{sub.errors.full_messages}" unless sub.persisted?
groups = { top_level: top, subgroup: sub }
# C) ai_settings returned by GET /groups/:id, before the update
before = groups.transform_values { |group| request(:get, "/groups/#{group.id}").last['ai_settings'] }
before.each { |name, settings| log("#{name} ai_settings before: #{settings}") }
# D) Update the setting on each group
updates = groups.to_h do |name, group|
status, body = request(:put, "/groups/#{group.id}", { ai_settings_attributes: { SETTING => true } })
log("#{name} update -> #{status} #{status == 200 ? '' : body}")
[name, { status: status, body: body }]
end
after = groups.transform_values { |group| request(:get, "/groups/#{group.id}").last['ai_settings'] }
after.each { |name, settings| log("#{name} ai_settings after: #{settings}") }
persisted = groups.transform_values { |group| group.reset.ai_settings.public_send(SETTING) }
# E) Clean up; destroying the top-level group also removes the subgroup
delete_test_groups(user)
token.revoke!
puts
puts '=== Summary ==='
puts "SaaS (gitlab_com_subscriptions): #{saas}"
groups.each_key do |name|
update = updates[name]
puts
puts "#{name}:"
puts " update HTTP status: #{update[:status]}"
puts " update error: #{update[:body]['message']}" unless update[:status] == 200
puts " value in DB (Rails check): #{persisted[name]}"
puts " ai_settings returned: #{!after[name].nil?}"
puts " #{SETTING} returned: #{after[name]&.key?(SETTING) ? after[name][SETTING] : 'not included'}"
puts " exposed before includes it: #{before[name]&.key?(SETTING) || false}"
puts " exposed after includes it: #{after[name]&.key?(SETTING) || false}"
endYou must also update the gdk.yml GITLAB_SIMULATE_SAAS: '1' and gdk reconfigure; gdk restart between runs
Script results:
kaveh@kvejad--20251026-73SB4:~/gdk/gitlab$ GITLAB_SIMULATE_SAAS=1 bundle exec rails runner /home/kaveh/gdk/kaveh/test_group_file_attachments.rb
=== Summary ===
SaaS (gitlab_com_subscriptions): true
top_level:
update HTTP status: 200
value in DB (Rails check): true
ai_settings returned: true
duo_workflow_file_attachments_enabled returned: true
exposed before includes it: true
exposed after includes it: true
subgroup:
update HTTP status: 400
update error: {"ai_settings.duo_workflow_file_attachments_enabled" => ["can only be set for top-level groups"]}
value in DB (Rails check): false
ai_settings returned: true
duo_workflow_file_attachments_enabled returned: not included
exposed before includes it: false
exposed after includes it: false
kaveh@kvejad--20251026-73SB4:~/gdk/gitlab$ gdk reconfigure; gdk restart
kaveh@kvejad--20251026-73SB4:~/gdk/gitlab$ bundle exec rails runner /home/kaveh/gdk/kaveh/test_group_file_attachments.rb
=== Summary ===
SaaS (gitlab_com_subscriptions): false
top_level:
update HTTP status: 200
value in DB (Rails check): false
ai_settings returned: true
duo_workflow_file_attachments_enabled returned: not included
exposed before includes it: false
exposed after includes it: false
subgroup:
update HTTP status: 200
value in DB (Rails check): false
ai_settings returned: true
duo_workflow_file_attachments_enabled returned: not included
exposed before includes it: false
exposed after includes it: falseOn Self managed the flag is dropped, so the update returns 200, but nothing is updated.
On SaaS, if a user tries to update a sub group with the new value, an error is returned
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 #633198