FIX: `auto_image_caption` not always present for current user. (#746)

This commit is contained in:
Keegan George 2024-08-08 13:37:26 -07:00 committed by GitHub
parent 1d6a6c9f8f
commit 0be292f247
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 0 deletions

View File

@ -57,6 +57,16 @@ module DiscourseAi
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
end,
) { object.auto_image_caption }
plugin.add_to_serializer(
:current_user_option,
:auto_image_caption,
include_condition: -> do
SiteSetting.composer_ai_helper_enabled &&
SiteSetting.ai_helper_enabled_features.include?("image_caption") &&
scope.user.in_any_groups?(SiteSetting.ai_auto_image_caption_allowed_groups_map)
end,
) { object.auto_image_caption }
end
end
end

View File

@ -36,4 +36,15 @@ describe DiscourseAi::AiHelper::EntryPoint do
)
end
end
it "will include auto_image_caption field in the user_option if image caption is enabled" do
assign_fake_provider_to(:ai_helper_model)
assign_fake_provider_to(:ai_helper_image_caption_model)
SiteSetting.composer_ai_helper_enabled = true
SiteSetting.ai_helper_enabled_features = "image_caption"
SiteSetting.ai_auto_image_caption_allowed_groups = "10" # tl0
serializer = CurrentUserSerializer.new(english_user, scope: Guardian.new(english_user))
expect(serializer.user_option.auto_image_caption).to eq(false)
end
end

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
RSpec.describe UserOption do
before do
assign_fake_provider_to(:ai_helper_model)
assign_fake_provider_to(:ai_helper_image_caption_model)
SiteSetting.composer_ai_helper_enabled = true
SiteSetting.ai_helper_enabled_features = "image_caption"
SiteSetting.ai_auto_image_caption_allowed_groups = "10" # tl0
end
describe "#auto_image_caption" do
it "is present" do
expect(described_class.new.auto_image_caption).to eq(false)
end
end
end