diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index 78be9682c..1fe64d228 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -11,6 +11,7 @@ background-color: #FFFFFF; color: $black; cursor: pointer; + text-align: center; -webkit-appearance: none; &:hover { @@ -44,6 +45,18 @@ } } + &.danger { + color: $black; + border-color: $border-grey; + background-color: #FFFFFF; + + &:hover { + color: #FFFFFF; + border-color: $medium-red; + background-color: $medium-red; + } + } + &.accepted { color: #FFFFFF; border-color: $green; diff --git a/app/assets/stylesheets/new_design/forms.scss b/app/assets/stylesheets/new_design/forms.scss index ba7b16d39..5322c2f90 100644 --- a/app/assets/stylesheets/new_design/forms.scss +++ b/app/assets/stylesheets/new_design/forms.scss @@ -281,13 +281,44 @@ } .send-wrapper { - text-align: right; - margin-top: 2 * $default-padding; + display: flex; + width: 100%; + justify-content: flex-end; + margin-top: $default-padding; margin-bottom: 2 * $default-padding; .button { + margin-top: $default-padding; margin-bottom: 0; } + + // Wide layout: align buttons on a single row + @media (min-width: 550px) { + flex-direction: row; + + .button:not(:first-of-type) { + margin-left: $default-spacer; + } + + .button.danger { + margin-right: auto; + } + } + + // Narrow layout: stack buttons vertically + @media (max-width: 550px) { + flex-direction: column-reverse; + align-items: center; + + .button, + .button.danger { + width: 100%; + max-width: 350px; + line-height: 30px; + margin-left: none; + margin-right: none; + } + } } .inline-champ { diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 9e5d682a4..a969da1b3 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -17,6 +17,7 @@ module NewAdministrateur redirect_to services_path(procedure_id: params[:procedure_id]), notice: "#{new_service.nom} créé" else + @procedure = procedure flash[:alert] = new_service.errors.full_messages render :new end @@ -34,6 +35,7 @@ module NewAdministrateur redirect_to services_path(procedure_id: params[:procedure_id]), notice: "#{@service.nom} modifié" else + @procedure = procedure flash[:alert] = @service.errors.full_messages render :edit end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 1cf543a63..f91a0e245 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -276,8 +276,12 @@ class Dossier < ApplicationRecord now = Time.now deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now) update(hidden_at: now) + + administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email] + administration_emails.each do |email| + DossierMailer.notify_deletion_to_administration(deleted_dossier, email).deliver_later + end DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later - DossierMailer.notify_deletion_to_administration(deleted_dossier, procedure.administrateur.email).deliver_later end private diff --git a/app/views/dossiers/_edit_carto.html.haml b/app/views/dossiers/_edit_carto.html.haml index d0f57a8a9..fc7dff7e5 100644 --- a/app/views/dossiers/_edit_carto.html.haml +++ b/app/views/dossiers/_edit_carto.html.haml @@ -2,4 +2,4 @@ - if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier)) %a#maj_carte.action{ href: "/users/dossiers/#{@facade.dossier.id}/carte" } .col-lg-2.col-md-2.col-sm-2.col-xs-2.action - = 'ÉDITER' + = 'MODIFIER' diff --git a/app/views/dossiers/_edit_dossier.html.haml b/app/views/dossiers/_edit_dossier.html.haml index ecbed3cca..4f442527c 100644 --- a/app/views/dossiers/_edit_dossier.html.haml +++ b/app/views/dossiers/_edit_dossier.html.haml @@ -2,4 +2,4 @@ - if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier)) = link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do #edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action - = "ÉDITER" + = "MODIFIER" diff --git a/app/views/notification_mailer/closed_mail_with_attestation.html.haml b/app/views/notification_mailer/closed_mail_with_attestation.html.haml index 2cec1ca59..e1851d5db 100644 --- a/app/views/notification_mailer/closed_mail_with_attestation.html.haml +++ b/app/views/notification_mailer/closed_mail_with_attestation.html.haml @@ -14,7 +14,7 @@ Bonne journée, %p - L'équipe demarches-simplifiees.fr (anciennement Téléprocédures Simplifiées) + L'équipe demarches-simplifiees.fr %p — diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index e2d3e5ad7..be5252fce 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -49,7 +49,7 @@ = link_to ".button.secondary", "#", class: "button secondary" - = link_to ".button.accepted", "#", class: "button accepted" + = link_to ".button.danger", "#", class: "button danger" = link_to "#", class: "button" do %span.icon.follow @@ -58,6 +58,13 @@ = link_to "#", class: "button icon-only" do %span.icon.follow + %p + = link_to ".button.accepted", "#", class: "button accepted" + + = link_to ".button.refused", "#", class: "button refused" + + = link_to ".button.without-continuation", "#", class: "button without-continuation" + %p = link_to ".button.large", "#", class: "button large" diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index c975b16d2..eaf3e6c18 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -62,9 +62,16 @@ = hidden_field_tag 'submit_action', 'draft' - if dossier.brouillon? + - if current_user.owns?(dossier) + = link_to ask_deletion_dossier_path(dossier), + method: :post, + class: 'button danger', + data: { confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations qu’il contient. Toute suppression entraine l’annulation de la démarche en cours.\n\nConfirmer la suppression ?" } do + Supprimer le brouillon + = f.button 'Enregistrer le brouillon', formnovalidate: true, - class: 'button send', + class: 'button send secondary', data: { action: 'draft', disable_with: 'Envoi...' } - if current_user.owns?(dossier) && dossier.can_transition_to_en_construction? diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index 8bf213f79..3a2c4866b 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -1,5 +1,6 @@ describe NewAdministrateur::ServicesController, type: :controller do let(:admin) { create(:administrateur) } + let(:procedure) { create(:procedure, administrateur: admin) } describe '#create' do before do @@ -38,7 +39,7 @@ describe NewAdministrateur::ServicesController, type: :controller do end context 'when submitting an invalid service' do - let(:params) { { service: { nom: 'super service' } } } + let(:params) { { service: { nom: 'super service' }, procedure_id: procedure.id } } it { expect(flash.alert).not_to be_nil } it { expect(response).to render_template(:new) } @@ -54,7 +55,7 @@ describe NewAdministrateur::ServicesController, type: :controller do params = { id: service.id, service: service_params, - procedure_id: 12 + procedure_id: procedure.id } patch :update, params: params end @@ -64,7 +65,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.notice).to eq('nom modifié') } it { expect(Service.last.nom).to eq('nom') } it { expect(Service.last.type_organisme).to eq('region') } - it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) } end context 'when updating a service with invalid data' do diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb index 26acaa12d..4b8100e65 100644 --- a/spec/features/new_user/dossier_spec.rb +++ b/spec/features/new_user/dossier_spec.rb @@ -112,6 +112,20 @@ feature 'The user' do expect(page).to have_current_path(merci_dossier_path(user_dossier)) end + scenario 'delete a draft', js: true do + log_in(user.email, password, simple_procedure) + fill_individual + + page.accept_alert('Confirmer la suppression ?') do + click_on 'Supprimer le brouillon' + end + + expect(page).to have_current_path(dossiers_path) + expect(page).to have_text('Votre dossier a bien été supprimé') + expect(page).not_to have_text(user_dossier.procedure.libelle) + expect(user_dossier.reload.hidden_at).to be_present + end + private def log_in(email, password, procedure) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 829009f61..dc7bc7999 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -806,6 +806,54 @@ describe Dossier do end end + describe "#delete_and_keep_track" do + let(:dossier) { create(:dossier) } + let(:deleted_dossier) { DeletedDossier.find_by!(dossier_id: dossier.id) } + + before do + allow(DossierMailer).to receive(:notify_deletion_to_user).and_return(double(deliver_later: nil)) + allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil)) + end + + subject! { dossier.delete_and_keep_track } + + it 'hides the dossier' do + expect(dossier.hidden_at).to be_present + end + + it 'creates a DeletedDossier record' do + expect(deleted_dossier.dossier_id).to eq dossier.id + expect(deleted_dossier.procedure).to eq dossier.procedure + expect(deleted_dossier.state).to eq dossier.state + expect(deleted_dossier.deleted_at).to be_present + end + + it 'notifies the user' do + expect(DossierMailer).to have_received(:notify_deletion_to_user).with(deleted_dossier, dossier.user.email) + end + + context 'where gestionnaires are following the dossier' do + let(:dossier) { create(:dossier, :followed) } + let!(:non_following_gestionnaire) do + non_following_gestionnaire = create(:gestionnaire) + non_following_gestionnaire.procedures << dossier.procedure + non_following_gestionnaire + end + + it 'notifies the following gestionnaires' do + expect(DossierMailer).to have_received(:notify_deletion_to_administration).once + expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.followers_gestionnaires.first.email) + end + end + + context 'when there are no following gestionnaires' do + it 'notifies the procedure administrateur' do + expect(DossierMailer).to have_received(:notify_deletion_to_administration).once + expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateur.email) + end + end + end + describe 'webhook' do let(:dossier) { create(:dossier) }