Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions assets/javascripts/discourse/components/ai-topic-gist.gjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { emojiUnescape, sanitize } from "discourse/lib/text";

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

get gistOrExcerpt() {
const topic = this.args.topic;
const gist = topic.get("ai_topic_gist");
const excerpt = emojiUnescape(sanitize(topic.get("excerpt")));
get hasGist() {
return !!this.gist;
}

get gist() {
return this.args.topic.get("ai_topic_gist");
}

return gist || excerpt;
get escapedExceprt() {
return this.args.topic.get("escapedExcerpt");
}

<template>
{{#if this.shouldShow}}
{{#if this.gistOrExcerpt}}
{{#if this.hasGist}}
<div class="excerpt">
<div>{{htmlSafe this.gistOrExcerpt}}</div>
<div>{{this.gist}}</div>
</div>
{{else}}
{{#if this.esacpedExceprt}}
<div class="excerpt">
<div>{{htmlSafe this.escapedExceprt}}</div>
</div>
{{/if}}
{{/if}}
{{/if}}
</template>
Expand Down
3 changes: 3 additions & 0 deletions lib/guardian_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def can_see_summary?(target)
def can_see_gists?
return false if !SiteSetting.ai_summarization_enabled
return false if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
if SiteSetting.ai_hot_topic_gists_allowed_groups.to_s == Group::AUTO_GROUPS[:everyone].to_s
return true
end
return false if anonymous?
return false if SiteSetting.ai_hot_topic_gists_allowed_groups_map.empty?

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/guardian_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
end
end

context "when setting is set to everyone" do
before { SiteSetting.ai_hot_topic_gists_allowed_groups = Group::AUTO_GROUPS[:everyone] }

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

context "when there is a user but it's not a member of the allowed groups" do
before { SiteSetting.ai_hot_topic_gists_allowed_groups = "" }

Expand Down