Browse Source

Remove feature flag for new email journey

pull/1835/head
Jack S 3 years ago
parent
commit
b6f13be12f
  1. 4
      app/controllers/users_controller.rb
  2. 12
      app/mailers/devise_notify_mailer.rb
  3. 4
      app/services/feature_toggle.rb
  4. 54
      spec/requests/users_controller_spec.rb

4
app/controllers/users_controller.rb

@ -53,7 +53,7 @@ class UsersController < ApplicationController
if @user == current_user if @user == current_user
bypass_sign_in @user bypass_sign_in @user
flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password") flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password")
if user_params.key?("email") && FeatureToggle.new_email_journey? if user_params.key?("email")
flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email) flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email)
end end
@ -66,7 +66,7 @@ class UsersController < ApplicationController
elsif user_params[:active] == "true" elsif user_params[:active] == "true"
@user.send_confirmation_instructions @user.send_confirmation_instructions
flash[:notice] = I18n.t("devise.activation.reactivated", user_name:) flash[:notice] = I18n.t("devise.activation.reactivated", user_name:)
elsif user_params.key?("email") && FeatureToggle.new_email_journey? elsif user_params.key?("email")
flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email) flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email)
end end
redirect_to user_path(@user) redirect_to user_path(@user)

12
app/mailers/devise_notify_mailer.rb

@ -36,14 +36,9 @@ class DeviseNotifyMailer < Devise::Mailer
def confirmation_instructions(record, token, _opts = {}) def confirmation_instructions(record, token, _opts = {})
if email_changed?(record) if email_changed?(record)
if new_email_journey?
send_email_changed_to_old_email(record) send_email_changed_to_old_email(record)
send_email_changed_to_new_email(record, token) send_email_changed_to_new_email(record, token)
else elsif !record.confirmed? && record.unconfirmed_email
send_confirmation_email(record.unconfirmed_email, record, token, record.unconfirmed_email)
send_confirmation_email(record.email, record, token, record.unconfirmed_email)
end
elsif !record.confirmed? && record.unconfirmed_email && new_email_journey?
send_confirmation_email(record.unconfirmed_email, record, token, record.unconfirmed_email) send_confirmation_email(record.unconfirmed_email, record, token, record.unconfirmed_email)
send_email_changed_to_old_email(record) send_email_changed_to_old_email(record)
else else
@ -96,16 +91,11 @@ class DeviseNotifyMailer < Devise::Mailer
record.confirmable_template == User::CONFIRMABLE_TEMPLATE_ID && ( record.confirmable_template == User::CONFIRMABLE_TEMPLATE_ID && (
record.unconfirmed_email.present? && record.unconfirmed_email != record.email) record.unconfirmed_email.present? && record.unconfirmed_email != record.email)
) || ( ) || (
new_email_journey? &&
record.versions.last.changeset.key?("unconfirmed_email") && record.versions.last.changeset.key?("unconfirmed_email") &&
record.confirmed? record.confirmed?
) )
end end
def new_email_journey?
FeatureToggle.new_email_journey?
end
def send_confirmation_email(email, record, token, username) def send_confirmation_email(email, record, token, username)
url = "#{user_confirmation_url}?confirmation_token=" url = "#{user_confirmation_url}?confirmation_token="

4
app/services/feature_toggle.rb

@ -33,8 +33,4 @@ class FeatureToggle
def self.deduplication_flow_enabled? def self.deduplication_flow_enabled?
!Rails.env.production? && !Rails.env.staging? !Rails.env.production? && !Rails.env.staging?
end end
def self.new_email_journey?
!Rails.env.production?
end
end end

54
spec/requests/users_controller_spec.rb

@ -1551,27 +1551,6 @@ RSpec.describe UsersController, type: :request do
before do before do
user.legacy_users.destroy_all user.legacy_users.destroy_all
allow(FeatureToggle).to receive(:new_email_journey?).and_return(false)
end
it "allows changing email and dpo" do
request
user.reload
expect(user.unconfirmed_email).to eq(new_email)
expect(user.is_data_protection_officer?).to be true
expect(user.is_key_contact?).to be true
end
it "sends a confirmation email to both emails" do
expect(notify_client).to receive(:send_email).with(email_address: new_email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).to receive(:send_email).with(email_address: user.email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
request
end
context "with new email journy enabled" do
before do
allow(FeatureToggle).to receive(:new_email_journey?).and_return(true)
end end
it "shows flash notice" do it "shows flash notice" do
@ -1647,7 +1626,6 @@ RSpec.describe UsersController, type: :request do
end end
end end
end end
end
context "when we update the user password" do context "when we update the user password" do
let(:params) do let(:params) do
@ -1778,37 +1756,6 @@ RSpec.describe UsersController, type: :request do
before do before do
other_user.legacy_users.destroy_all other_user.legacy_users.destroy_all
allow(FeatureToggle).to receive(:new_email_journey?).and_return(false)
end
it "does not update the password" do
expect { patch "/users/#{other_user.id}", headers:, params: }
.not_to change(other_user, :encrypted_password)
end
it "does update other values" do
expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.name }.from("Danny Rojas").to("new name")
end
it "allows changing email" do
expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.unconfirmed_email }.from(nil).to(new_email)
end
it "sends a confirmation email to both emails" do
expect(notify_client).to receive(:send_email).with(email_address: other_user.email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).to receive(:send_email).with(email_address: new_email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).not_to receive(:send_email)
patch "/users/#{other_user.id}", headers:, params:
end
context "with new user email flow enabled" do
before do
allow(FeatureToggle).to receive(:new_email_journey?).and_return(true)
end end
it "shows flash notice" do it "shows flash notice" do
@ -1845,7 +1792,6 @@ RSpec.describe UsersController, type: :request do
end end
end end
end end
end
context "when the update fails to persist" do context "when the update fails to persist" do
before do before do

Loading…
Cancel
Save