diff --git a/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs b/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs index 8f0283a0..ec289dfb 100644 --- a/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs +++ b/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs @@ -3,19 +3,26 @@ import { LinkTo } from "@ember/routing"; import dIcon from "discourse-common/helpers/d-icon"; 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 // AI preferences if these conditions aren't met. // 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. - 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 { static shouldRender(outletArgs, helper) { return ( helper.siteSettings.discourse_ai_enabled && - showAiPreferences(outletArgs.model) + showAiPreferences(outletArgs.model, helper.siteSettings) ); } diff --git a/assets/javascripts/discourse/controllers/preferences-ai.js b/assets/javascripts/discourse/controllers/preferences-ai.js index 58856a68..5ae900bc 100644 --- a/assets/javascripts/discourse/controllers/preferences-ai.js +++ b/assets/javascripts/discourse/controllers/preferences-ai.js @@ -11,6 +11,17 @@ export default class PreferencesAiController extends Controller { @service siteSettings; @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 save() { this.saved = false; diff --git a/assets/javascripts/discourse/templates/preferences/ai.hbs b/assets/javascripts/discourse/templates/preferences/ai.hbs index dceec402..182a2f73 100644 --- a/assets/javascripts/discourse/templates/preferences/ai.hbs +++ b/assets/javascripts/discourse/templates/preferences/ai.hbs @@ -1,17 +1,24 @@ - +{{! + Later when we have more preferences, + move the conditional (showAutoImageCaptionSetting) + to be only around the auto-image-caption preference. + }} +{{#if this.showAutoImageCaptionSetting}} + -