From 43557143fe0c29fbbf8931d85db284a9c5eecdb0 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Mon, 26 Oct 2020 12:26:43 +0200 Subject: [PATCH] FIX: Reset invite when resending it (#11013) Resending an invite moved the expire date in the future, but did not invalidate it. For example, if an invite was sent to an email, invalidated and then resent, it would still be left invalidated. --- app/models/invite.rb | 2 +- spec/models/invite_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/invite.rb b/app/models/invite.rb index a7340ae3010..260a79aecac 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -313,7 +313,7 @@ class Invite < ActiveRecord::Base end def resend_invite - self.update_columns(updated_at: Time.zone.now, expires_at: SiteSetting.invite_expiry_days.days.from_now) + self.update_columns(updated_at: Time.zone.now, invalidated_at: nil, expires_at: SiteSetting.invite_expiry_days.days.from_now) Jobs.enqueue(:invite_email, invite_id: self.id) end diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index fc81d4d8d3f..82225cb8767 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -164,10 +164,11 @@ describe Invite do it 'resets expiry of a resent invite' do SiteSetting.invite_expiry_days = 2 - invite.update!(expires_at: 10.days.ago) + invite.update!(invalidated_at: 10.days.ago, expires_at: 10.days.ago) expect(invite).to be_expired invite.resend_invite + expect(invite.invalidated_at).to be_nil expect(invite).not_to be_expired end