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

Commit a0aec48

Browse files
authored
FIX: gists are not html safe (#931)
Also allow "Everyone" in ai_hot_topic_gists_allowed_groups
1 parent f09e74c commit a0aec48

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

assets/javascripts/discourse/components/ai-topic-gist.gjs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Component from "@glimmer/component";
22
import { service } from "@ember/service";
33
import { htmlSafe } from "@ember/template";
4-
import { emojiUnescape, sanitize } from "discourse/lib/text";
54

65
export default class AiTopicGist extends Component {
76
@service gists;
@@ -10,20 +9,30 @@ export default class AiTopicGist extends Component {
109
return this.gists.preference === "table-ai" && this.gists.shouldShow;
1110
}
1211

13-
get gistOrExcerpt() {
14-
const topic = this.args.topic;
15-
const gist = topic.get("ai_topic_gist");
16-
const excerpt = emojiUnescape(sanitize(topic.get("excerpt")));
12+
get hasGist() {
13+
return !!this.gist;
14+
}
15+
16+
get gist() {
17+
return this.args.topic.get("ai_topic_gist");
18+
}
1719

18-
return gist || excerpt;
20+
get escapedExceprt() {
21+
return this.args.topic.get("escapedExcerpt");
1922
}
2023

2124
<template>
2225
{{#if this.shouldShow}}
23-
{{#if this.gistOrExcerpt}}
26+
{{#if this.hasGist}}
2427
<div class="excerpt">
25-
<div>{{htmlSafe this.gistOrExcerpt}}</div>
28+
<div>{{this.gist}}</div>
2629
</div>
30+
{{else}}
31+
{{#if this.esacpedExceprt}}
32+
<div class="excerpt">
33+
<div>{{htmlSafe this.escapedExceprt}}</div>
34+
</div>
35+
{{/if}}
2736
{{/if}}
2837
{{/if}}
2938
</template>

lib/guardian_extensions.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def can_see_summary?(target)
2424
def can_see_gists?
2525
return false if !SiteSetting.ai_summarization_enabled
2626
return false if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
27+
if SiteSetting.ai_hot_topic_gists_allowed_groups.to_s == Group::AUTO_GROUPS[:everyone].to_s
28+
return true
29+
end
2730
return false if anonymous?
2831
return false if SiteSetting.ai_hot_topic_gists_allowed_groups_map.empty?
2932

spec/lib/guardian_extensions_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@
8989
end
9090
end
9191

92+
context "when setting is set to everyone" do
93+
before { SiteSetting.ai_hot_topic_gists_allowed_groups = Group::AUTO_GROUPS[:everyone] }
94+
95+
it "returns true" do
96+
expect(guardian.can_see_gists?).to eq(true)
97+
end
98+
end
99+
92100
context "when there is a user but it's not a member of the allowed groups" do
93101
before { SiteSetting.ai_hot_topic_gists_allowed_groups = "" }
94102

0 commit comments

Comments
 (0)