FIX: `auto_image_caption` not always present for current user. (#746)
This commit is contained in:
parent
1d6a6c9f8f
commit
0be292f247
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue