From c0c254f6a5dc33fb3e2002d0d147b3bc203e5ba8 Mon Sep 17 00:00:00 2001 From: Amir Reavis-Bey Date: Wed, 7 Jun 2023 08:35:13 -0400 Subject: [PATCH 1/4] do not update verified_at when activating a profile due to a password reset [skip changelog] --- app/models/profile.rb | 18 +++++++++++------- spec/models/profile_spec.rb | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index d113a180ec1..6886a80a6d6 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -46,18 +46,22 @@ def pending_reasons end # rubocop:disable Rails/SkipsModelValidations - def activate + def activate(reason_deactivated = nil) confirm_that_profile_can_be_activated! now = Time.zone.now is_reproof = Profile.find_by(user_id: user_id, active: true) + + attrs = { + active: true, + activated_at: now, + } + + attrs[:verified_at] = now unless reason_deactivated == :password_reset + transaction do Profile.where(user_id: user_id).update_all(active: false) - update!( - active: true, - activated_at: now, - verified_at: now, - ) + update!(attrs) end send_push_notifications if is_reproof end @@ -97,7 +101,7 @@ def activate_after_password_reset update!( deactivation_reason: nil, ) - activate + activate(:password_reset) end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 17af2a7c199..92556092b35 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -332,6 +332,22 @@ expect(profile.active).to eq true expect(profile.deactivation_reason).to eq nil + expect(profile.verified_at).to eq nil + end + + it 'activates a previously verified profile after password reset' do + verified_at = Time.now - 1.year + profile = create( + :profile, + user: user, + active: false, + deactivation_reason: :password_reset, + verified_at: verified_at + ) + + profile.activate_after_password_reset + + expect(profile.verified_at).to eq verified_at end it 'does not activate a profile if it has a pending reason' do From 04e4e0d385397031bc1f359692c4ec87a77c4f17 Mon Sep 17 00:00:00 2001 From: Amir Reavis-Bey Date: Wed, 7 Jun 2023 08:46:59 -0400 Subject: [PATCH 2/4] happy linting --- spec/models/profile_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 92556092b35..41b33d00c63 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -336,13 +336,13 @@ end it 'activates a previously verified profile after password reset' do - verified_at = Time.now - 1.year + verified_at = Time.zone.now - 1.year profile = create( :profile, user: user, active: false, deactivation_reason: :password_reset, - verified_at: verified_at + verified_at: verified_at, ) profile.activate_after_password_reset From 1565b955a239607487ca91fc7e04ab491c0da269 Mon Sep 17 00:00:00 2001 From: Amir Reavis-Bey Date: Wed, 7 Jun 2023 08:59:43 -0400 Subject: [PATCH 3/4] keep test checks from password_reset of unverified profile in test for an already verified profile --- spec/models/profile_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 41b33d00c63..7d87abdaa2d 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -347,6 +347,8 @@ profile.activate_after_password_reset + expect(profile.active).to eq true + expect(profile.deactivation_reason).to eq nil expect(profile.verified_at).to eq verified_at end From 77799450823ee8bad3ddc39fc64dee8f9c664778 Mon Sep 17 00:00:00 2001 From: Amir Reavis-Bey Date: Wed, 7 Jun 2023 10:58:11 -0400 Subject: [PATCH 4/4] udpate activate signature style to symbol --- app/models/profile.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 6886a80a6d6..e0a408ada17 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -46,7 +46,7 @@ def pending_reasons end # rubocop:disable Rails/SkipsModelValidations - def activate(reason_deactivated = nil) + def activate(reason_deactivated: nil) confirm_that_profile_can_be_activated! now = Time.zone.now @@ -101,7 +101,7 @@ def activate_after_password_reset update!( deactivation_reason: nil, ) - activate(:password_reset) + activate(reason_deactivated: :password_reset) end end