FIX: Image caption feature should respect composer AI helper groups (#522)

This commit is contained in:
Keegan George 2024-03-11 15:35:20 -07:00 committed by GitHub
parent 79638c2f50
commit 740731ab53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 1 deletions

View File

@ -10,10 +10,15 @@ export default apiInitializer("1.25.0", (api) => {
class: "generate-caption", class: "generate-caption",
}; };
const settings = api.container.lookup("service:site-settings"); const settings = api.container.lookup("service:site-settings");
const currentUser = api.getCurrentUser();
if (!settings.ai_helper_enabled_features.includes("image_caption")) { if (
!settings.ai_helper_enabled_features.includes("image_caption") ||
!currentUser.can_use_assistant
) {
return; return;
} }
api.addComposerImageWrapperButton( api.addComposerImageWrapperButton(
buttonAttrs.label, buttonAttrs.label,
buttonAttrs.class, buttonAttrs.class,

View File

@ -2,6 +2,8 @@
RSpec.describe "AI image caption", type: :system, js: true do RSpec.describe "AI image caption", type: :system, js: true do
fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) } fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:non_member_group) { Fabricate(:group) }
let(:composer) { PageObjects::Components::Composer.new } let(:composer) { PageObjects::Components::Composer.new }
let(:popup) { PageObjects::Components::AiCaptionPopup.new } let(:popup) { PageObjects::Components::AiCaptionPopup.new }
let(:file_path) { file_from_fixtures("logo.jpg", "images").path } let(:file_path) { file_from_fixtures("logo.jpg", "images").path }
@ -25,6 +27,26 @@ RSpec.describe "AI image caption", type: :system, js: true do
) )
end end
shared_examples "shows no image caption button" do
it "should not show an image caption button" do
visit("/latest")
page.find("#create-topic").click
attach_file([file_path]) { composer.click_toolbar_button("upload") }
wait_for { composer.has_no_in_progress_uploads? }
expect(popup).to have_no_generate_caption_button
end
end
context "when not a member of ai helper group" do
before { SiteSetting.ai_helper_allowed_groups = non_member_group.id.to_s }
include_examples "shows no image caption button"
end
context "when image caption feature is disabled" do
before { SiteSetting.ai_helper_enabled_features = "" }
include_examples "shows no image caption button"
end
context "when triggering caption with AI on desktop" do context "when triggering caption with AI on desktop" do
it "should show an image caption in an input field" do it "should show an image caption in an input field" do
visit("/latest") visit("/latest")

View File

@ -34,6 +34,10 @@ module PageObjects
def has_no_disabled_generate_button? def has_no_disabled_generate_button?
page.has_no_css?("#{GENERATE_CAPTION_SELECTOR}.disabled", visible: false) page.has_no_css?("#{GENERATE_CAPTION_SELECTOR}.disabled", visible: false)
end end
def has_no_generate_caption_button?
page.has_no_css?(GENERATE_CAPTION_SELECTOR, visible: false)
end
end end
end end
end end