A platform for community discussion. Free, open, simple.
FEATURE: Add friendly names to calendar subscription feeds (#39154)
Rafael dos Santos Silvab38c2d7e9b98
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 16507492465..d3726926183 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -1934,6 +1934,9 @@ class UsersController < ApplicationControllerendendformat.ics do+ @calendar_name =+ I18n.t("calendar_subscriptions.bookmarks_feed_name", site_title: SiteSetting.title)+bookmark_query = Bookmark.with_reminders.where(user_id: user.id)after_param = params[:after].presence || 3.months.ago.iso8601diff --git a/app/views/users/bookmarks.ics.erb b/app/views/users/bookmarks.ics.erbindex f28cece62d1..53862fe5478 100644--- a/app/views/users/bookmarks.ics.erb+++ b/app/views/users/bookmarks.ics.erb@@ -1,6 +1,7 @@BEGIN:VCALENDARVERSION:2.0PRODID:-//Discourse//<%= Discourse.current_hostname %>//<%= Discourse.full_version %>//EN+X-WR-CALNAME:<%= IcalEncoder.encode(@calendar_name) %><% @bookmark_reminders.each do |bookmark| %>BEGIN:VEVENTUID:bookmark_reminder_#<%= bookmark.id %>@<%= Discourse.current_hostname %>diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex f5fdbe79f97..59b0679b603 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1253,6 +1253,7 @@ en:calendar_subscriptions:application_name: "Calendar Subscriptions"+ bookmarks_feed_name: "%{site_title} - Bookmark reminders"user_api_key:title: 'Authorize "%{application_name}"'diff --git a/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb b/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rbindex ec78d0d5f43..c108e121a8b 100644--- a/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb+++ b/plugins/discourse-calendar/app/controllers/discourse_post_event/events_controller.rb@@ -23,6 +23,8 @@ module DiscoursePostEventrespond_to do |format|format.ics do+ @calendar_name = calendar_name_for_ics+after_time = filtered_events_params[:after]&.to_datetime || Time.currentbefore_time = filtered_events_params[:before]&.to_datetime || 1.year.from_now@@ -212,5 +214,20 @@ module DiscoursePostEventtime.in_time_zone(event.timezone).iso8601(3)endend++ def calendar_name_for_ics+ translation_key =+ if filtered_events_params[:attending_user].present? &&+ current_user&.username_lower == filtered_events_params[:attending_user].downcase+ "my_events_feed_name"+ else+ "all_events_feed_name"+ end++ I18n.t(+ "discourse_calendar.calendar_subscriptions.#{translation_key}",+ site_title: SiteSetting.title,+ )+ endendenddiff --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.erbindex 495afce6a1a..9ff3896023c 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,6 +1,7 @@BEGIN:VCALENDARVERSION:2.0PRODID:-//Discourse//<%= Discourse.current_hostname %>//<%= Discourse.full_version %>//EN+X-WR-CALNAME:<%= IcalEncoder.encode(@calendar_name) %><%- @ics_events.each do |entry| -%><%- event = entry[:event] -%><%- starts_at = entry[:starts_at] -%>diff --git a/plugins/discourse-calendar/config/locales/server.en.yml b/plugins/discourse-calendar/config/locales/server.en.ymlindex 9fb92445942..c76524d8c45 100644--- a/plugins/discourse-calendar/config/locales/server.en.yml+++ b/plugins/discourse-calendar/config/locales/server.en.yml@@ -65,6 +65,9 @@ en:calendar_first_day_of_week: "Set the first day of the week for calendar display. Options are Saturday, Sunday, or Monday."discourse_calendar:+ calendar_subscriptions:+ all_events_feed_name: "%{site_title} - All events"+ my_events_feed_name: "%{site_title} - My events"invite_user_notification: "%{username} invited you to: %{description}"calendar_must_be_in_first_post: "Calendar tag can only be used in first post of a topic."more_than_one_calendar: "You can’t have more than one calendar in a post."diff --git a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb b/plugins/discourse-calendar/spec/requests/events_controller_spec.rbindex 22b00c16256..93246f71b30 100644--- a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb+++ b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb@@ -75,8 +75,14 @@ module DiscoursePostEvent)body = response.body+ calendar_name =+ I18n.t(+ "discourse_calendar.calendar_subscriptions.all_events_feed_name",+ site_title: SiteSetting.title,+ )expect(body).to include("BEGIN:VCALENDAR")expect(body).to include("END:VCALENDAR")+ expect(body).to include("X-WR-CALNAME:#{IcalEncoder.encode(calendar_name)}")expect(body).to include("BEGIN:VEVENT")expect(body).to include("END:VEVENT")expect(body).to include("SUMMARY:Test Event 1")@@ -267,6 +273,12 @@ module DiscoursePostEventparams: events_params.merge(user_api_key: user_api_key.key)expect(response.status).to eq(200)+ calendar_name =+ I18n.t(+ "discourse_calendar.calendar_subscriptions.my_events_feed_name",+ site_title: SiteSetting.title,+ )+ expect(response.body).to include("X-WR-CALNAME:#{IcalEncoder.encode(calendar_name)}")expect(response.body).to include("SUMMARY:Going Event")expect(response.body).to include("SUMMARY:Interested Event")enddiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex d25dd21fe0b..b313eb4ad3a 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -7333,10 +7333,13 @@ RSpec.describe UsersController dosign_in(user1)get "/u/#{user1.username}/bookmarks.ics"expect(response.status).to eq(200)+ calendar_name =+ I18n.t("calendar_subscriptions.bookmarks_feed_name", site_title: SiteSetting.title)expect(response.body).to eq(<<~ICS)BEGIN:VCALENDARVERSION:2.0PRODID:-//Discourse//#{Discourse.current_hostname}//#{Discourse.full_version}//EN+ X-WR-CALNAME:#{IcalEncoder.encode(calendar_name)}BEGIN:VEVENTUID:bookmark_reminder_##{bookmark1.id}@#{Discourse.current_hostname}DTSTAMP:#{bookmark1.updated_at.strftime(I18n.t("datetime_formats.formats.calendar_ics"))}