Skip to content

Commit 829aba7

Browse files
committed
Implement new user dashboard
Have to change request specs, we have 2 redirects now Closes https://linear.app/pole-api/issue/API-2120
1 parent c6e34a8 commit 829aba7

15 files changed

+175
-56
lines changed
+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
class DashboardController < AuthenticatedUserController
2-
def index; end
2+
layout 'dashboard'
3+
4+
def index
5+
redirect_to dashboard_show_path(id: 'moi')
6+
end
7+
8+
def show
9+
case params[:id]
10+
when 'moi'
11+
@authorization_requests = policy_scope(AuthorizationRequest).where(applicant: current_user)
12+
when 'organisation'
13+
@authorization_requests = policy_scope(AuthorizationRequest)
14+
when 'mentions'
15+
@authorization_requests = AuthorizationRequestsMentionsQuery.new(current_user).perform
16+
else
17+
redirect_to dashboard_show_path(id: 'moi')
18+
end
19+
end
320
end

app/policies/application_policy.rb

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def destroy?
3737
delegate :current_organization, to: :user
3838

3939
class Scope
40+
delegate :current_organization, to: :user
41+
4042
def initialize(user, scope)
4143
@user = user
4244
@scope = scope

app/policies/authorization_request_policy.rb

+6
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ def unicity_constraint_violated?
3535
def another_authorization_request_with_same_type_exists?
3636
current_organization.authorization_requests.where(type: record.to_s).any?
3737
end
38+
39+
class Scope < Scope
40+
def resolve
41+
scope.where(organization: current_organization)
42+
end
43+
end
3844
end

app/views/dashboard/index.html.erb

-34
This file was deleted.

app/views/dashboard/show.html.erb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<% if @authorization_requests.any? %>
2+
<% if @authorization_requests.changes_requested.any? %>
3+
<%= render partial: 'authorization_requests', locals: { authorization_requests: @authorization_requests.changes_requested, kind: 'changes_requested' } %>
4+
<% end %>
5+
6+
<% if @authorization_requests.validated_or_refused.any? %>
7+
<%= render partial: 'authorization_requests', locals: { authorization_requests: @authorization_requests.validated_or_refused, kind: 'validated_or_refused' } %>
8+
<% end %>
9+
10+
<% if @authorization_requests.drafts.any? %>
11+
<%= render partial: 'authorization_requests', locals: { authorization_requests: @authorization_requests.drafts, kind: 'draft' } %>
12+
<% end %>
13+
14+
<% if @authorization_requests.in_instructions.any? %>
15+
<%= render partial: 'authorization_requests', locals: { authorization_requests: @authorization_requests.in_instructions, kind: 'pending' } %>
16+
<% end %>
17+
<% else %>
18+
<h3 class="center">
19+
<%= t(".no_authorization_requests.#{params[:id]}") %>
20+
</h3>
21+
<% end %>

app/views/layouts/dashboard.html.erb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<%= content_for(:body) do %>
2+
<div class="sub-header">
3+
<h1 class="fr-m-0">
4+
<%= t('.title') %>
5+
</h1>
6+
7+
<div>
8+
<% if current_user.instructor? %>
9+
<%= link_to t('.instruction_cta'), instruction_path, class: %w(fr-btn fr-btn--secondary fr-icon-file-add-fill fr-btn--icon-left) %>
10+
<% end %>
11+
<%= link_to t('.new_authorization_request'), authorization_requests_path, class: %w(fr-btn fr-btn--secondary fr-icon-add-line fr-btn--icon-left) %>
12+
</div>
13+
</div>
14+
15+
<% tabs = ['moi', 'organisation', 'mentions'] %>
16+
17+
<div class="fr-tabs fr-pt-5w">
18+
<ul class="fr-tabs__list" role="tablist" aria-label="Menu secondaire">
19+
<% tabs.each do |id| %>
20+
<% path = dashboard_show_path(id:) %>
21+
22+
<li role="presentation">
23+
<%=
24+
link_to t(".tabs.#{id}.title"),
25+
path,
26+
class: [
27+
'fr-tabs__tab',
28+
],
29+
role: 'tab',
30+
id: "tab-#{id}",
31+
tabindex: current_page?(path) ? '0' : '-1',
32+
data: {
33+
turbo_frame: "tab-#{id}-panel",
34+
},
35+
aria: {
36+
selected: current_page?(path),
37+
controls: "tab-#{id}-panel"
38+
}
39+
%>
40+
</li>
41+
<% end %>
42+
</ul>
43+
44+
<% tabs.each do |id| %>
45+
<% path = dashboard_show_path(id:) %>
46+
47+
<turbo-frame id="tab-<%= id %>-panel" class="fr-tabs__panel fr-tabs__panel--selected" role="tabpanel" aria-labelledby="tab-<%= id %>" tabindex="0" data-turbo-action="advance">
48+
<% if current_page?(path) %>
49+
<%= yield %>
50+
<% else %>
51+
<%= render partial: 'shared/loader' %>
52+
<% end %>
53+
</turbo-frame>
54+
<% end %>
55+
</div>
56+
<% end %>
57+
58+
<%= render template: 'layouts/application' %>

config/locales/fr.yml

+17-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ fr:
3434
- annuaire-entreprises.data.gouv.fr
3535
- data.gouv.fr
3636

37+
dashboard:
38+
title: Accueil
39+
instruction_cta: Espace instruction
40+
new_authorization_request: Demander une nouvelle habilitation
41+
tabs:
42+
moi:
43+
title: Mes demandes ou habilitations
44+
organisation:
45+
title: Les demandes ou habilitations de l'organisation
46+
mentions:
47+
title: Mes mentions
48+
3749
instruction:
3850
authorization_request:
3951
tabs:
@@ -65,11 +77,11 @@ fr:
6577
title: Se connecter
6678

6779
dashboard:
68-
index:
69-
title: Accueil
70-
instruction_cta: Espace instruction
71-
new_authorization_request: Demander une nouvelle habilitation
72-
no_authorization_requests: Vous n'avez aucun habilitations ou demandes en cours.
80+
show:
81+
no_authorization_requests:
82+
moi: Vous n'avez aucune habilitation ou demande en cours.
83+
organisation: Votre organization ne possède aucune habilitation ou demande en cours.
84+
mentions: Vous n'êtes mentionné dans aucune habilitation ou demande en cours.
7385
authorization_requests:
7486
validated_or_refused_title: Mes habilitations
7587
draft_title: Demandes en brouillon

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
get 'compte/deconnexion', to: 'sessions#destroy', as: :signout
88

99
get '/tableau-de-bord', to: 'dashboard#index', as: :dashboard
10+
get '/tableau-de-bord/:id', to: 'dashboard#show', as: :dashboard_show
1011

1112
get '/compte', to: 'profile#edit', as: :profile
1213
patch '/compte', to: 'profile#update'

features/step_definitions/authorization_requests_steps.rb

+20-5
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,31 @@
5252

5353
visit instruction_authorization_request_path(authorization_request)
5454
else
55-
authorization_request = create_authorization_requests_with_status(type, status, 1, current_user).first
55+
authorization_request = create_authorization_requests_with_status(type, status, 1, applicant: current_user).first
5656

5757
visit authorization_request_path(authorization_request)
5858
end
5959
end
6060

61-
# https://rubular.com/r/AiBmvod6e8ssvO
62-
Quand(/(j'ai|il y a) (\d+) demandes? d'habilitation "([^"]+)" ?(?:en )?(.+)?/) do |who, count, type, status|
63-
applicant = who == 'j\'ai' ? current_user : nil
64-
create_authorization_requests_with_status(type, status, count, applicant)
61+
# https://rubular.com/r/t8v2hsttNnb9h3
62+
Quand(/(j'ai|il y a|mon organisation a) (\d+) demandes? d'habilitation "([^"]+)" ?(?:en )?(.+)?/) do |who, count, type, status|
63+
applicant = case who
64+
when 'j\'ai'
65+
current_user
66+
when 'mon organisation a'
67+
create(:user, current_organization: current_user.current_organization)
68+
end
69+
70+
create_authorization_requests_with_status(type, status, count, applicant:)
71+
end
72+
73+
Quand(/je suis mentionné dans (\d+) demandes? d'habilitation "([^"]+)" en tant que "([^"]+)"/) do |count, type, role_humanized|
74+
role = role_humanized.parameterize.underscore
75+
options = {
76+
"#{role}_email": current_user.email,
77+
}
78+
79+
create_authorization_requests_with_status(type, nil, count, options)
6580
end
6681

6782
# https://rubular.com/r/dRUFmK5dzDpjJv

features/support/authorization_request_helpers.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ def extract_state_from_french_status(status)
2424
end
2525

2626
# rubocop:disable Metrics/MethodLength
27-
def create_authorization_requests_with_status(type, status = nil, count = 1, applicant = nil)
28-
applicant ||= FactoryBot.create(:user)
27+
def create_authorization_requests_with_status(type, status = nil, count = 1, attributes = {})
28+
attributes[:applicant] ||= FactoryBot.create(:user)
2929

3030
if status
3131
FactoryBot.create_list(
3232
:authorization_request,
3333
count,
3434
extract_state_from_french_status(status),
3535
find_factory_trait_from_name(type),
36-
applicant:,
37-
organization: applicant.current_organization,
36+
organization: attributes[:applicant].current_organization,
37+
**attributes,
3838
)
3939
else
4040
FactoryBot.create_list(
4141
:authorization_request,
4242
count,
4343
find_factory_trait_from_name(type),
44-
applicant:,
45-
organization: applicant.current_organization,
44+
organization: attributes[:applicant].current_organization,
45+
**attributes,
4646
)
4747
end
4848
end

features/tableau_de_bord.feature

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,31 @@ Fonctionnalité: Tableau de bord
88
Sachant que je suis un demandeur
99
Et que je me connecte
1010

11-
Scénario: Je vois l'ensemble des habilitations quelque soit leur état
11+
Scénario: Je vois sur l'écran principal l'ensemble de mes habilitations quelque soit leur état
1212
Quand j'ai 1 demande d'habilitation "API Entreprise" en brouillon
1313
Et j'ai 1 demande d'habilitation "API Entreprise" en attente
1414
Et j'ai 1 demande d'habilitation "API Entreprise" refusée
1515
Et j'ai 1 demande d'habilitation "API Entreprise" validée
16+
Et que mon organisation a 1 demande d'habilitation "API Entreprise"
1617
Et que je vais sur la page du tableau de bord
1718
Alors je vois 4 demandes d'habilitation
19+
20+
Scénario: Je ne vois pas sur l'écran principal les habilitations de mon organisation
21+
Quand mon organisation a 1 demande d'habilitation "API Entreprise"
22+
Et que je vais sur la page du tableau de bord
23+
Alors je vois 0 demande d'habilitation
24+
25+
Scénario: Je vois toutes les habilitations de mon organization
26+
Quand mon organisation a 2 demandes d'habilitation "API Entreprise"
27+
Et que j'ai 1 demande d'habilitation "API Particulier"
28+
Et que je vais sur la page du tableau de bord
29+
Et que je clique sur "Les demandes ou habilitations de l'organisation"
30+
Alors je vois 3 demandes d'habilitations
31+
32+
Scénario: Je vois les habilitations où je suis mentionné
33+
Quand j'ai 3 demandes d'habilitation "API Entreprise"
34+
Et que mon organisation a 2 demandes d'habilitation "API Entreprise"
35+
Et que je suis mentionné dans 1 demande d'habilitation "API Entreprise" en tant que "Contact métier"
36+
Et que je vais sur la page du tableau de bord
37+
Et que je clique sur "Mes mentions"
38+

spec/features/authorization_requests/multiple_steps_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
submit_habilitation
134134
}.to change { authorization_request.reload.state }.to('submitted')
135135

136-
expect(page).to have_current_path(dashboard_path)
136+
expect(page).to have_current_path(/#{dashboard_path}/)
137137
end
138138
end
139139

spec/features/authorization_requests/submit_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
it 'does not allow access' do
2929
visit authorization_request_form_path(form_uid: authorization_request_form.uid, id: authorization_request.id)
3030

31-
expect(page).to have_current_path(dashboard_path, ignore_query: true)
31+
expect(page).to have_current_path(/#{dashboard_path}/)
3232
end
3333
end
3434
end

spec/requests/instruction_access_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
it 'can not access the instruction space' do
2828
visit_instruction
2929

30-
2.times { follow_redirect! }
30+
3.times { follow_redirect! }
3131

3232
expect(response.body).to include('pas le droit')
3333
end

spec/support/requests_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def sign_in(user)
2525
it do
2626
subject
2727

28-
follow_redirect!
28+
2.times { follow_redirect! }
2929

3030
expect(response.body).to include('pas le droit')
3131
end

0 commit comments

Comments
 (0)