From 57a576bd26d9ebbfcd8a28437e52c1a41a573dcf Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 27 May 2022 11:08:04 +0100 Subject: [PATCH] Don't trigger confirmation emails for inactive users --- app/models/user.rb | 6 ++++-- spec/models/user_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 97cc43c62..5eec7bed8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -90,8 +90,10 @@ class User < ApplicationRecord old_user_id.present? end - def skip_confirmation! - !active? + def send_confirmation_instructions + return unless active? + + super end def need_two_factor_authentication?(_request) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index df3f82911..646e65d2a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -85,6 +85,18 @@ RSpec.describe User, type: :model do ) end + it "does not send a confirmation email to inactive users" do + expect(DeviseNotifyMailer).not_to receive(:confirmation_instructions) + described_class.create!( + name: "unconfirmed_user", + email: "unconfirmed_user@example.com", + password: "password123", + organisation: other_organisation, + role: "data_provider", + active: false, + ) + end + context "when the user is a data provider" do it "cannot assign roles" do expect(user.assignable_roles).to eq({})