Skip to content

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

FIX: removes support for include_expired param (#34582)

Joffrey JAFFEUX249ae0009ac2
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.rb
index 62710031b4f..5a5bf64c507 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
@@ -120,7 +120,6 @@ module DiscoursePostEvent
:post_id,
:category_id,
:include_subcategories,
- :include_expired,
:limit,
:before,
:attending_user,
diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
index 61ee47399b2..1d80c05ebcb 100644
--- a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
@@ -78,7 +78,7 @@ module DiscoursePostEvent
def set_topic_bump
date = nil
- return if reminders.blank?
+ return if reminders.blank? || starts_at.nil?
reminders
.split(",")
.each do |reminder|
@@ -97,20 +97,37 @@ module DiscoursePostEvent
end
def expired?
+ if recurring?
+ return false if recurrence_until.nil?
+ return Time.current > recurrence_until
+ end
+
+ return true if starts_at.nil?
(ends_at || starts_at.end_of_day) <= Time.now
end
def starts_at
- event_dates.pending.order(:starts_at).last&.starts_at ||
- event_dates.order(:updated_at, :id).last&.starts_at
+ return nil if recurring? && recurrence_until.present? && recurrence_until < Time.current
+
+ from_event_dates =
+ event_dates.pending.order(:starts_at).last&.starts_at ||
+ event_dates.order(:updated_at, :id).last&.starts_at
+
+ from_event_dates || original_starts_at
end
def ends_at
- event_dates.pending.order(:starts_at).last&.ends_at ||
- event_dates.order(:updated_at, :id).last&.ends_at
+ return nil if recurring? && recurrence_until.present? && recurrence_until < Time.current
+
+ from_event_dates =
+ event_dates.pending.order(:starts_at).last&.ends_at ||
+ event_dates.order(:updated_at, :id).last&.ends_at
+
+ from_event_dates || original_ends_at
end
def on_going_event_invitees
+ return [] if self.starts_at.nil? # Can't determine ongoing status without start time
return [] if !self.ends_at && self.starts_at < Time.now
if self.ends_at
@@ -194,7 +211,7 @@ module DiscoursePostEvent
end
def create_notification!(user, post, predefined_attendance: false)
- return if post.event.starts_at < Time.current
+ return if post.event.starts_at.nil? || post.event.starts_at < Time.current
message =
if predefined_attendance
@@ -220,7 +237,7 @@ module DiscoursePostEvent
end
def ongoing?
- return false if self.closed || self.expired?
+ return false if self.closed || self.expired? || self.starts_at.nil?
finishes_at = self.ends_at || self.starts_at.end_of_day
(self.starts_at..finishes_at).cover?(Time.now)
end
diff --git a/plugins/discourse-calendar/app/serializers/discourse_post_event/basic_event_serializer.rb b/plugins/discourse-calendar/app/serializers/discourse_post_event/basic_event_serializer.rb
index c08f8cf7c67..f6ce7fbdec4 100644
--- a/plugins/discourse-calendar/app/serializers/discourse_post_event/basic_event_serializer.rb
+++ b/plugins/discourse-calendar/app/serializers/discourse_post_event/basic_event_serializer.rb
@@ -37,13 +37,16 @@ module DiscoursePostEvent
def rrule
return nil unless include_rrule?
- # Use UTC for RRULE to avoid timezone compatibility issues with FullCalendar
+ # Use the original event time (same as the frontend display) for rrule generation
+ timezone_starts_at = object.original_starts_at.in_time_zone(object.timezone)
+ timezone_recurrence_until = object.recurrence_until&.in_time_zone(object.timezone)
+
RRuleGenerator.generate_string(
- starts_at: object.original_starts_at,
- timezone: "UTC",
+ starts_at: timezone_starts_at,
+ timezone: object.timezone,
recurrence: object.recurrence,
- recurrence_until: object.recurrence_until,
- dtstart: object.original_starts_at,
+ recurrence_until: timezone_recurrence_until,
+ dtstart: timezone_starts_at,
)
end
@@ -51,30 +54,22 @@ module DiscoursePostEvent
# For recurring events, use UTC to match RRULE
# For non-recurring events, use the event's timezone
if object.recurring?
- object.original_starts_at
+ object.original_starts_at&.in_time_zone(object.timezone)
else
- object.starts_at.in_time_zone(object.timezone)
+ object.starts_at&.in_time_zone(object.timezone)
end
end
def ends_at
- if object.ends_at
- if object.recurring?
- object.ends_at
- else
- object.ends_at.in_time_zone(object.timezone)
- end
- else
- # Use consistent timezone as starts_at for calculation
- base_starts_at =
+ if object.recurring?
+ object.original_ends_at&.in_time_zone(object.timezone) ||
(
- if object.recurring?
- object.original_starts_at
- else
- object.starts_at.in_time_zone(object.timezone)
- end
+ object.original_starts_at &&
+ object.original_starts_at.in_time_zone(object.timezone) + 1.hour
)
- (base_starts_at + 1.hour)
+ else
+ base_starts_at = object.starts_at&.in_time_zone(object.timezone)
+ base_starts_at ? (base_starts_at + 1.hour) : nil
end
end
end
diff --git a/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb b/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb
index eb50534619e..44c4f192468 100644
--- a/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb
+++ b/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb
@@ -156,7 +156,7 @@ module DiscoursePostEvent
end
def ends_at
- object.ends_at || object.starts_at + 1.hour
+ object.ends_at || (object.starts_at ? object.starts_at + 1.hour : nil)
end
end
end
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
index 5e6cc27697a..dbcfcaec323 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
@@ -26,10 +26,6 @@ export default class CategoryCalendar extends Component {
include_subcategories: true,
};
- if (this.siteSettings.include_expired_events_on_calendar) {
- params.include_expired = true;
- }
-
return await this.discoursePostEventApi.events(params);
} catch (error) {
popupAjaxError(error);
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/dates.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
index 85107a9a8fd..5248a9f653e 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/dates.gjs
@@ -122,6 +122,10 @@ export default class DiscoursePostEventDates extends Component {
@action
async computeDates(element) {
+ if (this.args.expiredAndRecurring) {
+ return;
+ }
+
if (this.siteSettings.discourse_local_dates_enabled) {
const result = await cook(this.datesBBCode.join("<span> → </span>"));
this.htmlDates = htmlSafe(result.toString());
@@ -155,6 +159,12 @@ export default class DiscoursePostEventDates extends Component {
class="event__section event-dates"
{{didInsert this.computeDates}}
>
- {{icon "clock"}}{{this.htmlDates}}</section>
+ {{icon "clock"}}
+ {{#if @expiredAndRecurring}}
+ -
+ {{else}}
+ {{this.htmlDates}}
+ {{/if}}
+ </section>
</template>
}
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs
index 1a22673b8bf..601954e63b7 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs
@@ -93,6 +93,10 @@ export default class DiscoursePostEvent extends Component {
return this.event.watchingInvitee?.status;
}
+ get expiredAndRecurring() {
+ return this.event.isExpired && this.event.recurrence;
+ }
+
@bind
async loadEvent() {
if (this.event) {
@@ -118,8 +122,20 @@ export default class DiscoursePostEvent extends Component {
{{#if event}}
<header class="event-header" {{this.setupMessageBus}}>
<div class="event-date">
- <div class="month">{{this.startsAtMonth}}</div>
- <div class="day">{{this.startsAtDay}}</div>
+ <div class="month">
+ {{#if this.expiredAndRecurring}}
+ -
+ {{else}}
+ {{this.startsAtMonth}}
+ {{/if}}
+ </div>
+ <div class="day">
+ {{#if this.expiredAndRecurring}}
+ -
+ {{else}}
+ {{this.startsAtDay}}
+ {{/if}}
+ </div>
</div>
<div class="event-info">
<span class="name">
@@ -174,13 +190,20 @@ export default class DiscoursePostEvent extends Component {
Description description=event.description
)
Location=(component Location location=event.location)
- Dates=(component Dates event=event)
+ Dates=(component
+ Dates
+ event=event
+ expiredAndRecurring=this.expiredAndRecurring
+ )
Invitees=(component Invitees event=event)
Status=(component Status event=event)
ChatChannel=(component ChatChannel event=event)
}}
>
- <Dates @event={{event}} />
+ <Dates
+ @event={{event}}
+ @expiredAndRecurring={{this.expiredAndRecurring}}
+ />
<Location @location={{event.location}} />
<Url @url={{event.url}} />
<ChatChannel @event={{event}} />
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
index cc25ffa2f67..520d283f4d3 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs
@@ -144,12 +144,11 @@ export default class UpcomingEventsCalendar extends Component {
const currentYear = parseInt(currentParams.year, 10);
const currentMonth = parseInt(currentParams.month, 10);
const currentDay = parseInt(currentParams.day, 10);
-
const isViewChanged = currentParams.view !== view;
- // For view changes, always preserve the current URL parameters
if (isViewChanged) {
this._isViewChanging = true;
+
this.router.replaceWith(
this.router.currentRouteName,
view,
@@ -160,17 +159,12 @@ export default class UpcomingEventsCalendar extends Component {
return;
}
- // Skip navigation logic immediately after a view change
if (this._isViewChanging) {
this._isViewChanging = false;
return;
}
- const {
- year: urlYear,
- month: urlMonth,
- day: urlDay,
- } = this.#calculateUrlParams(
+ const calculatedParams = this.#calculateUrlParams(
view,
info.view,
currentYear,
@@ -179,6 +173,8 @@ export default class UpcomingEventsCalendar extends Component {
isViewChanged
);
+ const { year: urlYear, month: urlMonth, day: urlDay } = calculatedParams;
+
const isMonthChanged =
view === "month" &&
(currentYear !== urlYear || currentMonth !== urlMonth);
@@ -194,7 +190,9 @@ export default class UpcomingEventsCalendar extends Component {
return;
}
- if (isViewChanged || isMonthChanged || isDayChanged) {
+ const shouldNavigate = isViewChanged || isMonthChanged || isDayChanged;
+
+ if (shouldNavigate) {
this.router.replaceWith(
this.router.currentRouteName,
view,
@@ -217,55 +215,59 @@ export default class UpcomingEventsCalendar extends Component {
const viewEnd = moment(calendarView.currentEnd);
const currentParams = this.router.currentRoute.params;
- // For view changes, preserve the current date from URL
if (isViewChanged) {
- return {
+ const result = {
year: currentYear,
month: currentMonth,
day: parseInt(currentParams.day, 10),
};
+ return result;
}
if (view === "month") {
- const startYear = viewStart.year();
- const startMonth = viewStart.month() + 1;
-
- if (
- this.#isSequentialMonthNavigation(
- currentYear,
- currentMonth,
- startYear,
- startMonth
- )
- ) {
+ const viewMiddleForMonth = moment(
+ (viewStart.valueOf() + viewEnd.valueOf()) / 2
+ );
+ const startYear = viewMiddleForMonth.year();
+ const startMonth = viewMiddleForMonth.month() + 1;
+ const isSequential = this.#isSequentialMonthNavigation(
+ currentYear,
+ currentMonth,
+ startYear,
+ startMonth
+ );
+ const isTodayNav = this.#isTodayNavigation(
+ currentParams,
+ startYear,
+ startMonth
+ );
+
+ if (isSequential) {
return { year: startYear, month: startMonth, day: 1 };
- } else if (
- this.#isTodayNavigation(currentParams, startYear, startMonth)
- ) {
- return { year: startYear, month: startMonth, day: moment().date() };
+ } else if (isTodayNav) {
+ return {
+ year: startYear,
+ month: startMonth,
+ day: moment().date(),
+ };
} else {
- const viewMiddle = moment(
- (viewStart.valueOf() + viewEnd.valueOf()) / 2
- );
return {
- year: viewMiddle.year(),
- month: viewMiddle.month() + 1,
- day: viewMiddle.date(),
+ year: viewMiddleForMonth.year(),
+ month: viewMiddleForMonth.month() + 1,
+ day: viewMiddleForMonth.date(),
};
}
} else {
- // For view changes, preserve the current date from URL
- if (isViewChanged) {
- return {
- year: currentYear,
- month: currentMonth,
- day: currentDay,
- };
+ let viewDate;
+ if (view === "week") {
+ const utcDate = moment(viewStart).utc().add(1, "day");
+ const actualWeekStart = moment(utcDate.format("YYYY-MM-DD"));
+ viewDate = actualWeekStart.startOf("isoWeek");
+ } else {
+ const utcDate = moment(viewStart).utc().add(1, "day");
+ viewDate = moment(utcDate.format("YYYY-MM-DD"));
}
- // For navigation (next/prev/today), calculate based on the calendar view's current date
- const viewDate = moment(calendarView.currentStart);
-
return {
year: viewDate.year(),
month: viewDate.month() + 1,
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/services/discourse-post-event-service.js b/plugins/discourse-calendar/assets/javascripts/discourse/services/discourse-post-event-service.js
index 8199e6973b7..7218b96ec69 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/services/discourse-post-event-service.js
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/services/discourse-post-event-service.js
@@ -5,10 +5,6 @@ export default class DiscoursePostEventService extends Service {
@service discoursePostEventApi;
async fetchEvents(params = {}) {
- if (this.siteSettings.include_expired_events_on_calendar) {
- params.include_expired = true;
- }
-
const events = await this.discoursePostEventApi.events(params);
return await events;
}
diff --git a/plugins/discourse-calendar/config/locales/server.en.yml b/plugins/discourse-calendar/config/locales/server.en.yml
index ab870efba3d..effad75473b 100644
--- a/plugins/discourse-calendar/config/locales/server.en.yml
+++ b/plugins/discourse-calendar/config/locales/server.en.yml
@@ -57,7 +57,7 @@ en:
calendar_automatic_holidays_enabled: "Automatically set holiday status based on a users region (note: you can disable specific automatic holidays in plugin settings)"
event_participation_buttons: "List of event participation buttons users can use."
sidebar_show_upcoming_events: "Show upcoming events link in the sidebar under 'More'."
- include_expired_events_on_calendar: "Include past/expired events on Category Calendar and Upcoming Events views."
+
discourse_calendar:
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."
diff --git a/plugins/discourse-calendar/config/settings.yml b/plugins/discourse-calendar/config/settings.yml
index 7f17e4da807..36e5c5151b7 100644
--- a/plugins/discourse-calendar/config/settings.yml
+++ b/plugins/discourse-calendar/config/settings.yml
@@ -113,6 +113,3 @@ discourse_calendar:
client: true
default: ""
json_schema: DiscourseCalendar::SiteSettings::MapEventsTitleJsonSchema
- include_expired_events_on_calendar:
- default: false
- client: true
diff --git a/plugins/discourse-calendar/db/migrate/20250819123418_remove_include_expired_site_setting.rb b/plugins/discourse-calendar/db/migrate/20250819123418_remove_include_expired_site_setting.rb
new file mode 100644
index 00000000000..5cd9bdb9b49
--- /dev/null
+++ b/plugins/discourse-calendar/db/migrate/20250819123418_remove_include_expired_site_setting.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class RemoveIncludeExpiredSiteSetting < ActiveRecord::Migration[8.0]
+ def up
+ execute "DELETE FROM site_settings WHERE name = 'include_expired_events_on_calendar'"
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/discourse-calendar/jobs/regular/discourse_post_event/send_reminder.rb b/plugins/discourse-calendar/jobs/regular/discourse_post_event/send_reminder.rb
index a0774efccdf..553db37162c 100644
--- a/plugins/discourse-calendar/jobs/regular/discourse_post_event/send_reminder.rb
+++ b/plugins/discourse-calendar/jobs/regular/discourse_post_event/send_reminder.rb
@@ -29,7 +29,20 @@ module Jobs
post_number: 1,
)
- event_started = Time.now > event.starts_at
+ return if event.starts_at.nil?
+
+ # Convert both times to UTC for proper comparison
+ current_time = Time.current
+ event_start_time =
+ (
+ if event.starts_at.is_a?(ActiveSupport::TimeWithZone)
+ event.starts_at
+ else
+ event.starts_at.in_time_zone(event.timezone || "UTC")
+ end
+ )
+
+ event_started = current_time > event_start_time
# we remove users who have been visiting the topic since event started
if event_started
@@ -40,7 +53,7 @@ module Jobs
.where(
"topic_users.topic_id = ? AND topic_users.last_visited_at >= ? AND topic_users.last_read_post_number >= ?",
event.post.topic_id,
- event.starts_at,
+ event_start_time,
1,
)
.pluck(:user_id)
@@ -50,7 +63,15 @@ module Jobs
invitees = invitees.where.not(user_id: already_notified_users.pluck(:user_id))
end
- event_ended = event.ends_at && Time.now > event.ends_at
+ event_end_time =
+ (
+ if event.ends_at.is_a?(ActiveSupport::TimeWithZone)
+ event.ends_at
+ else
+ event.ends_at&.in_time_zone(event.timezone || "UTC")
+ end
+ )
+ event_ended = event_end_time && current_time > event_end_time
prefix = "before"
if event_ended
prefix = "after"
diff --git a/plugins/discourse-calendar/lib/discourse_post_event/event_finder.rb b/plugins/discourse-calendar/lib/discourse_post_event/event_finder.rb
index b5c283c48d9..0419ff7f2f3 100644
--- a/plugins/discourse-calendar/lib/discourse_post_event/event_finder.rb
+++ b/plugins/discourse-calendar/lib/discourse_post_event/event_finder.rb
@@ -6,9 +6,10 @@ module DiscoursePostEvent
guardian = Guardian.new(user)
build_base_query(guardian, user)
- .then { |query| apply_filters(query, params, guardian, user) }
- .then { |query| apply_date_filters(query, params) }
- .then { |query| apply_category_filters(query, params) }
+ .then { |query| filter_by_post_id(query, params) }
+ .then { |query| filter_by_attending_user(query, params, guardian, user) }
+ .then { |query| filter_by_dates(query, params) }
+ .then { |query| filter_by_category(query, params) }
.then { |query| apply_ordering(query) }
.then { |query| apply_limit(query, params) }
end
@@ -26,7 +27,9 @@ module DiscoursePostEvent
.merge(topics.or(pms))
.joins(latest_event_date_join)
.select("discourse_post_event_events.*, latest_event_dates.starts_at")
- .where("latest_event_dates.starts_at IS NOT NULL")
+ .where(
+ "(discourse_post_event_events.recurrence IS NOT NULL) OR (latest_event_dates.starts_at IS NOT NULL)",
+ )
.distinct
end
@@ -43,18 +46,6 @@ module DiscoursePostEvent
SQL
end
- def self.apply_filters(events, params, guardian, user)
- events
- .then { |query| filter_by_expiration(query, params) }
- .then { |query| filter_by_post_id(query, params) }
- .then { |query| filter_by_attending_user(query, params, guardian, user) }
- end
-
- def self.filter_by_expiration(events, params)
- return events if params[:include_expired].to_s == "true"
- events.where("latest_event_dates.finished_at IS NULL")
- end
-
def self.filter_by_post_id(events, params)
return events if params[:post_id].blank?
events.where(id: params[:post_id])
@@ -83,50 +74,59 @@ module DiscoursePostEvent
# If no user, can only see non-private events
return events.where.not(status: private_status) if user.nil?
- events.where(<<~SQL, private_status, private_status, user.id)
- discourse_post_event_events.status != ? OR (
- discourse_post_event_events.status = ? AND EXISTS (
- SELECT 1 FROM discourse_post_event_invitees dpei
- WHERE dpei.post_id = discourse_post_event_events.id
- AND dpei.user_id = ?
- )
- )
-SQL
+ # User can see private events if they are invited to them
+ events.where(
+ "discourse_post_event_events.status != ? OR (discourse_post_event_events.status = ? AND EXISTS (SELECT 1 FROM discourse_post_event_invitees WHERE post_id = discourse_post_event_events.id AND user_id = ?))",
+ private_status,
+ private_status,
+ user.id,
+ )
end
- def self.apply_date_filters(events, params)
- events
- .then { |query| apply_before_date_filter(query, params) }
- .then { |query| apply_after_date_filter(query, params) }
- .then { |query| apply_end_date_filter(query, params) }
- end
+ def self.filter_by_dates(events, params)
+ return events if params[:before].blank? && params[:after].blank?
+
+ before_date = params[:before]&.to_datetime
+ after_date = params[:after]&.to_datetime
- def self.apply_before_date_filter(events, params)
- return events if params[:before].blank?
+ recurring_scope = build_recurring_date_scope(after_date, before_date)
+ non_recurring_scope = build_non_recurring_date_scope(after_date, before_date)
- before_date = params[:before].to_datetime
- events.where("discourse_post_event_events.original_starts_at < ?", before_date)
+ # Apply the combined scope using OR logic
+ events.merge(recurring_scope.or(non_recurring_scope))
end
- def self.apply_after_date_filter(events, params)
- return events if params[:after].blank?
+ private
- after_date = params[:after].to_datetime
- events.where(
- "(discourse_post_event_events.recurrence_until IS NULL OR " \
- "discourse_post_event_events.recurrence_until >= ?)",
- after_date,
- )
- end
+ def self.build_recurring_date_scope(after_date, before_date)
+ scope = DiscoursePostEvent::Event.where.not(recurrence: nil)
+
+ if after_date
+ # For recurring events: original start date OR recurrence_until should be >= after_date
+ scope =
+ scope.where(
+ "original_starts_at >= ? OR recurrence_until IS NULL OR recurrence_until >= ?",
+ after_date,
+ after_date,
+ )
+ end
- def self.apply_end_date_filter(events, params)
- return events if params[:end_date].blank?
+ if before_date
+ # For recurring events: original start date should be < before_date
+ scope = scope.where("original_starts_at < ?", before_date)
+ end
+
+ scope
+ end
- end_date = params[:end_date].to_datetime
- events.where("discourse_post_event_events.original_starts_at <= ?", end_date)
+ def self.build_non_recurring_date_scope(after_date, before_date)
+ scope = DiscoursePostEvent::Event.where(recurrence: nil)
+ scope = scope.where("latest_event_dates.starts_at >= ?", after_date) if after_date
+ scope = scope.where("latest_event_dates.starts_at < ?", before_date) if before_date
+ scope
end
- def self.apply_category_filters(events, params)
+ def self.filter_by_category(events, params)
return events if params[:category_id].blank?
category_id = params[:category_id].to_i
diff --git a/plugins/discourse-calendar/lib/discourse_post_event/rrule_configurator.rb b/plugins/discourse-calendar/lib/discourse_post_event/rrule_configurator.rb
index d6af74a66ac..ae5dfdd8f3f 100644
--- a/plugins/discourse-calendar/lib/discourse_post_event/rrule_configurator.rb
+++ b/plugins/discourse-calendar/lib/discourse_post_event/rrule_configurator.rb
@@ -29,7 +29,7 @@ class RRuleConfigurator
"FREQ=WEEKLY;BYDAY=#{byday}"
end
- rule += ";UNTIL=#{recurrence_until.strftime("%Y%m%dT%H%M%SZ")}" if recurrence_until
+ rule += ";UNTIL=#{recurrence_until.strftime("%Y%m%dT%H%M%S")}" if recurrence_until
rule
end
diff --git a/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb b/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
index 804762cd08f..da9395c2f3f 100644
--- a/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
+++ b/plugins/discourse-calendar/lib/discourse_post_event/rrule_generator.rb
@@ -15,7 +15,7 @@ class RRuleGenerator
rrule = set_mandatory_options(rrule, starts_at)
::RRule::Rule
- .new(stringify(rrule), dtstart: starts_at, tzid: timezone, dtstart:)
+ .new(stringify(rrule), dtstart: starts_at, tzid: timezone)
.between(Time.current, Time.current + 14.months)
.first(RRuleConfigurator.how_many_recurring_events(recurrence:, max_years:))
end
@@ -30,19 +30,14 @@ class RRuleGenerator
)
rrule = generate_hash(RRuleConfigurator.rule(recurrence_until:, recurrence:, starts_at:))
rrule = set_mandatory_options(rrule, starts_at)
+ rrule_line = "RRULE:#{stringify(rrule)}"
- # Format as multi-line RFC 5545 format for FullCalendar
- # Include timezone information in DTSTART to ensure proper interpretation
if dtstart
if timezone == "UTC"
dtstart_line = "DTSTART:#{dtstart.utc.strftime("%Y%m%dT%H%M%SZ")}"
else
dtstart_line = "DTSTART;TZID=#{timezone}:#{dtstart.strftime("%Y%m%dT%H%M%S")}"
end
- end
- rrule_line = "RRULE:#{stringify(rrule)}"
-
- if dtstart_line
"#{dtstart_line}\n#{rrule_line}"
else
rrule_line
@@ -65,6 +60,7 @@ class RRuleGenerator
end
def self.set_mandatory_options(rrule, time)
+ # Use local time for BYHOUR/BYMINUTE to match the timezone-specific DTSTART
rrule["BYHOUR"] = time.strftime("%H")
rrule["BYMINUTE"] = time.strftime("%M")
rrule["INTERVAL"] ||= 1
diff --git a/plugins/discourse-calendar/spec/jobs/export_post_event_report_csv_spec.rb b/plugins/discourse-calendar/spec/jobs/export_post_event_report_csv_spec.rb
index 0a51bede8c9..20f3f51a917 100644
--- a/plugins/discourse-calendar/spec/jobs/export_post_event_report_csv_spec.rb
+++ b/plugins/discourse-calendar/spec/jobs/export_post_event_report_csv_spec.rb
@@ -46,9 +46,9 @@ describe Jobs::ExportCsvFile do
),
)
- upload = system_message.first_post.uploads.first
+ upload = Upload.last
- expect(system_message.first_post.raw).to eq(
+ expect(system_message.first_post.raw).to include(
I18n.t(
"system_messages.csv_export_succeeded.text_body_template",
download_link:
diff --git a/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
index 0fd615ccd4f..8d2e2fe46cb 100644
--- a/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
+++ b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/send_reminder_spec.rb
@@ -277,5 +277,201 @@ describe Jobs::DiscoursePostEventSendReminder do
end
end
end
+
+ context "with recurring event" do
+ let!(:recurring_event) do
+ Fabricate(
+ :event,
+ post: post_1,
+ reminders: reminders,
+ original_starts_at: 3.hours.from_now,
+ original_ends_at: 4.hours.from_now,
+ recurrence: "every_day",
+ )
+ end
+
+ let(:expired_event) do
+ Fabricate(
+ :event,
+ post: Fabricate(:post),
+ reminders: reminders,
+ original_starts_at: 1.day.ago,
+ original_ends_at: 1.day.ago + 1.hour,
+ recurrence: "every_day",
+ recurrence_until: 1.hour.ago,
+ )
+ end
+
+ before do
+ setup_recurring_event_invitees
+ clear_notifications
+ end
+
+ def setup_recurring_event_invitees
+ DiscoursePostEvent::Invitee.create_attendance!(going_user.id, recurring_event.id, :going)
+ DiscoursePostEvent::Invitee.create_attendance!(
+ interested_user.id,
+ recurring_event.id,
+ :interested,
+ )
+ DiscoursePostEvent::Invitee.create_attendance!(
+ not_going_user.id,
+ recurring_event.id,
+ :not_going,
+ )
+ DiscoursePostEvent::Invitee.create_attendance!(
+ going_user_unread_notification.id,
+ recurring_event.id,
+ :going,
+ )
+ DiscoursePostEvent::Invitee.create_attendance!(
+ going_user_read_notification.id,
+ recurring_event.id,
+ :going,
+ )
+ DiscoursePostEvent::Invitee.create_attendance!(
+ visited_going_user.id,
+ recurring_event.id,
+ :going,
+ )
+ end
+
+ def clear_notifications
+ all_users.each { |user| user.notifications.delete_all }
+ going_user_unread_notification.notifications.create!(
+ notification_type: Notification.types[:event_reminder],
+ topic_id: post_1.topic_id,
+ post_number: 1,
+ data: {}.to_json,
+ )
+ end
+
+ def all_users
+ [
+ going_user,
+ interested_user,
+ not_going_user,
+ going_user_unread_notification,
+ going_user_read_notification,
+ visited_going_user,
+ ]
+ end
+
+ def send_reminder(event = recurring_event)
+ Jobs::DiscoursePostEventSendReminder.new.execute(event_id: event.id, reminder: reminders)
+ end
+
+ def advance_to_next_occurrence
+ freeze_time(recurring_event.original_starts_at + 1.day + 1.hour)
+ recurring_event.event_dates.pending.update_all(finished_at: Time.current - 1.hour)
+ recurring_event.set_next_date
+ end
+
+ it "sends reminders for the first occurrence" do
+ recurring_event.set_next_date
+
+ expect { send_reminder }.to change { going_user.reload.unread_notifications }.by(1)
+ end
+
+ it "sends reminders for subsequent occurrences" do
+ recurring_event.set_next_date
+ first_event_date = recurring_event.event_dates.pending.first
+
+ send_reminder
+ going_user.notifications.update_all(read: true)
+
+ advance_to_next_occurrence
+
+ next_event_date = recurring_event.event_dates.pending.first
+ expect(next_event_date).to be_present
+ expect(next_event_date.id).not_to eq(first_event_date.id)
+
+ expect { send_reminder }.to change { going_user.reload.unread_notifications }.by(1)
+ end
+
+ it "handles timezone-specific events" do
+ recurring_event.update!(timezone: "America/Los_Angeles")
+ recurring_event.set_next_date
+
+ expect { send_reminder }.to change { going_user.reload.unread_notifications }.by(1)
+
+ going_user.notifications.update_all(read: true)
+ advance_to_next_occurrence
+
+ expect { send_reminder }.to change { going_user.reload.unread_notifications }.by(1)
+ end
+
+ it "correctly determines event status across timezones" do
+ tokyo_timezone = "Asia/Tokyo"
+
+ tokyo_time = Time.current.in_time_zone(tokyo_timezone) + 30.minutes
+
+ timezone_event =
+ Fabricate(
+ :event,
+ post: Fabricate(:post),
+ reminders: "notification.15.minutes",
+ original_starts_at: tokyo_time.to_time,
+ original_ends_at: tokyo_time.to_time + 1.hour,
+ timezone: tokyo_timezone,
+ )
+
+ DiscoursePostEvent::Invitee.create_attendance!(going_user.id, timezone_event.id, :going)
+ going_user.notifications.delete_all
+
+ expect { send_reminder(timezone_event) }.to change {
+ going_user.reload.unread_notifications
+ }.by(1)
+
+ notification = going_user.notifications.last
+ expect(JSON.parse(notification.data)["message"]).to eq(
+ "discourse_post_event.notifications.before_event_reminder",
+ )
+ end
+
+ it "correctly identifies ongoing events in different timezones" do
+ la_timezone = "America/Los_Angeles"
+ la_time = Time.current.in_time_zone(la_timezone) - 30.minutes
+
+ ongoing_event =
+ Fabricate(
+ :event,
+ post: Fabricate(:post),
+ reminders: "notification.15.minutes",
+ original_starts_at: la_time.to_time,
+ original_ends_at: la_time.to_time + 2.hours,
+ timezone: la_timezone,
+ )
+
+ DiscoursePostEvent::Invitee.create_attendance!(going_user.id, ongoing_event.id, :going)
+ going_user.notifications.delete_all
+
+ expect { send_reminder(ongoing_event) }.to change {
+ going_user.reload.unread_notifications
+ }.by(1)
+
+ notification = going_user.notifications.last
+ expect(JSON.parse(notification.data)["message"]).to eq(
+ "discourse_post_event.notifications.ongoing_event_reminder",
+ )
+ end
+
+ it "prevents duplicate reminders for same occurrence" do
+ recurring_event.set_next_date
+
+ expect { send_reminder }.to change { going_user.reload.unread_notifications }.by(1)
+ expect { send_reminder }.not_to change { going_user.reload.unread_notifications }
+ end
+
+ it "handles expired recurring events" do
+ DiscoursePostEvent::Invitee.create_attendance!(going_user.id, expired_event.id, :going)
+
+ expect(expired_event.starts_at).to be_nil
+
+ expect { send_reminder(expired_event) }.not_to change {
+ going_user.reload.unread_notifications
+ }
+ end
+ end
end
end
diff --git a/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb b/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
index 33b409f88a8..375e50a88e1 100644
--- a/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
+++ b/plugins/discourse-calendar/spec/lib/discourse_post_event/event_finder_spec.rb
@@ -142,111 +142,99 @@ describe DiscoursePostEvent::EventFinder do
end
end
- describe "by expiration status" do
- let!(:old_event) do
- Fabricate(
- :event,
- name: "old_event",
- original_starts_at: 2.hours.ago,
- original_ends_at: 1.hour.ago,
- )
+ describe "with a limit parameter provided" do
+ let!(:event1) { Fabricate(:event) }
+ let!(:event2) { Fabricate(:event) }
+ let!(:event3) { Fabricate(:event) }
+
+ it "returns the correct number of events" do
+ expect(finder.search(current_user, { limit: 2 })).to match_array([event1, event2])
end
- let!(:future_event) do
- Fabricate(
- :event,
- name: "future_event",
- original_starts_at: 1.hour.from_now,
- original_ends_at: 2.hours.from_now,
+ end
+
+ describe "with a before parameter provided" do
+ let!(:event1) { Fabricate(:event, original_starts_at: 2.minutes.from_now) }
+ let!(:event2) { Fabricate(:event, original_starts_at: 1.minute.from_now) }
+ let!(:event3) { Fabricate(:event, original_starts_at: 2.hours.ago) }
+
+ it "returns the events started before the provided value" do
+ expect(finder.search(current_user, { before: event2.starts_at.to_s })).to match_array(
+ [event3],
)
end
- let!(:current_event) do
+ end
+
+ describe "recurring events date filtering" do
+ let!(:recurring_event_june) do
Fabricate(
:event,
- name: "current_event",
- original_starts_at: 5.minutes.ago,
- original_ends_at: 5.minutes.from_now,
+ original_starts_at: Time.parse("2024-06-15 10:00:00 UTC"),
+ recurrence: "every_week",
+ recurrence_until: Time.parse("2024-12-31 10:00:00 UTC"),
)
end
- let!(:older_event) do
+
+ let!(:recurring_event_endless) do
Fabricate(
:event,
- name: "older_event",
- original_starts_at: 4.hours.ago,
- original_ends_at: 3.hour.ago,
+ original_starts_at: Time.parse("2024-06-15 10:00:00 UTC"),
+ recurrence: "every_week",
+ recurrence_until: nil,
)
end
- it "returns correct events" do
- expect(finder.search(current_user, { include_expired: false })).to eq(
- [current_event, future_event],
- )
- expect(finder.search(current_user, { include_expired: true })).to eq(
- [older_event, old_event, current_event, future_event],
- )
+ let!(:non_recurring_event_august) do
+ Fabricate(:event, original_starts_at: Time.parse("2024-08-15 10:00:00 UTC"))
end
- context "when a past event has been edited to be in the future" do
- let!(:event_date) do
- Fabricate(
- :event_date,
- event: future_event,
- starts_at: 2.hours.ago,
- ends_at: 1.hour.ago,
- finished_at: 1.hour.ago,
- )
- end
-
- it "returns correct events" do
- expect(finder.search(current_user, { include_expired: false })).to eq(
- [current_event, future_event],
- )
- expect(finder.search(current_user, { include_expired: true })).to eq(
- [older_event, old_event, current_event, future_event],
- )
+ describe "filtering for August events" do
+ it "returns recurring events that start before August but recur until after August" do
+ results =
+ finder.search(
+ current_user,
+ {
+ after: Time.parse("2024-08-01 00:00:00 UTC").to_s,
+ before: Time.parse("2024-08-31 23:59:59 UTC").to_s,
+ },
+ )
+
+ expect(results).to include(recurring_event_june)
+ expect(results).to include(non_recurring_event_august)
+ expect(results).to include(recurring_event_endless)
end
end
- context "when a future event has been edited to be in the past" do
- let!(:event_date) do
- Fabricate(
- :event_date,
- event: old_event,
- starts_at: 1.hour.from_now,
- ends_at: 2.hours.from_now,
- finished_at: 1.hour.ago,
- )
- end
-
- it "returns correct events" do
- expect(finder.search(current_user, { include_expired: false })).to eq(
- [current_event, future_event],
- )
- expect(finder.search(current_user, { include_expired: true })).to eq(
- [older_event, current_event, future_event, old_event],
- )
+ describe "filtering for January next year events" do
+ it "returns only endless recurring events and events that recur until after January" do
+ results =
+ finder.search(
+ current_user,
+ {
+ after: Time.parse("2025-01-01 00:00:00 UTC").to_s,
+ before: Time.parse("2025-01-31 23:59:59 UTC").to_s,
+ },
+ )
+
+ expect(results).not_to include(recurring_event_june)
+ expect(results).to include(recurring_event_endless)
+ expect(results).not_to include(non_recurring_event_august)
end
end
end
- describe "with a limit parameter provided" do
- let!(:event1) { Fabricate(:event) }
- let!(:event2) { Fabricate(:event) }
- let!(:event3) { Fabricate(:event) }
-
- it "returns the correct number of events" do
- expect(finder.search(current_user, { limit: 2 })).to match_array([event1, event2])
+ describe "expired events" do
+ let!(:expired_event) do
+ Fabricate(:event, original_starts_at: 2.hours.ago, original_ends_at: 1.hour.ago)
end
- end
- describe "with a before parameter provided" do
- let!(:event1) { Fabricate(:event, original_starts_at: 2.minutes.from_now) }
- let!(:event2) { Fabricate(:event, original_starts_at: 1.minute.from_now) }
- let!(:event3) { Fabricate(:event, original_starts_at: 2.hours.ago) }
+ let!(:current_event) do
+ Fabricate(:event, original_starts_at: 1.hour.from_now, original_ends_at: 2.hours.from_now)
+ end
- it "returns the events started before the provided value" do
- expect(finder.search(current_user, { before: event2.starts_at.to_s })).to match_array(
- [event3],
- )
+ it "returns both expired and current events" do
+ results = finder.search(current_user)
+ expect(results).to include(expired_event)
+ expect(results).to include(current_event)
end
end
end
diff --git a/plugins/discourse-calendar/spec/lib/discourse_post_event/rrule_configurator_spec.rb b/plugins/discourse-calendar/spec/lib/discourse_post_event/rrule_configurator_spec.rb
index de24744c047..e2dc3d35dff 100644
--- a/plugins/discourse-calendar/spec/lib/discourse_post_event/rrule_configurator_spec.rb
+++ b/plugins/discourse-calendar/spec/lib/discourse_post_event/rrule_configurator_spec.rb
@@ -78,7 +78,7 @@ describe RRuleConfigurator do
it "adds the UNTIL parameter to the rule" do
recurrence_until = Time.utc(2021, 8, 12, 16, 32)
rule = RRuleConfigurator.rule(recurrence: "every_day", starts_at: time, recurrence_until:)
- expect(rule).to eq("FREQ=DAILY;UNTIL=20210812T163200Z")
+ expect(rule).to eq("FREQ=DAILY;UNTIL=20210812T163200")
end
end
end
diff --git a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
index 1a79ef73595..490386bb715 100644
--- a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
+++ b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb
@@ -433,6 +433,71 @@ describe DiscoursePostEvent::Event do
end
end
end
+
+ context "with recurring events" do
+ context "with recurrence_until set" do
+ context "when current date is before recurrence_until" do
+ it "is not expired" do
+ post_event =
+ DiscoursePostEvent::Event.create!(
+ original_starts_at: DateTime.parse("2020-04-22 14:05"),
+ original_ends_at: DateTime.parse("2020-04-22 15:05"),
+ recurrence: "FREQ=WEEKLY",
+ recurrence_until: DateTime.parse("2020-05-01 00:00"),
+ post: first_post,
+ )
+
+ expect(post_event.expired?).to be(false)
+ end
+ end
+
+ context "when current date is after recurrence_until" do
+ it "is expired" do
+ post_event =
+ DiscoursePostEvent::Event.create!(
+ original_starts_at: DateTime.parse("2020-04-22 14:05"),
+ original_ends_at: DateTime.parse("2020-04-22 15:05"),
+ recurrence: "FREQ=WEEKLY",
+ recurrence_until: DateTime.parse("2020-04-23 00:00"),
+ post: first_post,
+ )
+
+ expect(post_event.expired?).to be(true)
+ end
+ end
+
+ context "when current date equals recurrence_until" do
+ it "is not expired" do
+ current_time = DateTime.parse("2020-04-24 14:10")
+ post_event =
+ DiscoursePostEvent::Event.create!(
+ original_starts_at: DateTime.parse("2020-04-22 14:05"),
+ original_ends_at: DateTime.parse("2020-04-22 15:05"),
+ recurrence: "FREQ=WEEKLY",
+ recurrence_until: current_time,
+ post: first_post,
+ )
+
+ expect(post_event.expired?).to be(false)
+ end
+ end
+ end
+
+ context "without recurrence_until set" do
+ it "never expires" do
+ post_event =
+ DiscoursePostEvent::Event.create!(
+ original_starts_at: DateTime.parse("2020-04-22 14:05"),
+ original_ends_at: DateTime.parse("2020-04-22 15:05"),
+ recurrence: "FREQ=WEEKLY",
+ recurrence_until: nil,
+ post: first_post,
+ )
+
+ expect(post_event.expired?).to be(false)
+ end
+ end
+ end
end
describe "#update_with_params!" do
@@ -534,4 +599,94 @@ describe DiscoursePostEvent::Event do
end
end
end
+
+ describe "#starts_at and #ends_at for expired recurring events" do
+ context "when recurring event has expired (past recurrence_until)" do
+ let(:expired_recurring_event) do
+ event =
+ Fabricate(
+ :event,
+ recurrence: "every_week",
+ recurrence_until: Time.current - 1.day,
+ original_starts_at: Time.current - 1.week,
+ original_ends_at: Time.current - 1.week + 2.hours,
+ )
+ event
+ end
+
+ it "returns nil for starts_at since no future dates can be computed" do
+ expect(expired_recurring_event.starts_at).to be_nil
+ end
+
+ it "returns nil for ends_at since no future dates can be computed" do
+ expect(expired_recurring_event.ends_at).to be_nil
+ end
+
+ it "serializer handles nil starts_at correctly" do
+ serializer =
+ DiscoursePostEvent::EventSerializer.new(
+ expired_recurring_event,
+ scope: Guardian.new,
+ root: false,
+ )
+ json = JSON.parse(serializer.to_json)
+ # Should not crash and should return nil for starts_at and ends_at
+ expect(json["starts_at"]).to be_nil
+ expect(json["ends_at"]).to be_nil
+ end
+
+ it "basic serializer handles expired recurring events correctly" do
+ serializer =
+ DiscoursePostEvent::BasicEventSerializer.new(expired_recurring_event, root: false)
+ json = JSON.parse(serializer.to_json)
+
+ expected_starts_at =
+ expired_recurring_event.original_starts_at.in_time_zone(expired_recurring_event.timezone)
+ expected_ends_at =
+ expired_recurring_event.original_ends_at.in_time_zone(expired_recurring_event.timezone)
+
+ expect(json["starts_at"]).to eq(expected_starts_at.iso8601(3))
+ expect(json["ends_at"]).to eq(expected_ends_at.iso8601(3))
+ end
+ end
+
+ context "when recurring event has no recurrence_until (endless)" do
+ let(:endless_recurring_event) do
+ Fabricate(
+ :event,
+ recurrence: "every_week",
+ recurrence_until: nil,
+ original_starts_at: Time.current - 1.week,
+ original_ends_at: Time.current - 1.week + 2.hours,
+ )
+ end
+
+ it "still returns starts_at from event_dates" do
+ expect(endless_recurring_event.starts_at).not_to be_nil
+ end
+
+ it "still returns ends_at from event_dates" do
+ expect(endless_recurring_event.starts_at).not_to be_nil
+ end
+ end
+
+ context "when non-recurring event" do
+ let(:non_recurring_event) do
+ Fabricate(
+ :event,
+ recurrence: nil,
+ original_starts_at: Time.current - 1.week,
+ original_ends_at: Time.current - 1.week + 2.hours,
+ )
+ end
+
+ it "still returns starts_at from event_dates regardless of when it was" do
+ expect(non_recurring_event.starts_at).not_to be_nil
+ end
+
+ it "still returns ends_at from event_dates regardless of when it was" do
+ expect(non_recurring_event.ends_at).not_to be_nil
+ end
+ end
+ end
end
diff --git a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
index c26b5172bde..5f69a08e406 100644
--- a/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
+++ b/plugins/discourse-calendar/spec/requests/events_controller_spec.rb
@@ -268,8 +268,10 @@ module DiscoursePostEvent
expect(response.status).to eq(200)
events = response.parsed_body["events"]
- expect(events.length).to eq(1)
- expect(events[0]["id"]).to eq(event_1.id)
+ expect(events.length).to eq(2) # Now includes expired event_3
+ event_ids = events.map { |e| e["id"] }
+ expect(event_ids).to include(event_1.id)
+ expect(event_ids).to include(event_3.id)
end
it "includes subcategory events when param provided" do
@@ -277,18 +279,7 @@ module DiscoursePostEvent
expect(response.status).to eq(200)
events = response.parsed_body["events"]
- expect(events.length).to eq(2)
- expect(events).to match_array(
- [hash_including("id" => event_1.id), hash_including("id" => event_2.id)],
- )
- end
-
- it "includes expired events when param provided" do
- get "/discourse-post-event/events.json?category_id=#{category.id}&include_subcategories=true&include_expired=true"
-
- expect(response.status).to eq(200)
- events = response.parsed_body["events"]
- expect(events.length).to eq(3)
+ expect(events.length).to eq(3) # Now includes expired event_3
expect(events).to match_array(
[
hash_including("id" => event_1.id),
@@ -304,11 +295,11 @@ module DiscoursePostEvent
expect(response.status).to eq(200)
events = response.parsed_body["events"]
expect(events.length).to eq(1)
- expect(events[0]["id"]).to eq(event_2.id)
+ expect(events[0]["id"]).to eq(event_3.id) # Expired event sorts first (NULL starts_at)
end
it "filters events before the provided datetime if before param provided" do
- get "/discourse-post-event/events.json?category_id=#{category.id}&include_subcategories=true&include_expired=true&before=#{event_2.starts_at}"
+ get "/discourse-post-event/events.json?category_id=#{category.id}&include_subcategories=true&before=#{event_2.starts_at}"
expect(response.status).to eq(200)
events = response.parsed_body["events"]
diff --git a/plugins/discourse-calendar/spec/serializers/topic_list_item_serializer_spec.rb b/plugins/discourse-calendar/spec/serializers/topic_list_item_serializer_spec.rb
index 19535c6208f..62909cc07ce 100644
--- a/plugins/discourse-calendar/spec/serializers/topic_list_item_serializer_spec.rb
+++ b/plugins/discourse-calendar/spec/serializers/topic_list_item_serializer_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe TopicListItemSerializer do
let(:parsed_json) { JSON.parse(serializer.to_json) }
before do
- freeze_time("2020-04-24 14:10")
+ freeze_time(Time.utc(2020, 4, 24, 14, 10))
Jobs.run_immediately!
SiteSetting.calendar_enabled = true
SiteSetting.discourse_post_event_enabled = true
diff --git a/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb b/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb
index a05d268adf3..00dad6ab444 100644
--- a/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb
+++ b/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe TopicViewSerializer do
let(:parsed_json) { JSON.parse(serializer.to_json) }
before do
- freeze_time("2020-04-24 14:10")
+ freeze_time(Time.utc(2020, 4, 24, 14, 10))
Jobs.run_immediately!
SiteSetting.calendar_enabled = true
SiteSetting.discourse_post_event_enabled = true
diff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rb
index 81e5f599b09..690dccf232e 100644
--- a/plugins/discourse-calendar/spec/system/post_event_spec.rb
+++ b/plugins/discourse-calendar/spec/system/post_event_spec.rb
@@ -191,6 +191,23 @@ describe "Post event", type: :system do
expect(page).to have_no_css(".send-pm-to-creator")
end
+ it "shows '-' for expired recurring events instead of dates" do
+ post =
+ PostCreator.create!(
+ admin,
+ title: "An expired recurring event",
+ raw:
+ "[event start='2024-01-01 10:00' recurrenceUntil='2025-07-31' recurrence='every_week']\n[/event]",
+ )
+
+ visit(post.topic.url)
+
+ expect(page).to have_css(".discourse-post-event")
+ expect(page).to have_css(".event-date .month", text: "-")
+ expect(page).to have_css(".event-date .day", text: "-")
+ expect(page).to have_css(".event-dates", text: "-")
+ end
+
it "persists changes" do
visit "/new-topic"
composer.fill_title("Test event with updates")