Skip to content

Commit

Permalink
Admin: can create whitelisted emails
Browse files Browse the repository at this point in the history
  • Loading branch information
skelz0r committed Jan 23, 2025
1 parent 16d296c commit 2fbad35
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/controllers/admin/whitelisted_verified_emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/views/admin/whitelisted_verified_emails/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<%= content_for(:header_action) do %>
<%= link_to t('.add'), new_admin_whitelisted_verified_email_path, class: %[fr-btn] %>
<% end %>

<turbo-frame id="verified_emails_table">
<div class="fr-table fr-table--bordered">
<div class="fr-table__container">
Expand Down
10 changes: 10 additions & 0 deletions app/views/admin/whitelisted_verified_emails/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="fr-container">
<div class="fr-grid-row">
<div class="fr-col-6">
<%= 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 %>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions config/locales/admin.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions features/admin/emails_verifies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
Et la page ne contient pas "[email protected]"

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 "[email protected]"
Et que je clique sur "Valider"
Alors la page contient "[email protected]"
Et il y a un message de succès contenant "a été ajouté"

0 comments on commit 2fbad35

Please sign in to comment.