Skip to content

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

FIX: event location field in .ics / google calendar exports (#35355)

Régis Hanolc6fc6d9612ae
diff --git a/plugins/discourse-calendar/app/views/discourse_post_event/events/index.ics.erb b/plugins/discourse-calendar/app/views/discourse_post_event/events/index.ics.erb
index 5c014b1a0ff..e0597f1fabd 100644
--- a/plugins/discourse-calendar/app/views/discourse_post_event/events/index.ics.erb
+++ b/plugins/discourse-calendar/app/views/discourse_post_event/events/index.ics.erb
@@ -1,15 +1,16 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Discourse//<%= Discourse.current_hostname %>//<%= Discourse.full_version %>//EN
-<% @events.each do |event| %>
- BEGIN:VEVENT
- UID:calendar_event_#<%= event.id %>@<%= Discourse.current_hostname %>
- DTSTAMP:<%= Time.now.utc.strftime("%Y%m%dT%H%M%SZ") %>
- DTSTART:<%= event.starts_at.strftime("%Y%m%dT%H%M%SZ") %>
- DTEND:<%= event.ends_at.presence ? event.ends_at.strftime("%Y%m%dT%H%M%SZ") : (event.starts_at + 1.hour).strftime("%Y%m%dT%H%M%SZ") %>
- SUMMARY:<%= event.name.presence || event.post.topic.title %>
- DESCRIPTION:<%= PrettyText.format_for_email(event.post.excerpt, event.post).html_safe.gsub(/\r?\n/, '\n') %>
- URL:<%= event.post.topic.url(event.post.post_number) %>
- END:VEVENT
-<% end %>
+<%- @events.each do |event| -%>
+BEGIN:VEVENT
+UID:calendar_event_#<%= event.id %>@<%= Discourse.current_hostname %>
+DTSTAMP:<%= Time.now.utc.strftime("%Y%m%dT%H%M%SZ") %>
+DTSTART:<%= event.starts_at.strftime("%Y%m%dT%H%M%SZ") %>
+DTEND:<%= event.ends_at.presence ? event.ends_at.strftime("%Y%m%dT%H%M%SZ") : (event.starts_at + 1.hour).strftime("%Y%m%dT%H%M%SZ") %>
+SUMMARY:<%= event.name.presence || event.post.topic.title %>
+<%- if event.location.present? -%> LOCATION:<%= event.location %><%- end -%>
+DESCRIPTION:<%= event.description.presence || PrettyText.format_for_email(event.post.excerpt, event.post).html_safe.gsub(/\r?\n/, '\n') %>
+URL:<%= event.url.presence || event.post.topic.url(event.post.post_number) %>
+END:VEVENT
+<%- end -%>
END:VCALENDAR
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs
index eab3b666df5..e05332743c0 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs
@@ -9,7 +9,6 @@ import concatClass from "discourse/helpers/concat-class";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { downloadCalendar } from "discourse/lib/download-calendar";
import { exportEntity } from "discourse/lib/export-csv";
-import { getAbsoluteURL } from "discourse/lib/get-url";
import { cook } from "discourse/lib/text";
import { applyValueTransformer } from "discourse/lib/transformer";
import { i18n } from "discourse-i18n";
@@ -85,8 +84,8 @@ export default class DiscoursePostEventMoreMenu extends Component {
],
{
rrule: event.rrule,
- location: event.url,
- details: getAbsoluteURL(event.post.url),
+ location: event.location,
+ details: event.description,
}
);
}
diff --git a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
index 50b599880d8..9b66829234a 100644
--- a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
@@ -82,6 +82,42 @@ module DiscoursePostEvent
expect(body).to include("SUMMARY:Test Event 1")
expect(body).to include("SUMMARY:Test Event 2")
end
+
+ it "should include location and description in ics format" do
+ event =
+ Fabricate(
+ :event,
+ original_starts_at: 1.day.from_now,
+ name: "Tech Conference",
+ location: "https://meet.google.com/abc-defg-hij",
+ description: "Bring your laptop and questions!",
+ url: "https://example.com/event-info",
+ )
+
+ get "/discourse-post-event/events.ics"
+
+ expect(response.status).to eq(200)
+ expect(response.content_type).to include("text/calendar")
+
+ body = response.body
+ expect(body).to include("SUMMARY:Tech Conference")
+ expect(body).to include("LOCATION:https://meet.google.com/abc-defg-hij")
+ expect(body).to include("DESCRIPTION:Bring your laptop and questions!")
+ expect(body).to include("URL:https://example.com/event-info")
+ end
+
+ it "should handle events without location and description in ics format" do
+ event = Fabricate(:event, original_starts_at: 1.day.from_now, name: "Simple Event")
+
+ get "/discourse-post-event/events.ics"
+
+ expect(response.status).to eq(200)
+ body = response.body
+ expect(body).to include("SUMMARY:Simple Event")
+ # Should still generate valid ICS even without LOCATION/DESCRIPTION
+ expect(body).to include("BEGIN:VEVENT")
+ expect(body).to include("END:VEVENT")
+ end
end
context "with an existing post" do