-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10456 from demarches-simplifiees/infra_email_conf…
…irmation Mise en place de l 'infrastructure de rejet d'envoi de mails non confirmés
- Loading branch information
Showing
11 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/tasks/maintenance/prefill_individual_email_verified_at_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# We are going to confirm the various email addresses of the users in the system. | ||
# Individual model (mandant) needs their email_verified_at attribute to be set in order to receive emails. | ||
# This task sets the email_verified_at attribute to the current time for all the individual to be backward compatible | ||
# See https://github.com/demarches-simplifiees/demarches-simplifiees.fr/issues/10450 | ||
module Maintenance | ||
class PrefillIndividualEmailVerifiedAtTask < MaintenanceTasks::Task | ||
def collection | ||
Individual.in_batches | ||
end | ||
|
||
def process(batch_of_individuals) | ||
batch_of_individuals.update_all(email_verified_at: Time.zone.now) | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
app/tasks/maintenance/prefill_user_email_verified_at_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# We are going to confirm the various email addresses of the users in the system. | ||
# User model needs their email_verified_at attribute to be set in order to receive emails. | ||
# This task sets the email_verified_at attribute to the current time for all users to be backward compatible | ||
# See https://github.com/demarches-simplifiees/demarches-simplifiees.fr/issues/10450 | ||
module Maintenance | ||
class PrefillUserEmailVerifiedAtTask < MaintenanceTasks::Task | ||
def collection | ||
User.in_batches | ||
end | ||
|
||
def process(batch_of_users) | ||
batch_of_users.update_all(email_verified_at: Time.zone.now) | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240524120336_add_email_verified_at_column_to_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddEmailVerifiedAtColumnToUsers < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :users, :email_verified_at, :datetime | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240527090508_add_email_verified_at_column_to_individuals.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddEmailVerifiedAtColumnToIndividuals < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :individuals, :email_verified_at, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,7 @@ | |
expect(individual.errors.full_messages).to be_empty | ||
expect(individual.notification_method).to eq('email') | ||
expect(individual.email).to eq('[email protected]') | ||
expect(individual.email_verified_at).to be_present | ||
expect(response).to redirect_to(brouillon_dossier_path(dossier)) | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
it do | ||
subject | ||
expect(fci.user.email).to eq('[email protected]') | ||
expect(fci.user.email_verified_at).to be_present | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,12 @@ | |
user.confirm | ||
expect(user.reload.invites.size).to eq(2) | ||
end | ||
|
||
it 'verifies its email' do | ||
expect(user.email_verified_at).to be_nil | ||
user.confirm | ||
expect(user.email_verified_at).to be_present | ||
end | ||
end | ||
|
||
describe '#owns?' do | ||
|
@@ -111,6 +117,7 @@ | |
user = subject | ||
expect(user.valid_password?(password)).to be true | ||
expect(user.confirmed_at).to be_present | ||
expect(user.email_verified_at).to be_present | ||
expect(user.instructeur).to be_present | ||
end | ||
|
||
|
@@ -184,6 +191,7 @@ | |
user = subject | ||
expect(user.valid_password?(password)).to be true | ||
expect(user.confirmed_at).to be_present | ||
expect(user.email_verified_at).to be_present | ||
expect(user.expert).to be_present | ||
end | ||
end | ||
|
@@ -214,6 +222,18 @@ | |
end | ||
end | ||
|
||
describe '.create_or_promote_to_gestionnaire' do | ||
let(:email) { '[email protected]' } | ||
let(:password) { 'un super password !' } | ||
|
||
subject { User.create_or_promote_to_gestionnaire(email, password) } | ||
|
||
it 'verifies its email' do | ||
user = subject | ||
expect(user.email_verified_at).to be_present | ||
end | ||
end | ||
|
||
describe 'invite_administrateur!' do | ||
let(:super_admin) { create(:super_admin) } | ||
let(:administrateur) { create(:administrateur) } | ||
|