diff --git a/.gitignore b/.gitignore index a210a1d87..e22760720 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ uploads/* *.swp .envrc .env +.tool-versions storage/ /node_modules /yarn-error.log diff --git a/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months.rake b/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months.rake new file mode 100644 index 000000000..3ef23f4dc --- /dev/null +++ b/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months.rake @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +namespace :after_party do + desc 'Deployment task: mark_email_verified_when_user_signed_in_during_last_5_months' + task mark_email_verified_when_user_signed_in_during_last_5_months: :environment do + affected_users_count = User.where(email_verified_at: nil, sign_in_count: 1..).count + + puts "Processing #{affected_users_count} users signed in during the last 5 months and not verified" + + User.where(email_verified_at: nil, sign_in_count: 1..).update_all(email_verified_at: Time.zone.now) + puts "Done" + + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end diff --git a/spec/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months_spec.rb b/spec/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months_spec.rb new file mode 100644 index 000000000..c2657e955 --- /dev/null +++ b/spec/lib/tasks/deployment/20240911141817_mark_email_verified_when_user_signed_in_during_last_5_months_spec.rb @@ -0,0 +1,28 @@ + +# frozen_string_literal: true + +describe 'after_party:mark_email_verified_when_user_signed_in_during_last_5_months' do + let(:rake_task) { Rake::Task['after_party:mark_email_verified_when_user_signed_in_during_last_5_months'] } + + subject { rake_task.invoke } + after(:each) { rake_task.reenable } + + let(:old_date) { 6.months.ago } + + let!(:user) { create(:user, email_verified_at: nil, sign_in_count: 1) } + let!(:user2) { create(:user, email_verified_at: nil, sign_in_count: 1) } + let!(:user3) { create(:user, email_verified_at: nil, sign_in_count: 0) } + let!(:user4) { create(:user, email_verified_at: old_date, sign_in_count: 1) } + + it 'mark_email_verified_when_user_signed_in_during_last_5_months' do + expect(User.where(email_verified_at: nil, sign_in_count: 1..).count).to eq(2) + + subject + + expect(User.where(email_verified_at: nil, sign_in_count: 1..).count).to eq(0) + expect(user.reload.email_verified_at).to be_present + expect(user2.reload.email_verified_at).to be_present + expect(user3.reload.email_verified_at).to be_nil + expect(user4.reload.email_verified_at).to eq(old_date) + end +end