Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce admin space with whitelisted emails verified #670

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ jobs:
--env-file ./.github/workflows/test.env \
--rm data_pass bundle exec rspec

integration-tests-instruction:
name: "Integration tests: instruction"
needs: build
uses: ./.github/workflows/reusable-integration-tests.yaml
with:
cucumber_options: "features/{instructeurs,reporters}/"

integration-tests-admin:
name: "Integration tests: admin"
needs: build
uses: ./.github/workflows/reusable-integration-tests.yaml
with:
cucumber_options: "features/{instructeurs,reporters}/"
cucumber_options: "features/admin/"

integration-tests-dgfip-habilitations:
name: "Integration tests: dgfip habilitations"
Expand All @@ -156,7 +163,7 @@ jobs:
needs: build
uses: ./.github/workflows/reusable-integration-tests.yaml
with:
cucumber_options: "-e features/instructeurs/ -e features/habilitations/ -e features/reporters/"
cucumber_options: "-e features/instructeurs/ -e features/habilitations/ -e features/reporters/ -e features/admin/"

merge-with-main:
name: "Merge develop with main"
Expand All @@ -169,6 +176,7 @@ jobs:
- yaml-lint
- unit-tests
- integration-tests-admin
- integration-tests-instruction
- integration-tests-dgfip-habilitations
- integration-tests-others-habilitations
- integration-tests-others
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/admin/whitelisted_verified_emails_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
19 changes: 19 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class AdminController < AuthenticatedUserController
before_action :check_user_is_admin!

layout 'admin'

def index
render layout: 'application'
end

def check_user_is_admin!
return if current_user.admin?

flash[:error] = {
title: t('application.user_not_authorized.title')
}

redirect_to dashboard_path
end
end
10 changes: 6 additions & 4 deletions app/lib/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,25 @@ def extract_applicant(attributes)

def create_all_verified_emails
User.find_each do |user|
create_verified_email(user.email)
create_verified_email(user.email, 'deliverable')
end

create_verified_email('[email protected]', 'whitelisted')

AuthorizationRequest.find_each do |authorization_request|
authorization_request.class.contact_types.each do |contact_type|
create_verified_email(authorization_request.send(:"#{contact_type}_email"))
create_verified_email(authorization_request.send(:"#{contact_type}_email"), 'deliverable')
end
end
end

def create_verified_email(email)
def create_verified_email(email, status)
return if email.blank?
return if VerifiedEmail.exists?(email:)

VerifiedEmail.create!(
email:,
status: 'deliverable',
status:,
verified_at: Time.zone.now,
)
end
Expand Down
17 changes: 17 additions & 0 deletions app/views/admin/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="fr-container">
<div class="dashboard-sub-header">
<div class="sub-header">
<div>
<h1 class="fr-m-0">
<%= t('.title') %>
</h1>
</div>
</div>
</div>

<%= render partial: 'shared/alerts' %>

<ul>
<li><%= link_to 'Emails en liste blanche', admin_whitelisted_verified_emails_path %></li>
</ul>
</div>
48 changes: 48 additions & 0 deletions app/views/admin/whitelisted_verified_emails/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= 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">
<div class="fr-table__content">
<table>
<thead>
<tr>
<%
%w[
email
created_at
actions
].each do |attr|
%>
<th scope="col">
<%= t(".table.header.#{attr}") %>
</th>
<% end %>
</tr>
</thead>

<tbody>
<% @verified_emails.each do |verified_email| %>
<tr id="<%= dom_id(verified_email) %>">
<td class="verified-email-email">
<%= verified_email.email %>
</td>
<td class="verified-email-created_at">
<%= verified_email.created_at.to_date %>
</td>
<td class="verified-email-actions">
Supprimer
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>

<%= paginate @verified_emails %>
</turbo-frame>

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>
25 changes: 25 additions & 0 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= content_for(:body) do %>
<div class="fr-container">
<div class="dashboard-sub-header">
<div class="sub-header">
<div>
<h1 class="fr-m-0">
<%= t("admin.#{controller_name}.#{action_name}.title") %>
</h1>
</div>

<% if content_for?(:header_action) %>
<div>
<%= content_for(:header_action) %>
</div>
<% end %>
</div>
</div>

<%= render partial: 'shared/alerts' %>

<%= yield %>
</div>
<% end %>

<%= render template: 'layouts/application' %>
7 changes: 7 additions & 0 deletions app/views/layouts/header/_tools.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<%= t('.links.authorization_requests_index.title') %>
</a>
</li>
<% if current_user.admin? %>
<li>
<a class="fr-link fr-icon-todo-fill" href="<%= admin_path %>">
<%= t('.links.admin.title') %>
</a>
</li>
<% end %>
<% if current_user.reporter? %>
<li>
<a class="fr-link fr-icon-draft-fill" href="<%= instruction_path %>">
Expand Down
19 changes: 19 additions & 0 deletions config/locales/admin.fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fr:
admin:
index:
title: Espace administrateur
whitelisted_verified_emails:
index:
title: Emails en liste blanche
table:
header:
email: Email
created_at: Date de création
actions: Actions
add: Ajouter un email
new:
title: &whitelisted_verified_emails_form_title Ajouter un email en liste blanche
cta: Valider
create:
title: *whitelisted_verified_emails_form_title
success: L'email %{verified_email_email} a été ajouté avec succès
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ fr:
tagline: Habilitations juridiques
tools:
links:
admin:
title: Espace admin
instruction:
title: Espace instruction
authorization_requests_index:
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
end
end

get '/admin', to: 'admin#index', as: :admin

namespace :admin do
resources :whitelisted_verified_emails, only: %w[index new create], path: 'emails-verifies'
end

namespace :api do
resources :frontal, only: :index
end
Expand Down
42 changes: 42 additions & 0 deletions features/acces_espaces_en_fonction_des_roles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# language: fr

Fonctionnalité: Niveau d'accès aux différentes pages en fonction des rôles
Scénario: En tant qu'utilisateur normal, je ne peux pas accéder à l'espace d'instruction
Sachant que je suis un demandeur
Et que je me connecte
Et que je vais sur la page instruction
Alors je suis sur la page "Demandes et habilitations"
Et il y a un message d'erreur contenant "Vous n'avez pas le droit d'accéder à cette page"

Scénario: En tant qu'instructeur, je peux accéder à la page d'instruction
Sachant que je suis un instructeur "API Entreprise"
Et que je me connecte
Et que je vais sur la page instruction
Alors je suis sur l'espace instruction

Scénario: En tant que rapporteur, je peux accéder à la page d'instruction
Sachant que je suis un rapporteur "API Entreprise"
Et que je me connecte
Et que je vais sur la page instruction
Alors je suis sur l'espace instruction

Scénario: En tant qu'instructeur, je ne peux pas accéder à la page d'administration
Sachant que je suis un instructeur "API Entreprise"
Et que je me connecte
Et que je vais sur l'espace administrateur
Alors je suis sur la page "Demandes et habilitations"
Et il y a un message d'erreur contenant "Vous n'avez pas le droit d'accéder à cette page"

Scénario: En tant que rapporteur, je ne peux pas accéder à la page d'administration
Sachant que je suis un rapporteur "API Entreprise"
Et que je me connecte
Et que je vais sur l'espace administrateur
Alors je suis sur la page "Demandes et habilitations"
Et il y a un message d'erreur contenant "Vous n'avez pas le droit d'accéder à cette page"

Scénario: En tant qu'administrateur, je peux accéder à l'espace administration
Sachant que je suis un administrateur
Et que je me connecte
Et que je vais sur l'espace administrateur
Alors je suis sur l'espace administrateur

25 changes: 25 additions & 0 deletions features/admin/emails_verifies.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# language: fr

Fonctionnalité: Espace admin: emails en liste blanche
En tant qu'administrateur, je peux voir les emails en liste blanche et en ajouter des supplémentaires,
dans le cas où on nous contacte au support et qu'on nous certifie que l'email est bien valide

Contexte:
Sachant que je suis un administrateur
Et que je me connecte

Scénario: Je peux consulter les emails en liste blanche
Quand il y a l'email "[email protected]" marqué en tant que "liste blanche"
Et qu'il y a l'email "[email protected]" marqué en tant que "délivrable"
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é"

11 changes: 11 additions & 0 deletions features/step_definitions/admin_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Quand("je me rends sur le module {string} de l'espace administrateur") do |path|
visit "/admin/#{path.parameterize}"
end

Quand("je vais sur l'espace administrateur") do
visit admin_path
end

Alors("je suis sur l'espace administrateur") do
expect(page).to have_current_path(/admin/)
end
3 changes: 3 additions & 0 deletions features/step_definitions/instructions_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Alors("je suis sur l'espace instruction") do
expect(page).to have_current_path(/instruction/)
end
15 changes: 15 additions & 0 deletions features/step_definitions/login_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def mock_mon_compte_pro(user)
end
end

Sachantque('je suis un administrateur') do
user = create_admin

if @current_user_email.blank?
@current_user_email = user.email
mock_mon_compte_pro(user)
end

if @current_user_email != user.email
current_user.roles << 'admin'
current_user.roles.uniq!
current_user.save!
end
end

Sachantque('je me connecte') do
steps %(
Quand je me rends sur la page d'accueil
Expand Down
10 changes: 10 additions & 0 deletions features/step_definitions/whitelisted_verified_emails_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Quand("il y a l'email {string} marqué en tant que {string}") do |email, kind|
case kind
when 'délivrable'
status = 'deliverable'
when 'liste blanche'
status = 'whitelisted'
end

create(:verified_email, email:, status:)
end
Loading
Loading