Skip to content

A platform for community discussion. Free, open, simple.

FIX: Include topic URL in "Add to calendar" export (#45210)

Martin Brennan6dfda265cb9d
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
index 20fef64db27..c25fe6941a4 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
@@ -11,6 +11,7 @@ import discourseLater from "discourse/lib/later";
import { applyLocalDates } from "discourse/lib/local-dates";
import { cook } from "discourse/lib/text";
import dIcon from "discourse/ui-kit/helpers/d-icon";
+import eventCalendarDetails from "../../lib/event-calendar-details.js";
export default class DiscoursePostEventDates extends Component {
@service siteSettings;
@@ -112,9 +113,7 @@ export default class DiscoursePostEventDates extends Component {
options.location = event.location;
}
- if (event.description) {
- options.details = event.description;
- }
+ options.details = eventCalendarDetails(event);
return generateIcsData(title, dates, options);
}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/lib/add-event-to-calendar.js b/plugins/discourse-events/assets/javascripts/discourse/lib/add-event-to-calendar.js
index 798daa41f2c..c026eb452eb 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/lib/add-event-to-calendar.js
+++ b/plugins/discourse-events/assets/javascripts/discourse/lib/add-event-to-calendar.js
@@ -1,4 +1,5 @@
import { downloadCalendar } from "discourse/lib/download-calendar";
+import eventCalendarDetails from "./event-calendar-details.js";
export default function addEventToCalendar(event) {
downloadCalendar(
@@ -18,7 +19,7 @@ export default function addEventToCalendar(event) {
? null
: event.rrule,
location: event.location,
- details: event.description,
+ details: eventCalendarDetails(event),
}
);
}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/lib/event-calendar-details.js b/plugins/discourse-events/assets/javascripts/discourse/lib/event-calendar-details.js
new file mode 100644
index 00000000000..92949bb9dce
--- /dev/null
+++ b/plugins/discourse-events/assets/javascripts/discourse/lib/event-calendar-details.js
@@ -0,0 +1,8 @@
+import { getAbsoluteURL } from "discourse/lib/get-url";
+
+export default function eventCalendarDetails(event) {
+ const description = event.description?.trim() ? event.description : null;
+ const postUrl = event.post?.url ? getAbsoluteURL(event.post.url) : null;
+
+ return [description, postUrl].filter(Boolean).join("\n");
+}
diff --git a/plugins/discourse-events/test/javascripts/integration/components/dates-test.gjs b/plugins/discourse-events/test/javascripts/integration/components/dates-test.gjs
index 1af1541ea72..f02e9dd0c1a 100644
--- a/plugins/discourse-events/test/javascripts/integration/components/dates-test.gjs
+++ b/plugins/discourse-events/test/javascripts/integration/components/dates-test.gjs
@@ -1,5 +1,7 @@
-import { render, settled, waitFor } from "@ember/test-helpers";
+import { find, render, settled, waitFor } from "@ember/test-helpers";
import { module, skip, test } from "qunit";
+import { bbcodeAttributeDecode } from "discourse/lib/bbcode-attributes";
+import { getAbsoluteURL } from "discourse/lib/get-url";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { fakeTime } from "discourse/tests/helpers/qunit-helpers";
import Dates from "discourse/plugins/discourse-events/discourse/components/discourse-post-event/dates";
@@ -66,6 +68,46 @@ module("Integration | Component | Dates", function (hooks) {
await settled();
}
+ test("embedded ICS includes the topic URL without a description", async function (assert) {
+ const event = {
+ ...events.currentYear.today,
+ description: null,
+ post: { url: "/t/workshop/123" },
+ };
+
+ await render(<template><Dates @event={{event}} /></template>);
+ await waitForDates();
+
+ const ics = bbcodeAttributeDecode(
+ find(".discourse-local-date").dataset.ics
+ ).replace(/\r\n[ \t]/g, "");
+ const postUrl = getAbsoluteURL(event.post.url);
+ assert.true(
+ ics.includes(`DESCRIPTION:${postUrl}\r\n`),
+ "the date popover's ICS links to the topic"
+ );
+ });
+
+ test("embedded ICS includes the topic URL with a description", async function (assert) {
+ const event = {
+ ...events.currentYear.today,
+ description: "Bring your laptop",
+ post: { url: "/t/workshop/123" },
+ };
+
+ await render(<template><Dates @event={{event}} /></template>);
+ await waitForDates();
+
+ const ics = bbcodeAttributeDecode(
+ find(".discourse-local-date").dataset.ics
+ ).replace(/\r\n[ \t]/g, "");
+ const postUrl = getAbsoluteURL(event.post.url);
+ assert.true(
+ ics.includes(`DESCRIPTION:Bring your laptop\\n${postUrl}\r\n`),
+ "the date popover's ICS preserves the description and links to the topic"
+ );
+ });
+
module("dates without time", function () {
test("formats weekdays within range 1 day before and 2 days after the specified day", async function (assert) {
await render(
diff --git a/plugins/discourse-events/test/javascripts/integration/components/event-calendar-export-test.gjs b/plugins/discourse-events/test/javascripts/integration/components/event-calendar-export-test.gjs
new file mode 100644
index 00000000000..cf06652b32a
--- /dev/null
+++ b/plugins/discourse-events/test/javascripts/integration/components/event-calendar-export-test.gjs
@@ -0,0 +1,302 @@
+import { click, render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import sinon from "sinon";
+import ModalContainer from "discourse/components/modal-container";
+import { restoreBaseUri, setupURL } from "discourse/lib/get-url";
+import User from "discourse/models/user";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import formKit from "discourse/tests/helpers/form-kit-helper";
+import CalendarPrompt from "discourse/plugins/discourse-events/discourse/components/discourse-post-event/calendar-prompt";
+import MoreMenu from "discourse/plugins/discourse-events/discourse/components/discourse-post-event/more-menu";
+
+async function exportCalendar(context, calendar) {
+ context.currentUser.set(
+ "user_option.default_calendar",
+ context.useModal ? "none_selected" : calendar
+ );
+
+ await render(
+ <template>
+ <ModalContainer />
+ {{#if context.fromMenu}}
+ <MoreMenu @event={{context.event}} />
+ {{else}}
+ <CalendarPrompt @event={{context.event}} />
+ {{/if}}
+ </template>
+ );
+
+ if (context.fromMenu) {
+ await click(".discourse-post-event-more-menu-trigger");
+ await click(".add-to-calendar button");
+ } else {
+ await click(".event-calendar-prompt__actions .btn-primary");
+ }
+
+ if (context.useModal) {
+ await formKit().field("calendar").select(calendar);
+ await click(".download-calendar-modal .btn-primary");
+ }
+}
+
+function assertGoogleDetails(assert, context, expected) {
+ assert.true(context.openWindow.calledOnce, "opens one calendar draft");
+ const url = new URL(context.openWindow.firstCall.args[0]);
+ assert.strictEqual(
+ url.searchParams.get("details"),
+ expected,
+ "Google Calendar details preserve the description and topic URL"
+ );
+}
+
+async function assertIcsDetails(assert, context, expected) {
+ assert.true(context.createObjectURL.calledOnce, "creates one ICS download");
+ const file = context.createObjectURL.firstCall.args[0];
+ const ics = (await file.text()).replace(/\r\n[ \t]/g, "");
+ const details = ics
+ .split("\r\n")
+ .find((line) => line.startsWith("DESCRIPTION:"))
+ ?.slice("DESCRIPTION:".length);
+ assert.strictEqual(
+ details,
+ expected,
+ "ICS details preserve the escaped description and topic URL"
+ );
+}
+
+module("Integration | Component | EventCalendarExport", function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ setupURL(null, "https://forum.example", "");
+ sinon.stub(User, "current").returns(this.currentUser);
+ this.openWindow = sinon.stub(window, "open");
+ this.createObjectURL = sinon
+ .stub(URL, "createObjectURL")
+ .returns("blob:calendar-export");
+ sinon.stub(HTMLAnchorElement.prototype, "click");
+ this.event = {
+ name: "Workshop",
+ startsAt: "2026-11-01T10:00:00Z",
+ endsAt: "2026-11-01T11:00:00Z",
+ post: { url: "/t/workshop/123", topic: { title: "Workshop" } },
+ creator: { username: "eviltrout" },
+ };
+ });
+
+ hooks.afterEach(function () {
+ restoreBaseUri();
+ });
+
+ module("Event menu", function (menuHooks) {
+ menuHooks.beforeEach(function () {
+ this.fromMenu = true;
+ });
+
+ module("Saved preference", function (preferenceHooks) {
+ preferenceHooks.beforeEach(function () {
+ this.useModal = false;
+ });
+
+ test("Google Calendar includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("Google Calendar includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "Bring snacks; tea, coffee\nC:\\notes\nhttps://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "Bring snacks\\; tea\\, coffee\\nC:\\\\notes\\nhttps://forum.example/t/workshop/123"
+ );
+ });
+ });
+
+ module("Calendar modal", function (modalHooks) {
+ modalHooks.beforeEach(function () {
+ this.useModal = true;
+ });
+
+ test("Google Calendar includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("Google Calendar includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "Bring snacks; tea, coffee\nC:\\notes\nhttps://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "Bring snacks\\; tea\\, coffee\\nC:\\\\notes\\nhttps://forum.example/t/workshop/123"
+ );
+ });
+ });
+ });
+
+ module("RSVP prompt", function (promptHooks) {
+ promptHooks.beforeEach(function () {
+ this.fromMenu = false;
+ });
+
+ module("Saved preference", function (preferenceHooks) {
+ preferenceHooks.beforeEach(function () {
+ this.useModal = false;
+ });
+
+ test("Google Calendar includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("Google Calendar includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "Bring snacks; tea, coffee\nC:\\notes\nhttps://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "Bring snacks\\; tea\\, coffee\\nC:\\\\notes\\nhttps://forum.example/t/workshop/123"
+ );
+ });
+ });
+
+ module("Calendar modal", function (modalHooks) {
+ modalHooks.beforeEach(function () {
+ this.useModal = true;
+ });
+
+ test("Google Calendar includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("Google Calendar includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "google");
+
+ assertGoogleDetails(
+ assert,
+ this,
+ "Bring snacks; tea, coffee\nC:\\notes\nhttps://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL without a description", async function (assert) {
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "https://forum.example/t/workshop/123"
+ );
+ });
+
+ test("ICS includes the topic URL with a description", async function (assert) {
+ this.event.description = "Bring snacks; tea, coffee\nC:\\notes";
+
+ await exportCalendar(this, "ics");
+
+ await assertIcsDetails(
+ assert,
+ this,
+ "Bring snacks\\; tea\\, coffee\\nC:\\\\notes\\nhttps://forum.example/t/workshop/123"
+ );
+ });
+ });
+ });
+});
diff --git a/plugins/discourse-events/test/javascripts/unit/lib/event-calendar-details-test.js b/plugins/discourse-events/test/javascripts/unit/lib/event-calendar-details-test.js
new file mode 100644
index 00000000000..3749a519e01
--- /dev/null
+++ b/plugins/discourse-events/test/javascripts/unit/lib/event-calendar-details-test.js
@@ -0,0 +1,95 @@
+import { setupTest } from "ember-qunit";
+import { module, test } from "qunit";
+import { restoreBaseUri, setupURL } from "discourse/lib/get-url";
+import eventCalendarDetails from "discourse/plugins/discourse-events/discourse/lib/event-calendar-details";
+
+module("Unit | Lib | event-calendar-details", function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ setupURL(null, "https://forum.example", "");
+ });
+
+ hooks.afterEach(function () {
+ restoreBaseUri();
+ });
+
+ test("preserves the description and appends the post URL", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({
+ description: "Bring your laptop\nQuestions welcome!",
+ post: { url: "/t/workshop/123" },
+ url: "https://external.example/meeting",
+ }),
+ "Bring your laptop\nQuestions welcome!\nhttps://forum.example/t/workshop/123",
+ "the link returns to the topic rather than the external event website"
+ );
+ });
+
+ test("includes the post URL with a missing description", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({
+ description: undefined,
+ post: { url: "/t/workshop/123" },
+ }),
+ "https://forum.example/t/workshop/123",
+ "blank descriptions leave just the absolute post URL"
+ );
+ });
+
+ test("includes the post URL with a null description", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({
+ description: null,
+ post: { url: "/t/workshop/123" },
+ }),
+ "https://forum.example/t/workshop/123",
+ "blank descriptions leave just the absolute post URL"
+ );
+ });
+
+ test("includes the post URL with a empty description", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({
+ description: "",
+ post: { url: "/t/workshop/123" },
+ }),
+ "https://forum.example/t/workshop/123",
+ "blank descriptions leave just the absolute post URL"
+ );
+ });
+
+ test("includes the post URL with a whitespace-only description", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({
+ description: " \n ",
+ post: { url: "/t/workshop/123" },
+ }),
+ "https://forum.example/t/workshop/123",
+ "blank descriptions leave just the absolute post URL"
+ );
+ });
+
+ test("handles missing post data", function (assert) {
+ assert.strictEqual(
+ eventCalendarDetails({ description: "Bring your laptop" }),
+ "Bring your laptop",
+ "the description is still available without a post"
+ );
+ assert.strictEqual(
+ eventCalendarDetails({ post: {} }),
+ "",
+ "missing content does not produce an invalid URL"
+ );
+ });
+
+ test("preserves the site subfolder exactly once", function (assert) {
+ setupURL(null, "https://forum.example/community", "/community");
+
+ assert.strictEqual(
+ eventCalendarDetails({ post: { url: "/community/t/workshop/123" } }),
+ "https://forum.example/community/t/workshop/123",
+ "the post URL includes the configured subfolder"
+ );
+ });
+});