FIX: Image caption feature should respect composer AI helper groups (#522)
This commit is contained in:
parent
79638c2f50
commit
740731ab53
|
@ -10,10 +10,15 @@ export default apiInitializer("1.25.0", (api) => {
|
|||
class: "generate-caption",
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
||||
api.addComposerImageWrapperButton(
|
||||
buttonAttrs.label,
|
||||
buttonAttrs.class,
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
RSpec.describe "AI image caption", type: :system, js: true do
|
||||
fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) }
|
||||
fab!(:non_member_group) { Fabricate(:group) }
|
||||
|
||||
let(:composer) { PageObjects::Components::Composer.new }
|
||||
let(:popup) { PageObjects::Components::AiCaptionPopup.new }
|
||||
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
|
||||
|
||||
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
|
||||
it "should show an image caption in an input field" do
|
||||
visit("/latest")
|
||||
|
|
|
@ -34,6 +34,10 @@ module PageObjects
|
|||
def has_no_disabled_generate_button?
|
||||
page.has_no_css?("#{GENERATE_CAPTION_SELECTOR}.disabled", visible: false)
|
||||
end
|
||||
|
||||
def has_no_generate_caption_button?
|
||||
page.has_no_css?(GENERATE_CAPTION_SELECTOR, visible: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue