Browse Source

Use reconfirmable template only if not confirmed

pull/1820/head
Jack S 3 years ago
parent
commit
fff578134b
  1. 2
      app/models/user.rb
  2. 7
      app/views/users/show.html.erb
  3. 2
      spec/features/user_spec.rb
  4. 24
      spec/mailers/resend_invitation_mailer_spec.rb

2
app/models/user.rb

@ -133,7 +133,7 @@ class User < ApplicationRecord
USER_REACTIVATED_TEMPLATE_ID
elsif was_migrated_from_softwire? && last_sign_in_at.blank?
BETA_ONBOARDING_TEMPLATE_ID
elsif initial_confirmation_sent
elsif initial_confirmation_sent && !confirmed?
RECONFIRMABLE_TEMPLATE_ID
else
CONFIRMABLE_TEMPLATE_ID

7
app/views/users/show.html.erb

@ -111,12 +111,11 @@
<%= govuk_button_to "Resend invite link", resend_invite_user_path(@user), secondary: true %>
<% end %>
<% else %>
<span class="app-!-colour-muted govuk-!-margin-right-2">
This user has been deactivated. <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %>
</span>
<span class="app-!-colour-muted govuk-!-margin-right-2">
This user has been deactivated. <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %>
</span>
<% end %>
<% end %>
</div>
</div>
</div>

2
spec/features/user_spec.rb

@ -529,7 +529,7 @@ RSpec.describe "User Features" do
end
before do
other_user.update!(initial_confirmation_sent: true)
other_user.update!(initial_confirmation_sent: true, confirmed_at: nil)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user)
visit(user_path(user.id))

24
spec/mailers/resend_invitation_mailer_spec.rb

@ -57,9 +57,31 @@ RSpec.describe ResendInvitationMailer do
end
it "sends a reinvitation" do
expect(notify_client).to receive(:send_email).with(email_address: "active_user@example.com", template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).to receive(:send_email).with(email_address: "active_user@example.com", template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(active_user)
end
end
context "with unconfirmed user after the initial invitation has been sent" do
let!(:unconfirmed_user) { create(:user, organisation:, confirmation_token: "dluch", initial_confirmation_sent: true, old_user_id: "234", sign_in_count: 0, confirmed_at: nil) }
let(:personalisation) do
{
name: unconfirmed_user.name,
email: unconfirmed_user.email,
organisation: unconfirmed_user.organisation.name,
link: include("/account/confirmation?confirmation_token=#{unconfirmed_user.confirmation_token}"),
}
end
before do
LegacyUser.destroy_all
end
it "sends a reinvitation" do
expect(notify_client).to receive(:send_email).with(email_address: unconfirmed_user.email, template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(unconfirmed_user)
end
end
end
end

Loading…
Cancel
Save