Skip to content

Commit 97fc822

Browse files
authored
FEATURE: Allow specific groups access to summary feature on PMs (#760)
New `ai_pm_summarization_allowed_groups` can be used to allow visibility of the summarization feature on PMs. This can be useful on forums where a lot of communication happens inside PMs.
1 parent c032826 commit 97fc822

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ en:
8080
ai_summarization_enabled: "Enable the topic summarization module."
8181
ai_summarization_model: "Model to use for summarization."
8282
ai_custom_summarization_allowed_groups: "Groups allowed to use create new summaries."
83+
ai_pm_summarization_allowed_groups: "Groups allowed to create and view summaries in PMs."
8384

8485
ai_bot_enabled: "Enable the AI Bot module."
8586
ai_bot_enable_chat_warning: "Display a warning when PM chat is initiated. Can be overriden by editing the translation string: discourse_ai.ai_bot.pm_warning"

config/settings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ discourse_ai:
353353
type: enum
354354
enum: "DiscourseAi::Configuration::LlmEnumerator"
355355
validator: "DiscourseAi::Configuration::LlmValidator"
356+
ai_pm_summarization_allowed_groups:
357+
type: group_list
358+
list_type: compact
359+
default: ""
356360
ai_custom_summarization_allowed_groups:
357361
type: group_list
358362
list_type: compact

lib/guardian_extensions.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ module GuardianExtensions
55
def can_see_summary?(target)
66
return false if !SiteSetting.ai_summarization_enabled
77

8-
# TODO we want a switch to allow summaries for all topics
9-
return false if target.class == Topic && target.private_message?
8+
if target.class == Topic && target.private_message?
9+
allowed =
10+
SiteSetting.ai_pm_summarization_allowed_groups_map.any? do |group_id|
11+
user.group_ids.include?(group_id)
12+
end
13+
14+
return false if !allowed
15+
end
1016

1117
has_cached_summary = AiSummary.exists?(target: target)
1218
return has_cached_summary if user.nil?

spec/lib/guardian_extensions_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
it "returns false" do
5151
expect(guardian.can_see_summary?(pm)).to eq(false)
5252
end
53+
54+
it "returns true if user is in a group that is allowed summaries" do
55+
SiteSetting.ai_pm_summarization_allowed_groups = group.id
56+
expect(guardian.can_see_summary?(pm)).to eq(true)
57+
end
5358
end
5459

5560
context "when there is no user" do

0 commit comments

Comments
 (0)