Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f9d641d

Browse files
authored
FIX: Restore gists previous group access behavior. (#1247)
Previously, allowing "everyone" to access gists meant anons would see them too. With the move to Personas, we used "[]" to reflect that. With discourse/discourse#32199 adding the "everyone" option to the personas-allowed groups, we are switching back to the original behavior. Leaving allowed groups empty should always mean nobody can use the feature.
1 parent ed907dd commit f9d641d

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

assets/javascripts/discourse/components/ai-persona-editor.gjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ export default class PersonaEditor extends Component {
9292

9393
@action
9494
async updateAllGroups() {
95-
this.allGroups = await Group.findAll();
95+
const groups = await Group.findAll({ include_everyone: true });
96+
97+
// Backwards-compatibility code. TODO(roman): Remove 01-09-2025
98+
const hasEveryoneGroup = groups.find((g) => g.id === 0);
99+
if (!hasEveryoneGroup) {
100+
const everyoneGroupName = "everyone";
101+
groups.push({ id: 0, name: everyoneGroupName });
102+
}
103+
104+
this.allGroups = groups;
96105
}
97106

98107
@action

db/fixtures/personas/603_ai_personas.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def from_setting(setting_name)
2525
setting_name = "ai_custom_summarization_allowed_groups"
2626
if persona_class == DiscourseAi::Personas::ShortSummarizer
2727
setting_name = "ai_summary_gists_allowed_groups"
28-
default_groups = [] # Blank == everyone
28+
default_groups = [Group::AUTO_GROUPS[:everyone]]
2929
end
3030

3131
persona.allowed_group_ids = from_setting(setting_name).first&.split("|") || default_groups
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
class SetCorrectDefaultForShortSummarizerPersona < ActiveRecord::Migration[7.2]
3+
def up
4+
execute <<~SQL
5+
UPDATE ai_personas
6+
SET allowed_group_ids = ARRAY[0]
7+
WHERE id = -12 AND allowed_group_ids = '{}'
8+
SQL
9+
end
10+
11+
def down
12+
raise ActiveRecord::IrreversibleMigration
13+
end
14+
end

lib/guardian_extensions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def can_see_gists?
2929
return false
3030
end
3131
persona_groups = ai_persona.allowed_group_ids.to_a
32-
return true if persona_groups.empty?
32+
return true if persona_groups.include?(Group::AUTO_GROUPS[:everyone])
3333
return false if anonymous?
3434

35-
ai_persona.allowed_group_ids.to_a.any? { |group_id| user.group_ids.include?(group_id) }
35+
persona_groups.any? { |group_id| user.group_ids.include?(group_id) }
3636
end
3737

3838
def can_request_summary?

spec/lib/guardian_extensions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
end
8787

8888
context "when access is set to everyone" do
89-
before { assign_persona_to(:ai_summary_gists_persona, []) }
89+
before { assign_persona_to(:ai_summary_gists_persona, [Group::AUTO_GROUPS[:everyone]]) }
9090

9191
it "returns true" do
9292
expect(guardian.can_see_gists?).to eq(true)

0 commit comments

Comments
 (0)