From 5e8327ff0930932310ab11453a1de389f8b734a3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 8 Apr 2021 17:46:11 +0200 Subject: [PATCH] manager: refactor SendInBlue unblock action --- app/controllers/manager/users_controller.rb | 16 ++++++++-------- app/lib/sendinblue/api.rb | 9 +++++++++ app/views/manager/users/emails.html.erb | 20 +++++++++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/controllers/manager/users_controller.rb b/app/controllers/manager/users_controller.rb index 604ba99d7..0dd325515 100644 --- a/app/controllers/manager/users_controller.rb +++ b/app/controllers/manager/users_controller.rb @@ -52,14 +52,14 @@ module Manager @sent_mails = Sendinblue::API.new.sent_mails(@user.email) end - def unblock_user - @user = User.find(params[:id]) - - transactionnal_api = ::SibApiV3Sdk::TransactionalEmailsApi.new - transactionnal_api.smtp_blocked_contacts_email_delete(@user.email) - - rescue ::SibApiV3Sdk::ApiError => e - flash.alert = "Impossible de débloquer cet email auprès de Sendinblue : #{e.message}" + def unblock_email + @user = User.find(params[:user_id]) + if Sendinblue::API.new.unblock_user(@user.email) + flash.notice = "L'adresse email a été débloquée auprès de Sendinblue" + else + flash.alert = "Impossible de débloquer cette addresse email auprès de Sendinblue" + end + redirect_to emails_manager_user_path(@user) end end end diff --git a/app/lib/sendinblue/api.rb b/app/lib/sendinblue/api.rb index 2e287999e..476240c9b 100644 --- a/app/lib/sendinblue/api.rb +++ b/app/lib/sendinblue/api.rb @@ -55,6 +55,15 @@ class Sendinblue::API [] end + def unblock_user(email_address) + client = ::SibApiV3Sdk::TransactionalEmailsApi.new + client.smtp_blocked_contacts_email_delete(email_address) + true + rescue ::SibApiV3Sdk::ApiError => e + Rails.logger.error e.message + false + end + def run hydra.run @hydra = nil diff --git a/app/views/manager/users/emails.html.erb b/app/views/manager/users/emails.html.erb index b0b4ccfd8..764b7a2e0 100644 --- a/app/views/manager/users/emails.html.erb +++ b/app/views/manager/users/emails.html.erb @@ -98,8 +98,12 @@ https://www.demarches-simplifiees.fr/users/password/new Cordialement <% end %> -

Compte bloqué chez Sendinblue ? Vous pouvez le <%= link_to('débloquer', manager_user_unblock_email_path(@user), method: :put, class: 'button', remote: true) %> puis lui envoyer

- +

+ Problème chez Sendinblue ? + Regardez leur page de status. + +

+Bien cordialement, +