DEV: Make more group-based settings client: false (#474)
Affects the following settings: ai_toxicity_groups_bypass ai_helper_allowed_groups ai_helper_custom_prompts_allowed_groups post_ai_helper_allowed_groups This turns off client: true for these group-based settings, because there is no guarantee that the current user gets all their group memberships serialized to the client. Better to check server-side first.
This commit is contained in:
parent
d66915ecc1
commit
dd6b073fc3
|
@ -234,12 +234,7 @@ export default class AiHelperContextMenu extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_showUserCustomPrompts() {
|
_showUserCustomPrompts() {
|
||||||
const allowedGroups =
|
return this.currentUser?.can_use_custom_prompts;
|
||||||
this.siteSettings?.ai_helper_custom_prompts_allowed_groups
|
|
||||||
.split("|")
|
|
||||||
.map((id) => parseInt(id, 10));
|
|
||||||
|
|
||||||
return this.currentUser?.groups.some((g) => allowedGroups.includes(g.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleBoundaries() {
|
handleBoundaries() {
|
||||||
|
|
|
@ -186,12 +186,7 @@ export default class AIHelperOptionsMenu extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_showUserCustomPrompts() {
|
_showUserCustomPrompts() {
|
||||||
const allowedGroups =
|
return this.currentUser?.can_use_custom_prompts;
|
||||||
this.siteSettings?.ai_helper_custom_prompts_allowed_groups
|
|
||||||
.split("|")
|
|
||||||
.map((id) => parseInt(id, 10));
|
|
||||||
|
|
||||||
return this.currentUser?.groups.some((g) => allowedGroups.includes(g.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
export function showComposerAIHelper(outletArgs, helper, featureType) {
|
export function showComposerAIHelper(outletArgs, helper, featureType) {
|
||||||
const enableHelper = _helperEnabled(helper.siteSettings);
|
const enableHelper = _helperEnabled(helper.siteSettings);
|
||||||
const enableAssistant = _canUseAssistant(
|
const enableAssistant = helper.currentUser.can_use_assistant;
|
||||||
helper.currentUser,
|
|
||||||
_findAllowedGroups(helper.siteSettings.ai_helper_allowed_groups)
|
|
||||||
);
|
|
||||||
const canShowInPM = helper.siteSettings.ai_helper_allowed_in_pm;
|
const canShowInPM = helper.siteSettings.ai_helper_allowed_in_pm;
|
||||||
const enableFeature =
|
const enableFeature =
|
||||||
helper.siteSettings.ai_helper_enabled_features.includes(featureType);
|
helper.siteSettings.ai_helper_enabled_features.includes(featureType);
|
||||||
|
@ -18,10 +15,7 @@ export function showComposerAIHelper(outletArgs, helper, featureType) {
|
||||||
export function showPostAIHelper(outletArgs, helper) {
|
export function showPostAIHelper(outletArgs, helper) {
|
||||||
return (
|
return (
|
||||||
_helperEnabled(helper.siteSettings) &&
|
_helperEnabled(helper.siteSettings) &&
|
||||||
_canUseAssistant(
|
helper.currentUser.can_use_assistant_in_post
|
||||||
helper.currentUser,
|
|
||||||
_findAllowedGroups(helper.siteSettings.post_ai_helper_allowed_groups)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +24,3 @@ function _helperEnabled(siteSettings) {
|
||||||
siteSettings.discourse_ai_enabled && siteSettings.composer_ai_helper_enabled
|
siteSettings.discourse_ai_enabled && siteSettings.composer_ai_helper_enabled
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _findAllowedGroups(setting) {
|
|
||||||
return setting.split("|").map((id) => parseInt(id, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
function _canUseAssistant(user, allowedGroups) {
|
|
||||||
return user?.groups.some((g) => allowedGroups.includes(g.id));
|
|
||||||
}
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ discourse_ai:
|
||||||
default: 60
|
default: 60
|
||||||
client: false
|
client: false
|
||||||
ai_toxicity_groups_bypass:
|
ai_toxicity_groups_bypass:
|
||||||
client: true
|
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: "3" # 3: @staff
|
default: "3" # 3: @staff
|
||||||
|
@ -172,7 +171,6 @@ discourse_ai:
|
||||||
client: true
|
client: true
|
||||||
validator: "DiscourseAi::Configuration::LlmDependencyValidator"
|
validator: "DiscourseAi::Configuration::LlmDependencyValidator"
|
||||||
ai_helper_allowed_groups:
|
ai_helper_allowed_groups:
|
||||||
client: true
|
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: "3|14" # 3: @staff, 14: @trust_level_4
|
default: "3|14" # 3: @staff, 14: @trust_level_4
|
||||||
|
@ -188,14 +186,12 @@ discourse_ai:
|
||||||
enum: "DiscourseAi::Configuration::LlmEnumerator"
|
enum: "DiscourseAi::Configuration::LlmEnumerator"
|
||||||
validator: "DiscourseAi::Configuration::LlmValidator"
|
validator: "DiscourseAi::Configuration::LlmValidator"
|
||||||
ai_helper_custom_prompts_allowed_groups:
|
ai_helper_custom_prompts_allowed_groups:
|
||||||
client: true
|
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: "3" # 3: @staff
|
default: "3" # 3: @staff
|
||||||
allow_any: false
|
allow_any: false
|
||||||
refresh: true
|
refresh: true
|
||||||
post_ai_helper_allowed_groups:
|
post_ai_helper_allowed_groups:
|
||||||
client: true
|
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: "3|14" # 3: @staff, 14: @trust_level_4
|
default: "3|14" # 3: @staff, 14: @trust_level_4
|
||||||
|
|
|
@ -100,6 +100,18 @@ module DiscourseAi
|
||||||
bots
|
bots
|
||||||
end
|
end
|
||||||
|
|
||||||
|
plugin.add_to_serializer(:current_user, :can_use_assistant) do
|
||||||
|
scope.user.in_any_groups?(SiteSetting.ai_helper_allowed_groups_map)
|
||||||
|
end
|
||||||
|
|
||||||
|
plugin.add_to_serializer(:current_user, :can_use_assistant_in_post) do
|
||||||
|
scope.user.in_any_groups?(SiteSetting.post_ai_helper_allowed_groups_map)
|
||||||
|
end
|
||||||
|
|
||||||
|
plugin.add_to_serializer(:current_user, :can_use_custom_prompts) do
|
||||||
|
scope.user.in_any_groups?(SiteSetting.ai_helper_custom_prompts_allowed_groups_map)
|
||||||
|
end
|
||||||
|
|
||||||
plugin.register_svg_icon("robot")
|
plugin.register_svg_icon("robot")
|
||||||
|
|
||||||
plugin.add_to_serializer(
|
plugin.add_to_serializer(
|
||||||
|
|
Loading…
Reference in New Issue