A platform for community discussion. Free, open, simple.
FIX: Display summaries for anonymous users. (#23294)
Roman Rizzie20de81de305
diff --git a/app/assets/javascripts/discourse/app/components/summary-box.js b/app/assets/javascripts/discourse/app/components/summary-box.jsindex 766262ddc4d..1827c5ab92b 100644--- a/app/assets/javascripts/discourse/app/components/summary-box.js+++ b/app/assets/javascripts/discourse/app/components/summary-box.js@@ -14,6 +14,7 @@ const MIN_POST_READ_TIME = 4;export default class SummaryBox extends Component {@service siteSettings;@service messageBus;+ @service currentUser;@tracked summary = "";@tracked summarizedOn = null;@@ -166,12 +167,27 @@ export default class SummaryBox extends Component {this.loadingSummary = true;}- let fetchURL = `/t/${this.args.postAttrs.topicId}/strategy-summary?stream=true`;+ let fetchURL = `/t/${this.args.postAttrs.topicId}/strategy-summary`;++ if (this.currentUser) {+ fetchURL += `stream=true`;+ }if (this.canRegenerate) {- fetchURL += "&skip_age_check=true";+ if (this.currentUser) {+ fetchURL += "&";+ }++ fetchURL += "skip_age_check=true";}- ajax(fetchURL).catch(popupAjaxError);+ ajax(fetchURL)+ .then((data) => {+ if (!this.currentUser) {+ data.done = true;+ this._updateSummary(data);+ }+ })+ .catch(popupAjaxError);}}diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-summary-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-summary-test.jsindex b1828c6ab39..6f19592a3dc 100644--- a/app/assets/javascripts/discourse/tests/acceptance/topic-summary-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-summary-test.js@@ -71,3 +71,44 @@ acceptance("Topic - Summary", function (needs) {assert.ok(exists(".summary-box .summarized-on"), "summary metadata exists");});});++acceptance("Topic - Summary - Anon", function (needs) {+ const finalSummary = "This is a completed summary";++ needs.pretender((server, helper) => {+ server.get("/t/1.json", () => {+ const json = cloneJSON(topicFixtures["/t/280/1.json"]);+ json.id = 1;+ json.summarizable = true;++ return helper.response(json);+ });++ server.get("/t/1/strategy-summary", () => {+ return helper.response({+ topic_summary: {+ summarized_text: finalSummary,+ summarized_on: "2023-01-01T04:00:00.000Z",+ algorithm: "OpenAI GPT-4",+ outdated: false,+ new_posts_since_summary: false,+ can_regenerate: false,+ },+ });+ });+ });++ test("displays cached summary inmediately", async function (assert) {+ await visit("/t/-/1");++ await click(".topic-strategy-summarization");++ assert.strictEqual(+ query(".summary-box .generated-summary p").innerText,+ finalSummary,+ "Updates the summary with the result"+ );++ assert.ok(exists(".summary-box .summarized-on"), "summary metadata exists");+ });+});diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 789e3610000..9b9016739c8 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -1185,7 +1185,7 @@ class TopicsController < ApplicationControlleropts = params.permit(:skip_age_check)- if params[:stream]+ if params[:stream] && current_userJobs.enqueue(:stream_topic_summary,topic_id: topic.id,