A platform for community discussion. Free, open, simple.
FIX: correct bulk invite expire time for DST (#23073)
marstall0dd1ee2e092d
diff --git a/app/models/invite.rb b/app/models/invite.rbindex 191da0818ca..213bb6a99ae 100644--- a/app/models/invite.rb+++ b/app/models/invite.rb@@ -134,7 +134,7 @@ class Invite < ActiveRecord::Basedef self.generate(invited_by, opts = nil)opts ||= {}-+ time_zone = Time.find_zone(invited_by&.user_option&.timezone) || Time.zoneemail = Email.downcase(opts[:email]) if opts[:email].present?raise UserExists.new(new.user_exists_error_msg(email)) if find_user_by_email(email)@@ -170,7 +170,7 @@ class Invite < ActiveRecord::Baseinvite.update_columns(created_at: Time.zone.now,updated_at: Time.zone.now,- expires_at: opts[:expires_at] || SiteSetting.invite_expiry_days.days.from_now,+ expires_at: opts[:expires_at] || time_zone.now + SiteSetting.invite_expiry_days.days,emailed_status: emailed_status,)else@@ -179,7 +179,8 @@ class Invite < ActiveRecord::Basecreate_args[:invited_by] = invited_bycreate_args[:email] = emailcreate_args[:emailed_status] = emailed_status- create_args[:expires_at] = opts[:expires_at] || SiteSetting.invite_expiry_days.days.from_now+ create_args[:expires_at] = opts[:expires_at] ||+ time_zone.now + SiteSetting.invite_expiry_days.daysinvite = Invite.create!(create_args)enddiff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rbindex ffbc5a9f4d3..9c7500287ca 100644--- a/spec/fabricators/user_fabricator.rb+++ b/spec/fabricators/user_fabricator.rb@@ -134,3 +134,11 @@ Fabricator(:bot, from: :user) do[(min_id || 0) - 1, -10].minendend++Fabricator(:east_coast_user, from: :user) do+ email "[email protected]"+ after_create do |user|+ user.user_option = UserOption.new(timezone: "Eastern Time (US & Canada)")+ user.save+ end+enddiff --git a/spec/jobs/bulk_invite_spec.rb b/spec/jobs/bulk_invite_spec.rbindex 3a8d370ab7e..b4233c12659 100644--- a/spec/jobs/bulk_invite_spec.rb+++ b/spec/jobs/bulk_invite_spec.rb@@ -4,6 +4,7 @@ RSpec.describe Jobs::BulkInvite dodescribe "#execute" dofab!(:user) { Fabricate(:user) }fab!(:admin) { Fabricate(:admin) }+ fab!(:east_coast_user) { Fabricate(:east_coast_user) }fab!(:group1) { Fabricate(:group, name: "group1") }fab!(:group2) { Fabricate(:group, name: "group2") }fab!(:topic) { Fabricate(:topic) }@@ -51,6 +52,18 @@ RSpec.describe Jobs::BulkInvite doexpect(post.raw).to include("1 error")end+ it "handles daylight savings time correctly" do+ # EDT (-04:00) transitions to EST (-05:00) on the first Sunday in November.+ # Freeze time to the last Day of October, so that the creation and expiration date will be in different time zones.++ Time.use_zone("Eastern Time (US & Canada)") do+ freeze_time DateTime.parse("2023-10-31 06:00:00 -0400")+ described_class.new.execute(current_user_id: east_coast_user.id, invites: invites)+ invite = Invite.first+ expect(invite.expires_at.hour).to equal(6)+ end+ end+it "does not create invited groups for automatic groups" dogroup2.update!(automatic: true)