From 6b19432d4701410a835e0e5501fcff6d0d9f8077 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Thu, 11 Jul 2019 11:49:01 +0200 Subject: [PATCH 1/9] =?UTF-8?q?deplacement=20de=20l'URL=20qui=20envoie=20v?= =?UTF-8?q?ers=20la=20proc=C3=A9dure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/procedures_controller.rb | 2 ++ app/views/admin/procedures/_informations.html.haml | 7 ++++--- app/views/admin/procedures/_modal_publish.html.haml | 5 +++++ spec/controllers/admin/procedures_controller_spec.rb | 7 ++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 448df9f3c..8372a2535 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -110,6 +110,8 @@ class Admin::ProceduresController < AdminController procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure.path = path + procedure.lien_site_web = params[:lien_site_web] + if !procedure.validate flash.alert = 'Lien de la démarche invalide' return redirect_to admin_procedures_path diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 7c1b8ad31..437e83dd4 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -19,9 +19,10 @@ = f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)" = f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true -.form-group - %h4 Où les usagers trouveront-ils le lien vers la démarche ? - = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche' +- if @procedure.locked? + .form-group + %h4 Où les usagers trouveront-ils le lien vers la démarche ? + = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche' .form-group %h4 Cadre juridique * diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 202f1f6bd..0df3e7bf9 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -38,6 +38,11 @@ "https://vimeo.com/334463514", target: "_blank" + .form-group + %h4 Où les usagers trouveront-ils le lien vers cette démarche ? + %p.center + = text_field_tag(:lien_site_web, @procedure.lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche') + #path-messages #path_is_mine.text-warning.center.message Ce lien est déjà utilisé par une de vos démarche. diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 4acaf3531..4ec06a296 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -334,10 +334,11 @@ describe Admin::ProceduresController, type: :controller do let(:procedure) { create(:procedure, administrateur: admin) } let(:procedure2) { create(:procedure, :published, administrateur: admin) } let(:procedure3) { create(:procedure, :published) } + let(:lien_site_web) { 'http://some.administration/' } context 'when admin is the owner of the procedure' do before do - put :publish, params: { procedure_id: procedure.id, path: path } + put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } procedure.reload procedure2.reload end @@ -348,6 +349,7 @@ describe Admin::ProceduresController, type: :controller do it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy expect(procedure.path).to eq(path) + expect(procedure.lien_site_web).to eq(lien_site_web) expect(response.status).to eq 302 expect(flash[:notice]).to have_content 'Démarche publiée' end @@ -359,6 +361,7 @@ describe Admin::ProceduresController, type: :controller do it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy expect(procedure.path).to eq(path) + expect(procedure.lien_site_web).to eq(lien_site_web) expect(response.status).to eq 302 expect(flash[:notice]).to have_content 'Démarche publiée' end @@ -375,6 +378,7 @@ describe Admin::ProceduresController, type: :controller do it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey expect(procedure.path).not_to match(path) + expect(procedure.lien_site_web).not_to match(lien_site_web) expect(response.status).to eq 200 end @@ -391,6 +395,7 @@ describe Admin::ProceduresController, type: :controller do it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey expect(procedure.path).not_to match(path) + expect(procedure.lien_site_web).not_to match(lien_site_web) expect(response).to redirect_to :admin_procedures expect(flash[:alert]).to have_content 'Lien de la démarche invalide' end From 6f4765530150b30bf8b88c292e3c77d4ea94cc87 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Thu, 11 Jul 2019 16:07:00 +0200 Subject: [PATCH 2/9] rendu lien_site_web obligatoire au moment de la publication --- .../admin/procedures_controller.rb | 7 ++--- app/models/procedure.rb | 22 +++++++--------- .../admin/procedures/_informations.html.haml | 2 +- .../admin/procedures/_modal_publish.html.haml | 7 +++-- .../admin/procedures_controller_spec.rb | 26 ++++++++++++++----- spec/factories/procedure.rb | 9 ++++--- spec/models/procedure_spec.rb | 2 +- 7 files changed, 45 insertions(+), 30 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 8372a2535..ff3024464 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -107,19 +107,20 @@ class Admin::ProceduresController < AdminController def publish path = params[:path] + lien_site_web = params[:lien_site_web] procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure.path = path - procedure.lien_site_web = params[:lien_site_web] + procedure.lien_site_web = lien_site_web if !procedure.validate - flash.alert = 'Lien de la démarche invalide' + flash.alert = 'Lien de la démarche invalide ou lien vers la démarche manquant' return redirect_to admin_procedures_path else procedure.path = nil end - if procedure.publish_or_reopen!(current_administrateur, path) + if procedure.publish_or_reopen!(current_administrateur, path, lien_site_web) flash.notice = "Démarche publiée" redirect_to admin_procedures_path else diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 4f36161dd..9ec30cef6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -107,12 +107,12 @@ class Procedure < ApplicationRecord end end - def publish_or_reopen!(administrateur, path) - if archivee? && may_reopen?(administrateur, path) - reopen!(administrateur, path) - elsif may_publish?(administrateur, path) + def publish_or_reopen!(administrateur, path, lien_site_web) + if archivee? && may_reopen?(administrateur, path, lien_site_web) + reopen!(administrateur, path, lien_site_web) + elsif may_publish?(administrateur, path, lien_site_web) reset! - publish!(administrateur, path) + publish!(administrateur, path, lien_site_web) end end @@ -488,21 +488,17 @@ class Procedure < ApplicationRecord update!(path: path) end - def can_publish?(administrateur, path) - path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) + def can_publish?(administrateur, path, lien_site_web) + path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) && lien_site_web.present? end - def can_reopen?(administrateur, path) - path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) - end - - def after_publish(administrateur, path) + def after_publish(administrateur, path, lien_site_web) update!(published_at: Time.zone.now) claim_path_ownership!(path) end - def after_reopen(administrateur, path) + def after_reopen(administrateur, path, lien_site_web) update!(published_at: Time.zone.now, archived_at: nil) claim_path_ownership!(path) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 437e83dd4..c2d1477a2 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -19,7 +19,7 @@ = f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)" = f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true -- if @procedure.locked? +- if @procedure.new? .form-group %h4 Où les usagers trouveront-ils le lien vers la démarche ? = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche' diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 0df3e7bf9..102e0c234 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -39,9 +39,12 @@ target: "_blank" .form-group - %h4 Où les usagers trouveront-ils le lien vers cette démarche ? + %h4 Où les usagers trouveront-ils le lien vers cette démarche ? * %p.center - = text_field_tag(:lien_site_web, @procedure.lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche') + = text_field_tag(:lien_site_web, @procedure.lien_site_web, + required: true, + class: 'form-control', + placeholder: 'https://exemple.gouv.fr/ma_demarche') #path-messages #path_is_mine.text-warning.center.message diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 4ec06a296..6f22b7ad3 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -15,6 +15,7 @@ describe Admin::ProceduresController, type: :controller do let(:duree_conservation_dossiers_dans_ds) { 3 } let(:duree_conservation_dossiers_hors_ds) { 6 } let(:monavis_embed) { nil } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:procedure_params) { { @@ -26,7 +27,8 @@ describe Admin::ProceduresController, type: :controller do cadre_juridique: cadre_juridique, duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds, - monavis_embed: monavis_embed + monavis_embed: monavis_embed, + lien_site_web: lien_site_web } } @@ -331,9 +333,10 @@ describe Admin::ProceduresController, type: :controller do end describe 'PUT #publish' do - let(:procedure) { create(:procedure, administrateur: admin) } - let(:procedure2) { create(:procedure, :published, administrateur: admin) } - let(:procedure3) { create(:procedure, :published) } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } + let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: nil) } + let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } + let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) } let(:lien_site_web) { 'http://some.administration/' } context 'when admin is the owner of the procedure' do @@ -400,6 +403,17 @@ describe Admin::ProceduresController, type: :controller do expect(flash[:alert]).to have_content 'Lien de la démarche invalide' end end + + context 'procedure path is valid but lien_site_web is missing' do + let(:path) { 'new_path' } + let(:lien_site_web) { nil } + + it 'does not publish the given procedure' do + expect(procedure.publiee?).to be_falsey + expect(flash[:alert]).to have_content 'Lien de la démarche invalide' + expect(response).to redirect_to :admin_procedures + end + end end context 'when admin is not the owner of the procedure' do @@ -421,7 +435,7 @@ describe Admin::ProceduresController, type: :controller do end describe 'PUT #archive' do - let(:procedure) { create(:procedure, :published, administrateur: admin) } + let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } context 'when admin is the owner of the procedure' do before do @@ -437,7 +451,7 @@ describe Admin::ProceduresController, type: :controller do context 'when owner want to re-enable procedure' do before do - put :publish, params: { procedure_id: procedure.id, path: 'fake_path' } + put :publish, params: { procedure_id: procedure.id, path: 'fake_path', lien_site_web: lien_site_web } procedure.reload end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 2e5bd901d..cc9be67ec 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -10,6 +10,7 @@ FactoryBot.define do duree_conservation_dossiers_dans_ds { 3 } duree_conservation_dossiers_hors_ds { 6 } ask_birthday { false } + lien_site_web { "https://mon-site.gouv" } transient do administrateur {} @@ -147,13 +148,13 @@ FactoryBot.define do trait :published do after(:build) do |procedure, _evaluator| - procedure.publish!(procedure.administrateurs.first, generate(:published_path)) + procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web) end end trait :archived do after(:build) do |procedure, _evaluator| - procedure.publish!(procedure.administrateurs.first, generate(:published_path)) + procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web) procedure.archive! end end @@ -162,14 +163,14 @@ FactoryBot.define do # For now the behavior is the same than :archived # (it may be different in the future though) after(:build) do |procedure, _evaluator| - procedure.publish!(procedure.administrateurs.first, generate(:published_path)) + procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web) procedure.archive! end end trait :hidden do after(:build) do |procedure, _evaluator| - procedure.publish!(procedure.administrateurs.first, generate(:published_path)) + procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web) procedure.hide! end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 81f94e500..d677a93bb 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -554,7 +554,7 @@ describe Procedure do before do Timecop.freeze(now) - procedure.publish!(procedure.administrateurs.first, "example-path") + procedure.publish!(procedure.administrateurs.first, "example-path", procedure.lien_site_web) end after { Timecop.return } From 314b0f5dc0d04fac05579bf85a09e8cf882be18f Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 23 Jul 2019 12:09:48 +0200 Subject: [PATCH 3/9] fix tests --- .../admin/procedures/_informations.html.haml | 2 +- .../admin/procedures_controller_spec.rb | 37 +++++++++++-------- spec/factories/procedure.rb | 2 +- .../features/admin/procedure_creation_spec.rb | 1 + .../admin/procedures/edit.html.haml_spec.rb | 2 +- .../admin/procedures/show.html.haml_spec.rb | 4 +- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index c2d1477a2..2ff2e84b2 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -19,7 +19,7 @@ = f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)" = f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true -- if @procedure.new? +- if @procedure.created_at.present? .form-group %h4 Où les usagers trouveront-ils le lien vers la démarche ? = f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche' diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 6f22b7ad3..82490bdd2 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -333,8 +333,7 @@ describe Admin::ProceduresController, type: :controller do end describe 'PUT #publish' do - let(:lien_site_web) { 'http://mon-site.gouv.fr' } - let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: nil) } + let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) } let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) } let(:lien_site_web) { 'http://some.administration/' } @@ -348,6 +347,7 @@ describe Admin::ProceduresController, type: :controller do context 'procedure path does not exist' do let(:path) { 'new_path' } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy @@ -360,6 +360,7 @@ describe Admin::ProceduresController, type: :controller do context 'procedure path exists and is owned by current administrator' do let(:path) { procedure2.path } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy @@ -377,11 +378,12 @@ describe Admin::ProceduresController, type: :controller do context 'procedure path exists and is not owned by current administrator' do let(:path) { procedure3.path } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey expect(procedure.path).not_to match(path) - expect(procedure.lien_site_web).not_to match(lien_site_web) + expect(procedure.lien_site_web).to match(lien_site_web) expect(response.status).to eq 200 end @@ -394,26 +396,16 @@ describe Admin::ProceduresController, type: :controller do context 'procedure path is invalid' do let(:path) { 'Invalid Procedure Path' } + let(:lien_site_web) { 'http://mon-site.gouv.fr' } it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey expect(procedure.path).not_to match(path) - expect(procedure.lien_site_web).not_to match(lien_site_web) + expect(procedure.lien_site_web).to match(lien_site_web) expect(response).to redirect_to :admin_procedures expect(flash[:alert]).to have_content 'Lien de la démarche invalide' end end - - context 'procedure path is valid but lien_site_web is missing' do - let(:path) { 'new_path' } - let(:lien_site_web) { nil } - - it 'does not publish the given procedure' do - expect(procedure.publiee?).to be_falsey - expect(flash[:alert]).to have_content 'Lien de la démarche invalide' - expect(response).to redirect_to :admin_procedures - end - end end context 'when admin is not the owner of the procedure' do @@ -432,6 +424,21 @@ describe Admin::ProceduresController, type: :controller do expect(flash[:alert]).to have_content 'Démarche inexistante' end end + + context 'when the admin does not provide a lien_site_web' do + before do + put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } + procedure.reload + end + context 'procedure path is valid but lien_site_web is missing' do + let(:path) { 'new_path2' } + let(:lien_site_web) { nil } + + it 'does not publish the given procedure' do + expect(procedure.publiee?).to be_falsey + end + end + end end describe 'PUT #archive' do diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index cc9be67ec..88bc8faa9 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -38,7 +38,7 @@ FactoryBot.define do after(:build) do |procedure, _evaluator| procedure.for_individual = true procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true) - procedure.publish!(procedure.administrateurs.first, generate(:published_path)) + procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web) end end diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 8ff486f90..83f11a236 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -123,6 +123,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do within '#publish-modal' do expect(page).to have_field('procedure_path') + fill_in 'lien_site_web', with: 'http://some.website' click_on 'publish' end diff --git a/spec/views/admin/procedures/edit.html.haml_spec.rb b/spec/views/admin/procedures/edit.html.haml_spec.rb index 28d4cc71b..cb09b0ba3 100644 --- a/spec/views/admin/procedures/edit.html.haml_spec.rb +++ b/spec/views/admin/procedures/edit.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'admin/procedures/edit.html.haml', type: :view, vcr: { cassette_name: 'admin_procedure_edit' } do let(:logo) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } - let(:procedure) { create(:procedure, logo: logo) } + let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') } before do assign(:procedure, procedure) diff --git a/spec/views/admin/procedures/show.html.haml_spec.rb b/spec/views/admin/procedures/show.html.haml_spec.rb index 57715a9a7..9c5c8deef 100644 --- a/spec/views/admin/procedures/show.html.haml_spec.rb +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -41,7 +41,7 @@ describe 'admin/procedures/show.html.haml', type: :view do describe 'procedure is published' do before do - procedure.publish!(procedure.administrateurs.first, 'fake_path') + procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web) procedure.reload render end @@ -59,7 +59,7 @@ describe 'admin/procedures/show.html.haml', type: :view do describe 'procedure is archived' do before do - procedure.publish!(procedure.administrateurs.first, 'fake_path') + procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web) procedure.archive! procedure.reload render From f1838f37676fab63e44264319c6115d129357da7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 29 Jul 2019 10:41:58 +0200 Subject: [PATCH 4/9] dossiers: fix edit button being visible on locked dossiers Fix #4143 --- app/views/users/dossiers/show/_header.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 8753abecb..910e220a7 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -11,7 +11,8 @@ = "- Déposé le #{l(dossier.en_construction_at, format: '%d %B %Y')}" - if current_user.owns?(dossier) - = link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" + - if dossier.can_be_updated_by_user? + = link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" = render partial: 'invites/dropdown', locals: { dossier: dossier } .clearfix From 7b345365fd9e4b92fbe6d076189d93783fedf1d8 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 29 Jul 2019 10:45:49 +0200 Subject: [PATCH 5/9] dossiers: fix the layout of the Edit button --- app/assets/stylesheets/new_design/dossier_show.scss | 4 ---- app/views/invites/_dropdown.html.haml | 2 +- app/views/users/dossiers/show/_header.html.haml | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/new_design/dossier_show.scss b/app/assets/stylesheets/new_design/dossier_show.scss index 971c7cc70..e26367a75 100644 --- a/app/assets/stylesheets/new_design/dossier_show.scss +++ b/app/assets/stylesheets/new_design/dossier_show.scss @@ -38,10 +38,6 @@ } } - .button.edit-form { - float: right; - } - .messagerie-explanation { margin-bottom: $default-padding * 2; } diff --git a/app/views/invites/_dropdown.html.haml b/app/views/invites/_dropdown.html.haml index 869804b53..368c359ef 100644 --- a/app/views/invites/_dropdown.html.haml +++ b/app/views/invites/_dropdown.html.haml @@ -1,4 +1,4 @@ -%span.dropdown.invite-user-action{ :style => "float:right;right: 10px;" } +%span.dropdown.invite-user-action %button.button.dropdown-button %span.icon.person - if dossier.invites.count > 0 diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 910e220a7..96341a4fe 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -11,10 +11,10 @@ = "- Déposé le #{l(dossier.en_construction_at, format: '%d %B %Y')}" - if current_user.owns?(dossier) - - if dossier.can_be_updated_by_user? - = link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" - = render partial: 'invites/dropdown', locals: { dossier: dossier } - .clearfix + .header-actions + = render partial: 'invites/dropdown', locals: { dossier: dossier } + - if dossier.can_be_updated_by_user? + = link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" %ul.tabs = dynamic_tab_item('Résumé', dossier_path(dossier)) From e99edda7b19642f483cc2df02feed4af8741e388 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 29 Jul 2019 10:49:49 +0200 Subject: [PATCH 6/9] dossiers: hide the Edit button on the actual edit page Otherwise the "Edit" button may be confused for a "Save" button. --- app/views/users/dossiers/show/_header.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 96341a4fe..51d6a2797 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -13,8 +13,8 @@ - if current_user.owns?(dossier) .header-actions = render partial: 'invites/dropdown', locals: { dossier: dossier } - - if dossier.can_be_updated_by_user? - = link_to "Modifier mon dossier", modifier_dossier_path(dossier.id), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" + - if dossier.can_be_updated_by_user? && !current_page?(modifier_dossier_path(dossier)) + = link_to "Modifier mon dossier", modifier_dossier_path(dossier), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction" %ul.tabs = dynamic_tab_item('Résumé', dossier_path(dossier)) From bcd5182446079a32932e6241d98746ab25a10c3a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 29 Jul 2019 10:54:19 +0200 Subject: [PATCH 7/9] dossier: hide the draft explanation when already submitted --- app/views/shared/dossiers/_edit.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index ed34765e0..3a03f3abd 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -15,8 +15,9 @@ Les champs avec un astérisque ( %span.mandatory> * ) sont obligatoires. - %p.mandatory-explanation - Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire. + - if dossier.brouillon? + %p.mandatory-explanation + Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire. - if notice_url(dossier.procedure).present? = link_to notice_url(dossier.procedure), target: '_blank', rel: 'noopener', class: 'button notice', title: "Pour vous aider à remplir votre dossier, vous pouvez consulter le guide de cette démarche." do From d06e2cd25f5b42996ce77ae8515106e184ae43b1 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 29 Jul 2019 11:40:51 +0200 Subject: [PATCH 8/9] Fix schema.rb description after #4116 Always run migrations in the PR :) --- db/schema.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index b38ea35e9..a4ef748da 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_07_17_132452) do +ActiveRecord::Schema.define(version: 2019_07_17_151228) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -430,6 +430,7 @@ ActiveRecord::Schema.define(version: 2019_07_17_132452) do t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" + t.text "message" end create_table "module_api_cartos", id: :serial, force: :cascade do |t| From b066ccbc89e03bcbb50a6071986200aa04e9665e Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Thu, 4 Jul 2019 16:15:40 +0200 Subject: [PATCH 9/9] Make sure Procedure.path is not null in our data --- app/models/procedure.rb | 6 +++--- ...ths_for_archived_and_hidden_procedures.rake | 18 ++++++++++++++++++ .../admin/procedures_controller_spec.rb | 1 - spec/models/procedure_spec.rb | 14 ++------------ 4 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 lib/tasks/deployment/20190704133852_create_dummy_paths_for_archived_and_hidden_procedures.rake diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 9ec30cef6..cefa39bc0 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -216,7 +216,7 @@ class Procedure < ApplicationRecord types_de_champ: [:drop_down_list, types_de_champ: :drop_down_list], types_de_champ_private: [:drop_down_list, types_de_champ: :drop_down_list] }, &method(:clone_attachments)) - procedure.path = nil + procedure.path = SecureRandom.uuid procedure.aasm_state = :brouillon procedure.test_started_at = nil procedure.archived_at = nil @@ -505,12 +505,12 @@ class Procedure < ApplicationRecord end def after_archive - update!(archived_at: Time.zone.now, path: nil) + update!(archived_at: Time.zone.now, path: SecureRandom.uuid) end def after_hide now = Time.zone.now - update!(hidden_at: now, path: nil) + update!(hidden_at: now, path: SecureRandom.uuid) dossiers.update_all(hidden_at: now) end diff --git a/lib/tasks/deployment/20190704133852_create_dummy_paths_for_archived_and_hidden_procedures.rake b/lib/tasks/deployment/20190704133852_create_dummy_paths_for_archived_and_hidden_procedures.rake new file mode 100644 index 000000000..5562087a5 --- /dev/null +++ b/lib/tasks/deployment/20190704133852_create_dummy_paths_for_archived_and_hidden_procedures.rake @@ -0,0 +1,18 @@ +namespace :after_party do + desc 'Deployment task: create_dummy_paths_for_archived_and_hidden_procedures' + task create_dummy_paths_for_archived_and_hidden_procedures: :environment do + puts "Running deploy task 'create_dummy_paths_for_archived_procedures'" + + Procedure.unscoped.archivees.where(path: nil).each do |p| + p.update_column(:path, SecureRandom.uuid) + end + + Procedure.unscoped.hidden.where(path: nil).each do |p| + p.update_column(:path, SecureRandom.uuid) + end + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord.create version: '20190704133852' + end +end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 82490bdd2..b6504a149 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -372,7 +372,6 @@ describe Admin::ProceduresController, type: :controller do it 'archive previous procedure' do expect(procedure2.archivee?).to be_truthy - expect(procedure2.path).to be_nil end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index d677a93bb..22621a3f7 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -690,19 +690,9 @@ describe Procedure do subject { procedure.export_filename(:csv) } - context "with a path" do - let(:procedure) { create(:procedure, :published) } + let(:procedure) { create(:procedure, :published) } - it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11.csv") } - end - - context "without a path" do - let(:procedure) { create(:procedure, :archived) } - - it do - is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv") - end - end + it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11.csv") } end describe '#new_dossier' do