Skip to content

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

FIX: Include post URL in ICS export description (#38797)

Régis Hanol51d7b763a9fd
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 b012059555a..c7f99dc7b44 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
@@ -14,7 +14,7 @@ DTEND:<%= ends_at.presence ? ends_at.utc.strftime("%Y%m%dT%H%M%SZ") : (starts_at
SUMMARY:<%= IcalEncoder.encode(event.name.presence || event.post.topic.title) %>
<%- if event.location.present? -%>LOCATION:<%= IcalEncoder.encode(event.location) %>
<%- end -%>
-DESCRIPTION:<%= IcalEncoder.encode(event.description.presence || event.post.excerpt) %>
+DESCRIPTION:<%= IcalEncoder.encode([(event.description.presence || event.post.excerpt), event.post.full_url].compact.join("\n")) %>
URL:<%= event.url.presence || event.post.topic.url(event.post.post_number) %>
END:VEVENT
<%- end -%>
diff --git a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
index 8b6b975e78d..8e598a7e010 100644
--- a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
@@ -119,6 +119,21 @@ module DiscoursePostEvent
expect(body).to include("END:VEVENT")
end
+ it "should include post url in description when no custom description is set" do
+ event =
+ Fabricate(:event, original_starts_at: 1.day.from_now, name: "Event Without Description")
+
+ get "/discourse-post-event/events.ics"
+
+ expect(response.status).to eq(200)
+ body = response.body
+
+ description_line = body.lines.find { |l| l.start_with?("DESCRIPTION:") }
+ post_url = "#{Discourse.base_url}#{event.post.url}"
+
+ expect(description_line).to include(post_url)
+ end
+
it "excludes events older than 3 months from ics feed by default" do
recent_event = Fabricate(:event, original_starts_at: 1.day.from_now, name: "Future Event")
old_event = Fabricate(:event, original_starts_at: 4.months.ago, name: "Old Event")