diff --git a/app/controllers/admin/whitelisted_verified_emails_controller.rb b/app/controllers/admin/whitelisted_verified_emails_controller.rb index e73804101..43f817ad6 100644 --- a/app/controllers/admin/whitelisted_verified_emails_controller.rb +++ b/app/controllers/admin/whitelisted_verified_emails_controller.rb @@ -2,4 +2,26 @@ class Admin::WhitelistedVerifiedEmailsController < AdminController def index @verified_emails = VerifiedEmail.where(status: 'whitelisted').order(created_at: :desc).page(params[:page]).per(50) end + + def new + @verified_email = VerifiedEmail.new + end + + def create + @verified_email = VerifiedEmail.new(verified_email_params) + + if @verified_email.save + success_message(title: t('.success', verified_email_email: @verified_email.email)) + + redirect_to admin_whitelisted_verified_emails_path + else + render :new, status: :unprocessable_entity + end + end + + private + + def verified_email_params + params.expect(verified_email: [:email]).merge(status: 'whitelisted') + end end diff --git a/app/views/admin/whitelisted_verified_emails/index.html.erb b/app/views/admin/whitelisted_verified_emails/index.html.erb index 97e9e0978..bf05ccb08 100644 --- a/app/views/admin/whitelisted_verified_emails/index.html.erb +++ b/app/views/admin/whitelisted_verified_emails/index.html.erb @@ -1,3 +1,7 @@ +<%= content_for(:header_action) do %> + <%= link_to t('.add'), new_admin_whitelisted_verified_email_path, class: %[fr-btn] %> +<% end %> +
diff --git a/app/views/admin/whitelisted_verified_emails/new.html.erb b/app/views/admin/whitelisted_verified_emails/new.html.erb new file mode 100644 index 000000000..52a68c9d5 --- /dev/null +++ b/app/views/admin/whitelisted_verified_emails/new.html.erb @@ -0,0 +1,10 @@ +
+
+
+ <%= form_with(model: @verified_email, url: admin_whitelisted_verified_emails_path) do |f| %> + <%= f.dsfr_email_field :email, required: true %> + <%= f.submit t('.cta'), class: %w[fr-btn fr-btn--sm] %> + <% end %> +
+
+
diff --git a/config/locales/admin.fr.yml b/config/locales/admin.fr.yml index bcdf676da..e0a6d9007 100644 --- a/config/locales/admin.fr.yml +++ b/config/locales/admin.fr.yml @@ -10,3 +10,9 @@ fr: email: Email created_at: Date de création actions: Actions + add: Ajouter un email + new: + title: Ajouter un email en liste blanche + cta: Valider + create: + success: L'email %{verified_email_email} a été ajouté avec succès diff --git a/features/admin/emails_verifies.feature b/features/admin/emails_verifies.feature index 080010dc5..9194069e0 100644 --- a/features/admin/emails_verifies.feature +++ b/features/admin/emails_verifies.feature @@ -14,3 +14,12 @@ Fonctionnalité: Espace admin: emails en liste blanche Et que je me rends sur le module "Emails vérifiés" de l'espace administrateur Alors la page contient "liste-blanche@gouv.fr" Et la page ne contient pas "delivrable@gouv.fr" + + Scénario: Je peux ajouter un email en liste blanche + Quand je me rends sur le module "Emails vérifiés" de l'espace administrateur + Et que je clique sur "Ajouter un email" + Et que je remplis "Email" avec "nouveau@gouv.fr" + Et que je clique sur "Valider" + Alors la page contient "nouveau@gouv.fr" + Et il y a un message de succès contenant "a été ajouté" +