FIX: Prevent AI caption setting from showing unless all criteria is met

This commit is contained in:
Keegan George 2024-08-14 09:36:09 -07:00
parent 72980a3d84
commit 0ebcf52761
No known key found for this signature in database
GPG Key ID: 91B40E38537AC000
3 changed files with 43 additions and 18 deletions

View File

@ -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)
);
}

View File

@ -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;

View File

@ -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">
<PreferenceCheckbox
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
@checked={{this.model.user_option.auto_image_caption}}
data-setting-name="auto-image-caption"
class="pref-auto-image-caption"
<div class="control-group ai-setting">
<PreferenceCheckbox
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
@checked={{this.model.user_option.auto_image_caption}}
data-setting-name="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>
<SaveControls
@id="user_ai_preference_save"
@model={{this.model}}
@action={{this.save}}
@saved={{this.saved}}
/>
{{/if}}