From 631ee42947cbba8e00803cd7498d676aea64fd6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Tue, 29 Oct 2024 11:39:31 +0000 Subject: [PATCH] More clean from transfer migration to DataPass --- .../notify_datapass_of_token_ownership.rb | 20 ------ app/mailers/api_entreprise/user_mailer.rb | 3 - app/mailers/api_particulier/user_mailer.rb | 3 - app/mailers/concerns/user_mailer_commons.rb | 27 ------- .../api_entreprise/user/o_auth_login.rb | 3 +- .../api_particulier/user/o_auth_login.rb | 3 +- .../signin_process_datapass_spec.rb | 11 --- .../signin_process_datapass_spec.rb | 11 --- .../api_entreprise/user_mailer_spec.rb | 70 ------------------- .../api_particulier/user_mailer_spec.rb | 70 ------------------- .../api_entreprise/user_mailer_preview.rb | 22 ------ .../api_particulier/user_mailer_preview.rb | 22 ------ .../api_entreprise/user/o_auth_login_spec.rb | 22 ------ .../api_particulier/user/o_auth_login_spec.rb | 22 ------ 14 files changed, 2 insertions(+), 307 deletions(-) delete mode 100644 app/interactors/user/notify_datapass_of_token_ownership.rb delete mode 100644 app/mailers/api_entreprise/user_mailer.rb delete mode 100644 app/mailers/api_particulier/user_mailer.rb delete mode 100644 app/mailers/concerns/user_mailer_commons.rb delete mode 100644 spec/mailers/api_entreprise/user_mailer_spec.rb delete mode 100644 spec/mailers/api_particulier/user_mailer_spec.rb delete mode 100644 spec/mailers/previews/api_entreprise/user_mailer_preview.rb delete mode 100644 spec/mailers/previews/api_particulier/user_mailer_preview.rb diff --git a/app/interactors/user/notify_datapass_of_token_ownership.rb b/app/interactors/user/notify_datapass_of_token_ownership.rb deleted file mode 100644 index 30e18eb6b..000000000 --- a/app/interactors/user/notify_datapass_of_token_ownership.rb +++ /dev/null @@ -1,20 +0,0 @@ -class User - class NotifyDatapassOfTokenOwnership < ApplicationInteractor - def call - return unless first_login_after_token_transfer? - - mailer_klass.notify_datapass_for_data_reconciliation(context.user, context.namespace).deliver_later - context.user.update(tokens_newly_transfered: false) - end - - private - - def mailer_klass - "#{context.namespace.classify}::UserMailer".constantize - end - - def first_login_after_token_transfer? - context.user.tokens_newly_transfered? - end - end -end diff --git a/app/mailers/api_entreprise/user_mailer.rb b/app/mailers/api_entreprise/user_mailer.rb deleted file mode 100644 index 97150c9b0..000000000 --- a/app/mailers/api_entreprise/user_mailer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class APIEntreprise::UserMailer < APIEntrepriseMailer - include UserMailerCommons -end diff --git a/app/mailers/api_particulier/user_mailer.rb b/app/mailers/api_particulier/user_mailer.rb deleted file mode 100644 index 4437d80b6..000000000 --- a/app/mailers/api_particulier/user_mailer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class APIParticulier::UserMailer < APIParticulierMailer - include UserMailerCommons -end diff --git a/app/mailers/concerns/user_mailer_commons.rb b/app/mailers/concerns/user_mailer_commons.rb deleted file mode 100644 index 2486a8121..000000000 --- a/app/mailers/concerns/user_mailer_commons.rb +++ /dev/null @@ -1,27 +0,0 @@ -module UserMailerCommons - include FriendlyDateHelper - - def transfer_ownership(old_owner, new_owner, namespace) - @new_owner = new_owner - @old_owner = old_owner - @login_url = "https://#{api(namespace)}.api.gouv.fr/compte/se-connecter" - @datapass_signup_url = 'https://app.moncomptepro.beta.gouv.fr/users/sign-up' - subject = "#{I18n.t("#{namespace}.name")} - Délégation d'accès" - - mail(to: @new_owner.email, subject:) - end - - def notify_datapass_for_data_reconciliation(user, namespace) - @user = user - @datapass_ids = user.authorization_requests.map(&:external_id).map(&:to_i) - - dest_address = 'datapass@api.gouv.fr' - subject = "#{I18n.t("#{namespace}.name")} - Réconciliation de demandes d'accès à un nouvel usager" - - mail(to: dest_address, subject:) - end - - def api(namespace) - namespace.slice(4..-1) - end -end diff --git a/app/organizers/api_entreprise/user/o_auth_login.rb b/app/organizers/api_entreprise/user/o_auth_login.rb index a5b1d1eff..f54a54dd4 100644 --- a/app/organizers/api_entreprise/user/o_auth_login.rb +++ b/app/organizers/api_entreprise/user/o_auth_login.rb @@ -1,5 +1,4 @@ class APIEntreprise::User::OAuthLogin < ApplicationOrganizer organize User::FindOrCreateThroughOAuth, - User::UpdateOAuthAPIGouvId, - User::NotifyDatapassOfTokenOwnership + User::UpdateOAuthAPIGouvId end diff --git a/app/organizers/api_particulier/user/o_auth_login.rb b/app/organizers/api_particulier/user/o_auth_login.rb index c8a825c23..1fa7e24ce 100644 --- a/app/organizers/api_particulier/user/o_auth_login.rb +++ b/app/organizers/api_particulier/user/o_auth_login.rb @@ -1,5 +1,4 @@ class APIParticulier::User::OAuthLogin < ApplicationOrganizer organize User::FindOrCreateThroughOAuth, - User::UpdateOAuthAPIGouvId, - User::NotifyDatapassOfTokenOwnership + User::UpdateOAuthAPIGouvId end diff --git a/spec/features/api_entreprise/signin_process_datapass_spec.rb b/spec/features/api_entreprise/signin_process_datapass_spec.rb index c8c7eb30f..9adf907fa 100644 --- a/spec/features/api_entreprise/signin_process_datapass_spec.rb +++ b/spec/features/api_entreprise/signin_process_datapass_spec.rb @@ -63,12 +63,6 @@ expect(user.oauth_api_gouv_id).to eq(unknown_api_gouv_id) end - it 'sends an email to DataPass to update the authorization request owner' do - expect { subject } - .to have_enqueued_mail(APIEntreprise::UserMailer, :notify_datapass_for_data_reconciliation) - .with(user, 'api_entreprise') - end - it 'redirects to the user profile' do subject @@ -79,11 +73,6 @@ context 'when the user signs in the second time (and more)' do let!(:user) { create(:user) } - it 'does not send any email to DataPass' do - expect { subject } - .not_to have_enqueued_mail(APIEntreprise::UserMailer, :notify_datapass_for_data_reconciliation) - end - it 'redirects to the user profile' do subject diff --git a/spec/features/api_particulier/signin_process_datapass_spec.rb b/spec/features/api_particulier/signin_process_datapass_spec.rb index cf9b354da..9547b9ae3 100644 --- a/spec/features/api_particulier/signin_process_datapass_spec.rb +++ b/spec/features/api_particulier/signin_process_datapass_spec.rb @@ -63,12 +63,6 @@ expect(user.oauth_api_gouv_id).to eq(unknown_api_gouv_id) end - it 'sends an email to DataPass to update the authorization request owner' do - expect { subject } - .to have_enqueued_mail(APIParticulier::UserMailer, :notify_datapass_for_data_reconciliation) - .with(user, 'api_particulier') - end - it 'redirects to the user profile' do subject @@ -79,11 +73,6 @@ context 'when the user signs in the second time (and more)' do let!(:user) { create(:user) } - it 'does not send any email to DataPass' do - expect { subject } - .not_to have_enqueued_mail(APIParticulier::UserMailer, :notify_datapass_for_data_reconciliation) - end - it 'redirects to the user profile' do subject diff --git a/spec/mailers/api_entreprise/user_mailer_spec.rb b/spec/mailers/api_entreprise/user_mailer_spec.rb deleted file mode 100644 index 0aecfd111..000000000 --- a/spec/mailers/api_entreprise/user_mailer_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'rails_helper' - -RSpec.describe APIEntreprise::UserMailer do - describe '#transfer_ownership' do - subject { described_class.transfer_ownership(old_owner, new_owner, 'api_entreprise') } - - let(:new_owner) { create(:user) } - let(:old_owner) { create(:user) } - - let!(:authorization_requests) do - create_list(:authorization_request, 3, :with_tokens, :with_demandeur, demandeur: old_owner, api: 'entreprise') - end - - its(:subject) { is_expected.to eq('API Entreprise - Délégation d\'accès') } - its(:to) { is_expected.to eq([new_owner.email]) } - - describe 'email body' do - it 'contains the previous owner email address' do - expect(subject.html_part.decoded).to include(old_owner.email) - expect(subject.text_part.decoded).to include(old_owner.email) - end - - it 'notifies the user to login to access his tokens' do - login_url = 'https://entreprise.api.gouv.fr/compte/se-connecter' - - expect(subject.html_part.decoded).to include(login_url) - expect(subject.text_part.decoded).to include(login_url) - end - - context 'when the new owner already has an API Gouv account' do - before { new_owner.oauth_api_gouv_id = '12' } - - it 'informs the user he will need his API Gouv account' do - expect(subject.html_part.decoded).to include(new_owner.email) - expect(subject.text_part.decoded).to include(new_owner.email) - end - end - end - end - - describe '#notify_datapass_for_data_reconciliation' do - subject { described_class.notify_datapass_for_data_reconciliation(user, 'api_entreprise') } - - let(:user) { create(:user) } - - let!(:authorization_requests) do - create_list(:authorization_request, 3, :with_tokens, :with_demandeur, demandeur: user, api: 'entreprise') - end - - let(:datapass_ids) { user.authorization_requests.for_api('entreprise').map(&:external_id).map(&:to_i) } - - its(:subject) { is_expected.to eq('API Entreprise - Réconciliation de demandes d\'accès à un nouvel usager') } - its(:to) { is_expected.to eq(['datapass@api.gouv.fr']) } - - it 'contains the user email address' do - expect(subject.html_part.decoded).to include(user.email) - expect(subject.text_part.decoded).to include(user.email) - end - - it 'contains the user API Gouv ID' do - expect(subject.html_part.decoded).to include(user.oauth_api_gouv_id.to_s) - expect(subject.text_part.decoded).to include(user.oauth_api_gouv_id.to_s) - end - - it 'contains the user\'s datapass IDs' do - expect(subject.html_part.decoded).to include(datapass_ids.to_s) - expect(subject.text_part.decoded).to include(datapass_ids.to_s) - end - end -end diff --git a/spec/mailers/api_particulier/user_mailer_spec.rb b/spec/mailers/api_particulier/user_mailer_spec.rb deleted file mode 100644 index 1738f094c..000000000 --- a/spec/mailers/api_particulier/user_mailer_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'rails_helper' - -RSpec.describe APIParticulier::UserMailer do - describe '#transfer_ownership' do - subject { described_class.transfer_ownership(old_owner, new_owner, 'api_particulier') } - - let(:new_owner) { create(:user) } - let(:old_owner) { create(:user) } - - let!(:authorization_requests) do - create_list(:authorization_request, 3, :with_tokens, :with_demandeur, demandeur: old_owner, api: 'particulier') - end - - its(:subject) { is_expected.to eq('API Particulier - Délégation d\'accès') } - its(:to) { is_expected.to eq([new_owner.email]) } - - describe 'email body' do - it 'contains the previous owner email address' do - expect(subject.html_part.decoded).to include(old_owner.email) - expect(subject.text_part.decoded).to include(old_owner.email) - end - - it 'notifies the user to login to access his tokens' do - login_url = 'https://particulier.api.gouv.fr/compte/se-connecter' - - expect(subject.html_part.decoded).to include(login_url) - expect(subject.text_part.decoded).to include(login_url) - end - - context 'when the new owner already has an API Gouv account' do - before { new_owner.oauth_api_gouv_id = '12' } - - it 'informs the user he will need his API Gouv account' do - expect(subject.html_part.decoded).to include(new_owner.email) - expect(subject.text_part.decoded).to include(new_owner.email) - end - end - end - end - - describe '#notify_datapass_for_data_reconciliation' do - subject { described_class.notify_datapass_for_data_reconciliation(user, 'api_particulier') } - - let(:user) { create(:user) } - - let!(:authorization_requests) do - create_list(:authorization_request, 3, :with_tokens, :with_demandeur, demandeur: user, api: 'particulier') - end - - let(:datapass_ids) { user.authorization_requests.for_api('particulier').map(&:external_id).map(&:to_i) } - - its(:subject) { is_expected.to eq('API Particulier - Réconciliation de demandes d\'accès à un nouvel usager') } - its(:to) { is_expected.to eq(['datapass@api.gouv.fr']) } - - it 'contains the user email address' do - expect(subject.html_part.decoded).to include(user.email) - expect(subject.text_part.decoded).to include(user.email) - end - - it 'contains the user API Gouv ID' do - expect(subject.html_part.decoded).to include(user.oauth_api_gouv_id.to_s) - expect(subject.text_part.decoded).to include(user.oauth_api_gouv_id.to_s) - end - - it 'contains the user\'s datapass IDs' do - expect(subject.html_part.decoded).to include(datapass_ids.to_s) - expect(subject.text_part.decoded).to include(datapass_ids.to_s) - end - end -end diff --git a/spec/mailers/previews/api_entreprise/user_mailer_preview.rb b/spec/mailers/previews/api_entreprise/user_mailer_preview.rb deleted file mode 100644 index 4a253dcf0..000000000 --- a/spec/mailers/previews/api_entreprise/user_mailer_preview.rb +++ /dev/null @@ -1,22 +0,0 @@ -class APIEntreprise::UserMailerPreview < ActionMailer::Preview - def transfer_ownership - new_owner = User.first - old_owner = User.last - - APIEntreprise::UserMailer.transfer_ownership(old_owner, new_owner, old_owner.authorization_requests.for_api('entreprise'), 'api_entreprise') - end - - def notify_datapass_for_data_reconciliation - APIEntreprise::UserMailer.notify_datapass_for_data_reconciliation(user, 'api_entreprise') - end - - private - - def to - 'example@fake.com' - end - - def user - User.first - end -end diff --git a/spec/mailers/previews/api_particulier/user_mailer_preview.rb b/spec/mailers/previews/api_particulier/user_mailer_preview.rb deleted file mode 100644 index 9a5fe646d..000000000 --- a/spec/mailers/previews/api_particulier/user_mailer_preview.rb +++ /dev/null @@ -1,22 +0,0 @@ -class APIParticulier::UserMailerPreview < ActionMailer::Preview - def transfer_ownership - new_owner = User.first - old_owner = User.last - - APIParticulier::UserMailer.transfer_ownership(old_owner, new_owner, old_owner.authorization_requests.for_api('particulier'), 'api_particulier') - end - - def notify_datapass_for_data_reconciliation - APIParticulier::UserMailer.notify_datapass_for_data_reconciliation(user, 'api_particulier') - end - - private - - def to - 'example@fake.com' - end - - def user - User.first - end -end diff --git a/spec/organizers/api_entreprise/user/o_auth_login_spec.rb b/spec/organizers/api_entreprise/user/o_auth_login_spec.rb index d8870bd62..cf5d188ed 100644 --- a/spec/organizers/api_entreprise/user/o_auth_login_spec.rb +++ b/spec/organizers/api_entreprise/user/o_auth_login_spec.rb @@ -67,27 +67,5 @@ expect(user.oauth_api_gouv_id).to eq(oauth_api_gouv_id) end end - - context 'when the user signs in after receiving new tokens' do - let!(:user) { create(:user, :new_token_owner) } - let(:oauth_api_gouv_id) { user.oauth_api_gouv_id } - - let(:another_sync) { described_class.call(params) } - - it { is_expected.to be_a_success } - - it 'sends an email to datapass for authorization request ownership update' do - expect { sync! } - .to have_enqueued_mail(APIEntreprise::UserMailer, :notify_datapass_for_data_reconciliation) - .with(user, 'api_entreprise') - end - - it 'does not send emails on second login' do - another_sync - - expect { sync! } - .not_to have_enqueued_mail(APIEntreprise::UserMailer, :notify_datapass_for_data_reconciliation) - end - end end end diff --git a/spec/organizers/api_particulier/user/o_auth_login_spec.rb b/spec/organizers/api_particulier/user/o_auth_login_spec.rb index a9c26daee..23ed71aa9 100644 --- a/spec/organizers/api_particulier/user/o_auth_login_spec.rb +++ b/spec/organizers/api_particulier/user/o_auth_login_spec.rb @@ -67,27 +67,5 @@ expect(user.oauth_api_gouv_id).to eq(oauth_api_gouv_id) end end - - context 'when the user signs in after receiving new tokens' do - let!(:user) { create(:user, :new_token_owner) } - let(:oauth_api_gouv_id) { user.oauth_api_gouv_id } - - let(:another_sync) { described_class.call(params) } - - it { is_expected.to be_a_success } - - it 'sends an email to datapass for authorization request ownership update' do - expect { sync! } - .to have_enqueued_mail(APIParticulier::UserMailer, :notify_datapass_for_data_reconciliation) - .with(user, 'api_particulier') - end - - it 'does not send emails on second login' do - another_sync - - expect { sync! } - .not_to have_enqueued_mail(APIParticulier::UserMailer, :notify_datapass_for_data_reconciliation) - end - end end end