FIX: Prevent AI caption setting from showing unless all criteria is met (#753)
This commit is contained in:
parent
72980a3d84
commit
23b88537d9
|
@ -3,19 +3,26 @@ import { LinkTo } from "@ember/routing";
|
||||||
import dIcon from "discourse-common/helpers/d-icon";
|
import dIcon from "discourse-common/helpers/d-icon";
|
||||||
import i18n from "discourse-common/helpers/i18n";
|
import i18n from "discourse-common/helpers/i18n";
|
||||||
|
|
||||||
function showAiPreferences(user) {
|
function showAiPreferences(user, settings) {
|
||||||
// Since we only have one AI related user setting we don't show
|
// Since we only have one AI related user setting we don't show
|
||||||
// AI preferences if these conditions aren't met.
|
// AI preferences if these conditions aren't met.
|
||||||
// If we add more user settings in the future we can move this
|
// If we add more user settings in the future we can move this
|
||||||
// logic to the the specific settings and conditionally show it in the template.
|
// logic to the the specific settings and conditionally show it in the template.
|
||||||
return user?.user_allowed_ai_auto_image_captions;
|
const aiHelperEnabledFeatures =
|
||||||
|
settings.ai_helper_enabled_features.split("|");
|
||||||
|
|
||||||
|
return (
|
||||||
|
user?.user_allowed_ai_auto_image_captions &&
|
||||||
|
aiHelperEnabledFeatures.includes("image_caption") &&
|
||||||
|
settings.ai_helper_enabled
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AutoImageCaptionSetting extends Component {
|
export default class AutoImageCaptionSetting extends Component {
|
||||||
static shouldRender(outletArgs, helper) {
|
static shouldRender(outletArgs, helper) {
|
||||||
return (
|
return (
|
||||||
helper.siteSettings.discourse_ai_enabled &&
|
helper.siteSettings.discourse_ai_enabled &&
|
||||||
showAiPreferences(outletArgs.model)
|
showAiPreferences(outletArgs.model, helper.siteSettings)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,17 @@ export default class PreferencesAiController extends Controller {
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
@tracked saved = false;
|
@tracked saved = false;
|
||||||
|
|
||||||
|
get showAutoImageCaptionSetting() {
|
||||||
|
const aiHelperEnabledFeatures =
|
||||||
|
this.siteSettings.ai_helper_enabled_features.split("|");
|
||||||
|
|
||||||
|
return (
|
||||||
|
this.model?.user_allowed_ai_auto_image_captions &&
|
||||||
|
aiHelperEnabledFeatures.includes("image_caption") &&
|
||||||
|
this.siteSettings.ai_helper_enabled
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
save() {
|
save() {
|
||||||
this.saved = false;
|
this.saved = false;
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
|
{{!
|
||||||
|
Later when we have more preferences,
|
||||||
|
move the conditional (showAutoImageCaptionSetting)
|
||||||
|
to be only around the auto-image-caption preference.
|
||||||
|
}}
|
||||||
|
{{#if this.showAutoImageCaptionSetting}}
|
||||||
|
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
|
||||||
|
|
||||||
<div class="control-group ai-setting">
|
<div class="control-group ai-setting">
|
||||||
<PreferenceCheckbox
|
<PreferenceCheckbox
|
||||||
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
|
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
|
||||||
@checked={{this.model.user_option.auto_image_caption}}
|
@checked={{this.model.user_option.auto_image_caption}}
|
||||||
data-setting-name="auto-image-caption"
|
data-setting-name="auto-image-caption"
|
||||||
class="pref-auto-image-caption"
|
class="pref-auto-image-caption"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SaveControls
|
||||||
|
@id="user_ai_preference_save"
|
||||||
|
@model={{this.model}}
|
||||||
|
@action={{this.save}}
|
||||||
|
@saved={{this.saved}}
|
||||||
/>
|
/>
|
||||||
</div>
|
{{/if}}
|
||||||
|
|
||||||
<SaveControls
|
|
||||||
@id="user_ai_preference_save"
|
|
||||||
@model={{this.model}}
|
|
||||||
@action={{this.save}}
|
|
||||||
@saved={{this.saved}}
|
|
||||||
/>
|
|
|
@ -22,6 +22,7 @@ RSpec.describe "AI image caption", type: :system, js: true do
|
||||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||||
assign_fake_provider_to(:ai_helper_model)
|
assign_fake_provider_to(:ai_helper_model)
|
||||||
assign_fake_provider_to(:ai_helper_image_caption_model)
|
assign_fake_provider_to(:ai_helper_image_caption_model)
|
||||||
|
SiteSetting.ai_helper_enabled = true
|
||||||
SiteSetting.ai_helper_enabled_features = "image_caption"
|
SiteSetting.ai_helper_enabled_features = "image_caption"
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
end
|
end
|
||||||
|
@ -87,6 +88,15 @@ RSpec.describe "AI image caption", type: :system, js: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "automatic image captioning" do
|
describe "automatic image captioning" do
|
||||||
|
context "when ai helper is disabled" do
|
||||||
|
before { SiteSetting.ai_helper_enabled = false }
|
||||||
|
|
||||||
|
it "should not have the setting present in the user preferences page" do
|
||||||
|
user_preferences_ai_page.visit(user)
|
||||||
|
expect(user_preferences_ai_page).to have_no_ai_preference("pref-auto-image-caption")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when toggling the setting from the user preferences page" do
|
context "when toggling the setting from the user preferences page" do
|
||||||
before { user.user_option.update!(auto_image_caption: false) }
|
before { user.user_option.update!(auto_image_caption: false) }
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,14 @@ module PageObjects
|
||||||
page.find(".#{preference} input").checked?
|
page.find(".#{preference} input").checked?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_ai_preference?(preference)
|
||||||
|
page.has_css?(".#{preference} input")
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_ai_preference?(preference)
|
||||||
|
page.has_no_css?(".#{preference} input")
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_setting(preference)
|
def toggle_setting(preference)
|
||||||
page.find(".#{preference} input").click
|
page.find(".#{preference} input").click
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue