diff --git a/app/assets/javascripts/new_design/direct_uploads.js b/app/assets/javascripts/new_design/direct_uploads.js
index 47b5aa23c..d85df6d4b 100644
--- a/app/assets/javascripts/new_design/direct_uploads.js
+++ b/app/assets/javascripts/new_design/direct_uploads.js
@@ -44,14 +44,26 @@ addEventListener("direct-upload:end", function (event) {
element.classList.add("direct-upload--complete");
});
-addEventListener('load', function() {
+addEventListener('turbolinks:load', function() {
var submitButtons = document.querySelectorAll('form button[type=submit][data-action]');
var hiddenInput = document.querySelector('form input[type=hidden][name=submit_action]');
submitButtons = [].slice.call(submitButtons);
submitButtons.forEach(function(button) {
button.addEventListener('click', function() {
- hiddenInput.value = button.getAttribute('data-action');
+ // Active Storage will intercept the form.submit event to upload
+ // the attached files, and then fire the submit action again – but forgetting
+ // which button was clicked. So we manually set the type of action that trigerred
+ // the form submission.
+ var action = button.getAttribute('data-action');
+ hiddenInput.value = action;
+ // Some form fields are marked as mandatory, but when saving a draft we don't want them
+ // to be enforced by the browser.
+ if (action === 'submit') {
+ button.form.removeAttribute('novalidate');
+ } else {
+ button.form.setAttribute('novalidate', 'novalidate');
+ }
});
});
});
diff --git a/app/assets/stylesheets/new_design/card.scss b/app/assets/stylesheets/new_design/card.scss
index 01866755d..61128cb72 100644
--- a/app/assets/stylesheets/new_design/card.scss
+++ b/app/assets/stylesheets/new_design/card.scss
@@ -5,6 +5,7 @@
padding: ($default-spacer * 3) ($default-spacer * 2);
border: 1px solid $border-grey;
margin-bottom: $default-spacer * 2;
+ background: #FFFFFF;
.card-title {
font-weight: bold;
diff --git a/app/assets/stylesheets/new_design/utils.scss b/app/assets/stylesheets/new_design/utils.scss
index 44d53176c..5b7d2856f 100644
--- a/app/assets/stylesheets/new_design/utils.scss
+++ b/app/assets/stylesheets/new_design/utils.scss
@@ -35,6 +35,16 @@
margin: 60px 0;
}
+.empty-text-details {
+ margin-bottom: 60px;
+ text-align: center;
+
+ .empty-text + & {
+ margin-top: -50px;
+ }
+}
+
+
.highlighted {
background: $orange-bg;
color: $black;
diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb
index a446570da..caf048db7 100644
--- a/app/controllers/api/v1/dossiers_controller.rb
+++ b/app/controllers/api/v1/dossiers_controller.rb
@@ -47,6 +47,6 @@ class API::V1::DossiersController < APIController
end
def per_page # inherited value from will_paginate
- [params[:resultats_par_page] || DEFAULT_PAGE_SIZE, 1000].min
+ [params[:resultats_par_page]&.to_i || DEFAULT_PAGE_SIZE, 1000].min
end
end
diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb
index 361eb3765..df860054b 100644
--- a/app/controllers/new_user/dossiers_controller.rb
+++ b/app/controllers/new_user/dossiers_controller.rb
@@ -72,7 +72,7 @@ module NewUser
elsif draft?
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
render :modifier
- elsif @dossier.brouillon?
+ elsif @dossier.can_transition_to_en_construction?
@dossier.en_construction!
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
@@ -88,8 +88,8 @@ module NewUser
end
def index
- @user_dossiers = current_user.dossiers.includes(:procedure).page(page)
- @dossiers_invites = current_user.dossiers_invites.includes(:procedure).page(page)
+ @user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
+ @dossiers_invites = current_user.dossiers_invites.includes(:procedure).order_by_updated_at.page(page)
@current_tab = current_tab(@user_dossiers.count, @dossiers_invites.count)
@@ -107,7 +107,7 @@ module NewUser
if !dossier.instruction_commencee?
dossier.delete_and_keep_track
flash.notice = 'Votre dossier a bien été supprimé.'
- redirect_to users_dossiers_path
+ redirect_to dossiers_path
else
flash.notice = "L'instruction de votre dossier a commencé, il n'est plus possible de supprimer votre dossier. Si vous souhaitez annuler l'instruction contactez votre administration par la messagerie de votre dossier."
redirect_to users_dossier_path(dossier)
@@ -123,7 +123,7 @@ module NewUser
def ensure_dossier_can_be_updated
if !dossier.can_be_updated_by_the_user?
flash.alert = 'Votre dossier ne peut plus être modifié'
- redirect_to users_dossiers_path
+ redirect_to dossiers_path
end
end
diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb
index 5e70939c1..b22b7a8c5 100644
--- a/app/controllers/root_controller.rb
+++ b/app/controllers/root_controller.rb
@@ -7,7 +7,7 @@ class RootController < ApplicationController
elsif gestionnaire_signed_in?
return redirect_to gestionnaire_procedures_path
elsif user_signed_in?
- return redirect_to users_dossiers_path
+ return redirect_to dossiers_path
elsif administration_signed_in?
return redirect_to manager_root_path
end
diff --git a/app/controllers/users/dossiers/add_siret_controller.rb b/app/controllers/users/dossiers/add_siret_controller.rb
index 59bfd936c..35251ed3f 100644
--- a/app/controllers/users/dossiers/add_siret_controller.rb
+++ b/app/controllers/users/dossiers/add_siret_controller.rb
@@ -8,6 +8,6 @@ class Users::Dossiers::AddSiretController < ApplicationController
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
- redirect_to url_for users_dossiers_path
+ redirect_to url_for dossiers_path
end
end
diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb
index 89ac80a3c..903a15f75 100644
--- a/app/controllers/users/dossiers/invites_controller.rb
+++ b/app/controllers/users/dossiers/invites_controller.rb
@@ -12,6 +12,6 @@ class Users::Dossiers::InvitesController < UsersController
render 'users/recapitulatif/show'
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
- redirect_to url_for users_dossiers_path
+ redirect_to url_for dossiers_path
end
end
diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb
index d9e1dd609..46e1e5b98 100644
--- a/app/controllers/users/dossiers_controller.rb
+++ b/app/controllers/users/dossiers_controller.rb
@@ -104,7 +104,7 @@ class Users::DossiersController < UsersController
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
- redirect_to url_for users_dossiers_path
+ redirect_to url_for dossiers_path
end
def siret_informations
@@ -133,7 +133,7 @@ class Users::DossiersController < UsersController
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
- redirect_to url_for users_dossiers_path
+ redirect_to url_for dossiers_path
end
def change_siret
@@ -181,7 +181,7 @@ class Users::DossiersController < UsersController
dossier.destroy
flash.notice = 'Brouillon supprimé'
end
- redirect_to url_for users_dossiers_path(liste: 'brouillon')
+ redirect_to url_for dossiers_path
end
def text_summary
@@ -229,7 +229,7 @@ class Users::DossiersController < UsersController
def error_procedure
flash.alert = t('errors.messages.procedure_not_found')
- redirect_to url_for users_dossiers_path
+ redirect_to url_for dossiers_path
end
def update_current_user_siret!(siret)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 72b29f510..46bae9be5 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -25,7 +25,7 @@ module ApplicationHelper
when :gestionnaire
gestionnaire_procedures_path
when :user
- users_dossiers_path
+ dossiers_path
else
root_path
end
diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb
index 8e2bc2b35..9baaf6d16 100644
--- a/app/helpers/dossier_helper.rb
+++ b/app/helpers/dossier_helper.rb
@@ -14,4 +14,18 @@ module DossierHelper
"highlighted"
end
end
+
+ def url_for_dossier(dossier)
+ if dossier.kind_of? Invite
+ users_dossiers_invite_path(id: dossier.id)
+ elsif dossier.brouillon?
+ modifier_dossier_path(dossier)
+ else
+ users_dossier_recapitulatif_path(dossier)
+ end
+ end
+
+ def dossier_submission_is_closed?(dossier)
+ dossier.brouillon? && dossier.procedure.archivee?
+ end
end
diff --git a/app/models/dossier.rb b/app/models/dossier.rb
index a6452b395..1cf543a63 100644
--- a/app/models/dossier.rb
+++ b/app/models/dossier.rb
@@ -167,6 +167,10 @@ class Dossier < ApplicationRecord
!(procedure.archivee? && brouillon?)
end
+ def can_transition_to_en_construction?
+ !procedure.archivee? && brouillon?
+ end
+
def can_be_updated_by_the_user?
brouillon? || en_construction?
end
diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml
index a5c6f5883..25f715ee8 100644
--- a/app/views/layouts/_new_header.haml
+++ b/app/views/layouts/_new_header.haml
@@ -36,7 +36,7 @@
- if nav_bar_profile == :user
%ul.header-tabs
%li
- = active_link_to "Dossiers", users_dossiers_path, active: :inclusive, class: 'tab-link'
+ = active_link_to "Dossiers", dossiers_path, active: :inclusive, class: 'tab-link'
%ul.header-right-content
- if nav_bar_profile == :gestionnaire && gestionnaire_signed_in?
@@ -63,7 +63,7 @@
- if SwitchDeviseProfileService.new(warden).multiple_devise_profile_connect?
- if user_signed_in? && nav_bar_profile != :user
%li
- = link_to users_dossiers_path, class: "menu-item menu-link" do
+ = link_to dossiers_path, class: "menu-item menu-link" do
= image_tag "icons/switch-profile.svg"
Passer en usager
- if gestionnaire_signed_in? && nav_bar_profile != :gestionnaire
diff --git a/app/views/layouts/_switch_devise_profile_module.html.haml b/app/views/layouts/_switch_devise_profile_module.html.haml
index a32ef804e..beaaa67da 100644
--- a/app/views/layouts/_switch_devise_profile_module.html.haml
+++ b/app/views/layouts/_switch_devise_profile_module.html.haml
@@ -6,7 +6,7 @@
%ul.dropdown-menu.dropdown-menu-left
- if user_signed_in?
%li
- = link_to(users_dossiers_path, id: :menu_item_procedure) do
+ = link_to(dossiers_path, id: :menu_item_procedure) do
%i.fa.fa-user
Usager
diff --git a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml
index 6f2031b6a..dd534209b 100644
--- a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml
+++ b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml
@@ -1,5 +1,5 @@
.link-to-dossiers
- = link_to 'retour aux dossiers', users_dossiers_path
+ = link_to 'retour aux dossiers', dossiers_path
#first-block
.en-cours
diff --git a/app/views/new_user/dossiers/identite.html.haml b/app/views/new_user/dossiers/identite.html.haml
index de65aefb1..cef41586f 100644
--- a/app/views/new_user/dossiers/identite.html.haml
+++ b/app/views/new_user/dossiers/identite.html.haml
@@ -15,35 +15,38 @@
= h string_to_html(@dossier.procedure.description)
.column.identity-form
- = form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|
- %h1 Données d'identité
+ = render partial: "shared/dossiers/submit_is_over", locals: { dossier: @dossier }
- %p.mb-1 Merci de remplir vos informations personnelles pour accéder à la démarche.
+ - if !dossier_submission_is_closed?(@dossier)
+ = form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|
+ %h1 Données d'identité
- %label
- %span.mandatory *
- champs requis
+ %p.mb-1 Merci de remplir vos informations personnelles pour accéder à la démarche.
- = f.label :gender, class: "required"
- = f.select :gender, ['M.', 'Mme'], {}, class: "small"
-
- .flex
- .inline-champ
- = f.label :prenom, class: "required"
- = f.text_field :prenom, class: "small", required: true
- .inline-champ
- = f.label :nom, class: "required"
- = f.text_field :nom, class: "small", required: true
-
- - if @dossier.procedure.ask_birthday?
- = f.label :birthdate, class: "required"
- = f.date_field :birthdate, value: @dossier.individual.birthdate, placeholder: 'format : AAAA-MM-JJ', required: true, class: "small"
-
- = fields_for :dossier, @dossier do |df|
- = label_tag do
- = df.check_box :autorisation_donnees, required: true
- J'accepte
- = link_to "les CGU", CGU_URL, target: :blank
+ %label
%span.mandatory *
+ champs requis
- = f.submit "Continuer", class: "button large primary expand"
+ = f.label :gender, class: "required"
+ = f.select :gender, ['M.', 'Mme'], {}, class: "small"
+
+ .flex
+ .inline-champ
+ = f.label :prenom, class: "required"
+ = f.text_field :prenom, class: "small", required: true
+ .inline-champ
+ = f.label :nom, class: "required"
+ = f.text_field :nom, class: "small", required: true
+
+ - if @dossier.procedure.ask_birthday?
+ = f.label :birthdate, class: "required"
+ = f.date_field :birthdate, value: @dossier.individual.birthdate, placeholder: 'format : AAAA-MM-JJ', required: true, class: "small"
+
+ = fields_for :dossier, @dossier do |df|
+ = label_tag do
+ = df.check_box :autorisation_donnees, required: true
+ J'accepte
+ = link_to "les CGU", CGU_URL, target: :blank
+ %span.mandatory *
+
+ = f.submit "Continuer", class: "button large primary expand"
diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml
index 266cd06fb..84576f3e6 100644
--- a/app/views/new_user/dossiers/index.html.haml
+++ b/app/views/new_user/dossiers/index.html.haml
@@ -37,23 +37,24 @@
- @dossiers.each do |dossier|
%tr
%td.folder-col
- = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do
+ = link_to(url_for_dossier(dossier), class: 'cell-link') do
%span.icon.folder
%td.number-col
- = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do
+ = link_to(url_for_dossier(dossier), class: 'cell-link') do
= dossier.id
%td
- = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do
+ = link_to(url_for_dossier(dossier), class: 'cell-link') do
= dossier.procedure.libelle
%td.status-col
- = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do
+ = link_to(url_for_dossier(dossier), class: 'cell-link') do
= render partial: 'shared/dossiers/status', locals: { dossier: dossier }
%td.updated-at-col
- = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do
+ = link_to(url_for_dossier(dossier), class: 'cell-link') do
= dossier.updated_at.localtime.strftime("%d/%m/%Y")
= paginate(@dossiers)
- else
.dossiers-table-empty
%h2.empty-text Aucun dossier.
+ %p.empty-text-details Pour l’instant vous n’avez commencé aucune démarche.
= link_to "Commencer une nouvelle démarche", new_demarche_url, class: "button primary"
diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml
index af646f8b5..c40b7bd4c 100644
--- a/app/views/root/patron.html.haml
+++ b/app/views/root/patron.html.haml
@@ -201,3 +201,4 @@
.container
%h2.empty-text Aucun dossier
+ %p.empty-text-details Vous n’avez commencé aucune démarche pour l’instant.
diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml
index 73b41af2a..5149c0040 100644
--- a/app/views/shared/dossiers/_edit.html.haml
+++ b/app/views/shared/dossiers/_edit.html.haml
@@ -1,4 +1,6 @@
.container
+ = render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
+
- if notice_url(dossier.procedure).present?
%p
Pour vous aider à remplir votre dossier, vous pouvez consulter
@@ -9,7 +11,7 @@
- if apercu
- form_options = { url: '', method: :get, html: { class: 'form', multipart: true } }
- else
- - form_options = { html: { class: 'form', multipart: true } }
+ - form_options = { html: { class: 'form', multipart: true, novalidate: dossier.brouillon? } }
= form_for dossier, form_options do |f|
= f.fields_for :champs, dossier.champs do |champ_form|
@@ -58,7 +60,7 @@
class: 'button send',
data: { action: 'draft', disable_with: 'Envoi...' }
- - if current_user.owns?(dossier)
+ - if current_user.owns?(dossier) && dossier.can_transition_to_en_construction?
= f.button 'Soumettre le dossier',
class: 'button send primary',
data: { action: 'submit', disable_with: 'Envoi...' }
@@ -67,3 +69,5 @@
= f.button 'Enregistrer les modifications du dossier',
class: 'button send primary',
data: { action: 'submit', disable_with: 'Envoi...' }
+
+ = render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
diff --git a/app/views/shared/dossiers/_submit_is_over.html.haml b/app/views/shared/dossiers/_submit_is_over.html.haml
new file mode 100644
index 000000000..9d81a8a96
--- /dev/null
+++ b/app/views/shared/dossiers/_submit_is_over.html.haml
@@ -0,0 +1,8 @@
+- if dossier_submission_is_closed?(dossier)
+ .card.featured
+ .card-title
+ Le dépôt de dossier est fermé
+ - if dossier.procedure.archived_at.present?
+ Il n'est plus possible de déposer de dossier pour cette démarche en ligne depuis le #{dossier.procedure.archived_at.strftime("%d/%m/%Y")}.
+ - else
+ Il n'est plus possible de déposer de dossier pour cette démarche en ligne.
diff --git a/app/views/users/confirmations/new.html.erb b/app/views/users/confirmations/new.html.erb
index 3df9635f9..fbcac0308 100644
--- a/app/views/users/confirmations/new.html.erb
+++ b/app/views/users/confirmations/new.html.erb
@@ -1,4 +1,4 @@
-
Resend confirmation instructions
+Renvoyer les instructions de confirmation de compte
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
@@ -9,7 +9,7 @@
- <%= f.submit "Resend confirmation instructions" %>
+ <%= f.submit "Renvoyer les instructions de confirmation" %>
<% end %>
diff --git a/app/views/users/unlocks/new.html.erb b/app/views/users/unlocks/new.html.erb
deleted file mode 100644
index 1eefabbb8..000000000
--- a/app/views/users/unlocks/new.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-Resend unlock instructions
-
-<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
- <%= devise_error_messages! %>
-
-
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true %>
-
-
-
- <%= f.submit "Resend unlock instructions" %>
-
-<% end %>
-
-<%= render "users/shared/links" %>
diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb
index 44ff98fad..38d815593 100644
--- a/spec/controllers/api/v1/dossiers_controller_spec.rb
+++ b/spec/controllers/api/v1/dossiers_controller_spec.rb
@@ -61,6 +61,13 @@ describe API::V1::DossiersController do
it { expect(subject[:nombre_de_page]).to eq(1) }
end
+ describe 'with custom resultats_par_page' do
+ let(:retour) { get :index, params: { token: admin.api_token, procedure_id: procedure_id, resultats_par_page: 18 } }
+ subject { body[:pagination] }
+ it { is_expected.to have_key(:resultats_par_page) }
+ it { expect(subject[:resultats_par_page]).to eq(18) }
+ end
+
describe 'dossiers' do
subject { body[:dossiers] }
it { expect(subject).to be_an(Array) }
diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb
index 5be0295da..17802c563 100644
--- a/spec/controllers/new_user/dossiers_controller_spec.rb
+++ b/spec/controllers/new_user/dossiers_controller_spec.rb
@@ -150,8 +150,8 @@ describe NewUser::DossiersController, type: :controller do
let(:individual_params) { { gender: 'M', nom: 'Mouse', prenom: 'Mickey' } }
let(:dossier_params) { { autorisation_donnees: true } }
- it 'redirects to user_dossiers_path' do
- expect(response).to redirect_to(users_dossiers_path)
+ it 'redirects to the dossiers list' do
+ expect(response).to redirect_to(dossiers_path)
expect(flash.alert).to eq('Votre dossier ne peut plus être modifié')
end
end
@@ -225,20 +225,33 @@ describe NewUser::DossiersController, type: :controller do
context 'when the dossier cannot be updated by the user' do
let!(:dossier) { create(:dossier, :en_instruction, user: user) }
- it 'redirects to user_dossiers_path' do
+ it 'redirects to the dossiers list' do
subject
- expect(response).to redirect_to(users_dossiers_path)
+ expect(response).to redirect_to(dossiers_path)
expect(flash.alert).to eq('Votre dossier ne peut plus être modifié')
end
end
- it 'updates the champs' do
- subject
+ context 'when dossier can be updated by the owner' do
+ it 'updates the champs' do
+ subject
- expect(response).to redirect_to(merci_dossier_path(dossier))
- expect(first_champ.reload.value).to eq('beautiful value')
- expect(dossier.reload.state).to eq('en_construction')
+ expect(response).to redirect_to(merci_dossier_path(dossier))
+ expect(first_champ.reload.value).to eq('beautiful value')
+ expect(dossier.reload.state).to eq('en_construction')
+ end
+
+ context "on an archived procedure" do
+ before { dossier.procedure.archive }
+
+ it "it does not change state" do
+ subject
+
+ expect(response).not_to redirect_to(merci_dossier_path(dossier))
+ expect(dossier.reload.state).to eq('brouillon')
+ end
+ end
end
it 'sends an email only on the first #update' do
@@ -405,6 +418,23 @@ describe NewUser::DossiersController, type: :controller do
it { expect(assigns(:current_tab)).to eq('mes-dossiers') }
end
end
+
+ describe 'sort order' do
+ before do
+ Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
+ Timecop.freeze(2.days.ago) { create(:dossier, user: user) }
+ Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
+ Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
+ get(:index)
+ end
+
+ it 'displays the most recently updated dossiers first' do
+ expect(assigns(:user_dossiers).first.updated_at.to_date).to eq(2.days.ago.to_date)
+ expect(assigns(:user_dossiers).second.updated_at.to_date).to eq(4.days.ago.to_date)
+ expect(assigns(:dossiers_invites).first.updated_at.to_date).to eq(2.days.ago.to_date)
+ expect(assigns(:dossiers_invites).second.updated_at.to_date).to eq(4.days.ago.to_date)
+ end
+ end
end
describe '#ask_deletion' do
@@ -444,7 +474,7 @@ describe NewUser::DossiersController, type: :controller do
expect(procedure.deleted_dossiers.first.dossier_id).to eq(dossier_id)
end
- it { is_expected.to redirect_to(users_dossiers_path) }
+ it { is_expected.to redirect_to(dossiers_path) }
context "and the instruction has started" do
let(:dossier) { create(:dossier, :en_instruction, user: user, autorisation_donnees: true) }
diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb
index 1c81e267b..b1f7fb15a 100644
--- a/spec/controllers/root_controller_spec.rb
+++ b/spec/controllers/root_controller_spec.rb
@@ -8,7 +8,7 @@ describe RootController, type: :controller do
sign_in create(:user)
end
- it { expect(subject).to redirect_to(users_dossiers_path) }
+ it { expect(subject).to redirect_to(dossiers_path) }
end
context 'when Gestionnaire is connected' do
diff --git a/spec/controllers/users/dossiers/add_siret_controller_spec.rb b/spec/controllers/users/dossiers/add_siret_controller_spec.rb
index de449881c..9a191b47d 100644
--- a/spec/controllers/users/dossiers/add_siret_controller_spec.rb
+++ b/spec/controllers/users/dossiers/add_siret_controller_spec.rb
@@ -11,7 +11,7 @@ describe Users::Dossiers::AddSiretController, type: :controller do
subject { get :show, params: { dossier_id: dossier.id } }
context 'when dossier is not attached at a procedure with individual siret attribut' do
- it { is_expected.to redirect_to users_dossiers_path }
+ it { is_expected.to redirect_to dossiers_path }
end
context 'when dossier is attached at a procedure with individual siret attribut' do
diff --git a/spec/controllers/users/dossiers/invites_controller_spec.rb b/spec/controllers/users/dossiers/invites_controller_spec.rb
index a02810436..90e61899c 100644
--- a/spec/controllers/users/dossiers/invites_controller_spec.rb
+++ b/spec/controllers/users/dossiers/invites_controller_spec.rb
@@ -72,7 +72,7 @@ describe Users::Dossiers::InvitesController, type: :controller do
let(:email) { 'fake@email.com' }
it { expect(subject.status).to eq 302 }
- it { is_expected.to redirect_to users_dossiers_path }
+ it { is_expected.to redirect_to dossiers_path }
end
end
end
diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb
index d70e19c30..1d2ff4572 100644
--- a/spec/controllers/users/dossiers_controller_spec.rb
+++ b/spec/controllers/users/dossiers_controller_spec.rb
@@ -120,7 +120,7 @@ describe Users::DossiersController, type: :controller do
context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived_at: Time.now) }
- it { is_expected.to redirect_to users_dossiers_path }
+ it { is_expected.to redirect_to dossiers_path }
end
end
context 'when user is not logged' do
@@ -136,7 +136,7 @@ describe Users::DossiersController, type: :controller do
sign_in user
end
- it { is_expected.to redirect_to users_dossiers_path }
+ it { is_expected.to redirect_to dossiers_path }
end
context 'when procedure is not published' do
@@ -146,7 +146,7 @@ describe Users::DossiersController, type: :controller do
sign_in user
end
- it { is_expected.to redirect_to users_dossiers_path }
+ it { is_expected.to redirect_to dossiers_path }
end
end
end
diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb
index b9145ab37..26acaa12d 100644
--- a/spec/features/new_user/dossier_spec.rb
+++ b/spec/features/new_user/dossier_spec.rb
@@ -84,7 +84,7 @@ feature 'The user' do
end
let(:simple_procedure) do
- tdcs = [create(:type_de_champ, mandatory: true, libelle: 'text')]
+ tdcs = [create(:type_de_champ, mandatory: true, libelle: 'texte obligatoire')]
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end
@@ -92,19 +92,23 @@ feature 'The user' do
log_in(user.email, password, simple_procedure)
fill_individual
+ # Check an incomplete dossier can be saved as a draft, even when mandatory fields are missing
click_on 'Enregistrer le brouillon'
+ expect(user_dossier.reload.brouillon?).to be(true)
expect(page).to have_content('Votre brouillon a bien été sauvegardé')
expect(page).to have_current_path(dossier_path(user_dossier))
+ # Check an incomplete dossier cannot be submitted when mandatory fields are missing
click_on 'Soumettre le dossier'
expect(user_dossier.reload.brouillon?).to be(true)
expect(page).to have_current_path(dossier_path(user_dossier))
- fill_in('text', with: 'super texte')
+ # Check a dossier can be submitted when all mandatory fields are filled
+ fill_in('texte obligatoire', with: 'super texte')
click_on 'Soumettre le dossier'
expect(user_dossier.reload.en_construction?).to be(true)
- expect(champ_value_for('text')).to eq('super texte')
+ expect(champ_value_for('texte obligatoire')).to eq('super texte')
expect(page).to have_current_path(merci_dossier_path(user_dossier))
end
diff --git a/spec/features/users/drawing_a_zone_with_freedraw_spec.rb b/spec/features/users/drawing_a_zone_with_freedraw_spec.rb
index a7e54ce25..ef7fe3c92 100644
--- a/spec/features/users/drawing_a_zone_with_freedraw_spec.rb
+++ b/spec/features/users/drawing_a_zone_with_freedraw_spec.rb
@@ -45,7 +45,7 @@ feature 'drawing a zone with freedraw' do
let(:module_api_carto) { create(:module_api_carto) }
scenario 'he is redirect to user dossiers index' do
- expect(page).to have_css('#users-index')
+ expect(page).to have_css('.dossiers-table')
end
scenario 'alert message is present' do
diff --git a/spec/features/users/list_dossiers_spec.rb b/spec/features/users/list_dossiers_spec.rb
index 195e80a72..8341291df 100644
--- a/spec/features/users/list_dossiers_spec.rb
+++ b/spec/features/users/list_dossiers_spec.rb
@@ -6,8 +6,12 @@ describe 'user access to the list of his dossier' do
let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: 'en_construction') }
let!(:dossier2) { create(:dossier, :with_entreprise) }
let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: 'en_construction') }
+ let(:dossiers_per_page) { 25 }
before do
+ @default_per_page = Dossier.default_per_page
+ Dossier.paginates_per dossiers_per_page
+
last_updated_dossier.update_column(:updated_at, "19/07/2052 15:35".to_time)
visit new_user_session_path
@@ -18,29 +22,47 @@ describe 'user access to the list of his dossier' do
end
end
+ after do
+ Dossier.paginates_per @default_per_page
+ end
+
it 'the list of dossier is displayed' do
expect(page).to have_content(dossier1.procedure.libelle)
+ expect(page).to have_content('en construction')
+ end
+
+ it 'dossiers belonging to other users are not displayed' do
expect(page).not_to have_content(dossier2.procedure.libelle)
end
- it 'the list must be order by last updated' do
+ it 'the list must be ordered by last updated' do
expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier1.procedure.libelle}/m)
end
- it 'should list archived dossier' do
+ it 'should list archived dossiers' do
expect(page).to have_content(dossier_archived.procedure.libelle)
end
- it 'the state of dossier is displayed' do
- expect(page).to have_css("#dossier_#{dossier1.id}_state")
- end
-
context 'when user clicks on a projet in list', js: true do
before do
- page.find("#tr_dossier_#{dossier1.id}").click
+ page.click_on(dossier1.procedure.libelle)
end
scenario 'user is redirected to dossier page' do
expect(page).to have_css('#users-recapitulatif-dossier-show')
end
end
+
+ context 'when there is more than one page' do
+ let(:dossiers_per_page) { 2 }
+
+ scenario 'the user can navigate through the other pages', js: true do
+ page.click_link("Suivant")
+ expect(page).to have_content(dossier_archived.procedure.libelle)
+ end
+
+ scenario 'the user sees a card asking for feedback' do
+ expect(page).to have_css('.card.feedback')
+ expect(page).to have_content(CONTACT_EMAIL)
+ end
+ end
end
diff --git a/spec/helpers/dossier_helper_spec.rb b/spec/helpers/dossier_helper_spec.rb
index 0ceec6d96..c2aa7d0d4 100644
--- a/spec/helpers/dossier_helper_spec.rb
+++ b/spec/helpers/dossier_helper_spec.rb
@@ -25,4 +25,80 @@ RSpec.describe DossierHelper, type: :helper do
it { is_expected.to eq nil }
end
end
+
+ describe ".url_for_dossier" do
+ subject { url_for_dossier(dossier) }
+
+ context "when the dossier is an invitation" do
+ let(:dossier) { create(:invite) }
+ it { is_expected.to eq "/users/dossiers/invites/#{dossier.id}" }
+ end
+
+ context "when the dossier is in the brouillon state" do
+ let(:dossier) { create(:dossier, state: 'brouillon') }
+ it { is_expected.to eq "/dossiers/#{dossier.id}/modifier" }
+ end
+
+ context "when the dossier is any other state" do
+ let(:dossier) { create(:dossier, state: 'en_construction') }
+ it { is_expected.to eq "/users/dossiers/#{dossier.id}/recapitulatif" }
+ end
+ end
+
+ describe ".dossier_submission_is_closed?" do
+ let(:dossier) { create(:dossier, state: state) }
+ let(:state) { "brouillon" }
+
+ subject { dossier_submission_is_closed?(dossier) }
+
+ context "when dossier state is brouillon" do
+ it { is_expected.to be false }
+
+ context "when dossier state is brouillon and procedure is archivee" do
+ before { dossier.procedure.archive }
+
+ it { is_expected.to be true }
+ end
+ end
+
+ shared_examples_for "returns false" do
+ it { is_expected.to be false }
+
+ context "and procedure is archivee" do
+ before { dossier.procedure.archive }
+
+ it { is_expected.to be false }
+ end
+ end
+
+ context "when dossier state is en_construction" do
+ let(:state) { "en_construction" }
+
+ it_behaves_like "returns false"
+ end
+
+ context "when dossier state is en_construction" do
+ let(:state) { "en_instruction" }
+
+ it_behaves_like "returns false"
+ end
+
+ context "when dossier state is en_construction" do
+ let(:state) { "accepte" }
+
+ it_behaves_like "returns false"
+ end
+
+ context "when dossier state is en_construction" do
+ let(:state) { "refuse" }
+
+ it_behaves_like "returns false"
+ end
+
+ context "when dossier state is en_construction" do
+ let(:state) { "sans_suite" }
+
+ it_behaves_like "returns false"
+ end
+ end
end
diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb
index cebaea315..829009f61 100644
--- a/spec/models/dossier_spec.rb
+++ b/spec/models/dossier_spec.rb
@@ -835,4 +835,46 @@ describe Dossier do
}.to have_enqueued_job(WebHookJob)
end
end
+
+ describe "#can_transition_to_en_construction?" do
+ let(:procedure) { create(:procedure, :published) }
+ let(:dossier) { create(:dossier, state: state, procedure: procedure) }
+
+ subject { dossier.can_transition_to_en_construction? }
+
+ context "dossier state is brouillon" do
+ let(:state) { "brouillon" }
+ it { is_expected.to be true }
+
+ context "procedure is archived" do
+ before { procedure.archive }
+ it { is_expected.to be false }
+ end
+ end
+
+ context "dossier state is en_construction" do
+ let(:state) { "en_construction" }
+ it { is_expected.to be false }
+ end
+
+ context "dossier state is en_instruction" do
+ let(:state) { "en_instruction" }
+ it { is_expected.to be false }
+ end
+
+ context "dossier state is en_instruction" do
+ let(:state) { "accepte" }
+ it { is_expected.to be false }
+ end
+
+ context "dossier state is en_instruction" do
+ let(:state) { "refuse" }
+ it { is_expected.to be false }
+ end
+
+ context "dossier state is en_instruction" do
+ let(:state) { "sans_suite" }
+ it { is_expected.to be false }
+ end
+ end
end
diff --git a/spec/views/layouts/_new_header_spec.rb b/spec/views/layouts/_new_header_spec.rb
index 49fd3345a..9cf454c1a 100644
--- a/spec/views/layouts/_new_header_spec.rb
+++ b/spec/views/layouts/_new_header_spec.rb
@@ -14,8 +14,8 @@ describe 'layouts/_new_header.html.haml', type: :view do
let(:user) { create(:user) }
let(:profile) { :user }
- it { is_expected.to have_css("a.header-logo[href=\"#{users_dossiers_path}\"]") }
- it { is_expected.to have_link("Dossiers", href: users_dossiers_path) }
+ it { is_expected.to have_css("a.header-logo[href=\"#{dossiers_path}\"]") }
+ it { is_expected.to have_link("Dossiers", href: dossiers_path) }
end
context 'when rendering for gestionnaire' do
diff --git a/spec/views/new_user/dossiers/index.html.haml_spec.rb b/spec/views/new_user/dossiers/index.html.haml_spec.rb
index 2b53ab43f..3df0520b7 100644
--- a/spec/views/new_user/dossiers/index.html.haml_spec.rb
+++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb
@@ -2,7 +2,9 @@ require 'spec_helper'
describe 'new_user/dossiers/index.html.haml', type: :view do
let(:user) { create(:user) }
- let(:user_dossiers) { create_list(:dossier, 2, state: 'brouillon', user: user) }
+ let(:dossier_brouillon) { create(:dossier, state: 'brouillon', user: user) }
+ let(:dossier_en_construction) { create(:dossier, state: 'en_construction', user: user) }
+ let(:user_dossiers) { [dossier_brouillon, dossier_en_construction] }
let(:dossiers_invites) { [] }
let(:current_tab) { 'mes-dossiers' }
@@ -21,9 +23,13 @@ describe 'new_user/dossiers/index.html.haml', type: :view do
it 'affiche les informations des dossiers' do
dossier = user_dossiers.first
- expect(rendered).to have_text(dossier.id)
- expect(rendered).to have_text(dossier.procedure.libelle)
- expect(rendered).to have_link(dossier.id, href: users_dossier_recapitulatif_path(dossier))
+ expect(rendered).to have_text(dossier_brouillon.id)
+ expect(rendered).to have_text(dossier_brouillon.procedure.libelle)
+ expect(rendered).to have_link(dossier_brouillon.id, href: modifier_dossier_path(dossier_brouillon))
+
+ expect(rendered).to have_text(dossier_en_construction.id)
+ expect(rendered).to have_text(dossier_en_construction.procedure.libelle)
+ expect(rendered).to have_link(dossier_en_construction.id, href: users_dossier_recapitulatif_path(dossier_en_construction))
end
context 'quand il n’y a aucun dossier' do