From 71affe75bf6154b837f96233d3eb88be7121ec76 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 27 May 2024 13:27:45 -0700 Subject: [PATCH] UX: Hide AI preferences page completely if no settings for user (#644) --- .../user-preferences-nav/ai-preferences.gjs | 18 +++++++++- .../discourse/controllers/preferences-ai.js | 9 ----- .../discourse/templates/preferences/ai.hbs | 35 ++++++++----------- config/locales/client.en.yml | 5 --- 4 files changed, 31 insertions(+), 36 deletions(-) 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 298c7119..2fc2a2b4 100644 --- a/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs +++ b/assets/javascripts/discourse/connectors/user-preferences-nav/ai-preferences.gjs @@ -3,9 +3,25 @@ import { LinkTo } from "@ember/routing"; import dIcon from "discourse-common/helpers/d-icon"; import i18n from "discourse-common/helpers/i18n"; +function showAiPreferences(user, siteSettings) { + // 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. + const userGroups = user.groups.map((g) => g.id); + const captionGroups = siteSettings.ai_auto_image_caption_allowed_groups + .split("|") + .map((id) => parseInt(id, 10)); + + return userGroups.some((groupId) => captionGroups.includes(groupId)); +} + export default class AutoImageCaptionSetting extends Component { static shouldRender(outletArgs, helper) { - return helper.siteSettings.discourse_ai_enabled; + return ( + helper.siteSettings.discourse_ai_enabled && + showAiPreferences(outletArgs.model, helper.siteSettings) + ); }