diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 96d6847fb..3eaae3dc6 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -103,10 +103,10 @@ module Administrateurs elsif @procedure.brouillon? reset_procedure flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.' - redirect_to edit_admin_procedure_path(id: @procedure.id) + redirect_to admin_procedure_path(id: @procedure.id) else flash.notice = 'Démarche modifiée.' - redirect_to edit_admin_procedure_path(id: @procedure.id) + redirect_to admin_procedure_path(id: @procedure.id) end end @@ -254,7 +254,26 @@ module Administrateurs end def procedure_params - editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :logo, :auto_archive_on, :monavis_embed, :api_entreprise_token, :duree_conservation_dossiers_dans_ds, :zone_id, :lien_dpo] + editable_params = [ + :libelle, + :description, + :organisation, + :direction, + :lien_site_web, + :cadre_juridique, + :deliberation, + :notice, + :web_hook_url, + :declarative_with_state, + :logo, + :auto_archive_on, + :monavis_embed, + :api_entreprise_token, + :duree_conservation_dossiers_dans_ds, + :zone_id, + :lien_dpo, + :procedure_expires_when_termine_enabled + ] permited_params = if @procedure&.locked? params.require(:procedure).permit(*editable_params) else diff --git a/app/controllers/instructeurs/archives_controller.rb b/app/controllers/instructeurs/archives_controller.rb index b339e0918..130d8372b 100644 --- a/app/controllers/instructeurs/archives_controller.rb +++ b/app/controllers/instructeurs/archives_controller.rb @@ -30,7 +30,7 @@ module Instructeurs private def ensure_procedure_enabled - if !procedure.feature_enabled?(:archive_zip_globale) || procedure.brouillon? + if procedure.brouillon? flash[:alert] = "L'accès aux archives n’est pas disponible pour cette démarche, merci d’en faire la demande à l'équipe de démarches simplifiees" return redirect_to instructeur_procedure_path(procedure) end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 43e4bccb3..89908b334 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -34,7 +34,7 @@ # monavis_embed :text # organisation :string # path :string not null -# procedure_expires_when_termine_enabled :boolean default(FALSE) +# procedure_expires_when_termine_enabled :boolean default(TRUE) # published_at :datetime # routing_criteria_name :text default("Votre ville") # routing_enabled :boolean diff --git a/app/views/administrateurs/procedures/_suggest_expires_when_termine.html.haml b/app/views/administrateurs/procedures/_suggest_expires_when_termine.html.haml new file mode 100644 index 000000000..bf2283c0a --- /dev/null +++ b/app/views/administrateurs/procedures/_suggest_expires_when_termine.html.haml @@ -0,0 +1,10 @@ +.container{ :"data-test-suggest_expires_when_termine" => "true" } + .card.warning + .card-title + Veuillez activer la suppression automatique des dossiers expirés. + %p + Pour des raisons liées au RGPD, veuillez activer la suppression automatique des dossiers expirés (#{procedure.duree_conservation_dossiers_dans_ds} mois après que le dossier ait été traité). Vous pouvez à tout moment récupérer une archive de la démarche en vous connectant en tant qu’instructeur. + = link_to "En savoir plus", DOC_PROCEDURE_EXPIRES_URL, rel: 'noopener', target: '_blank', class: '' + + %p + = button_to "Activer l’expiration des données", admin_procedure_path(id: procedure.id, params: { procedure: { procedure_expires_when_termine_enabled: true }}), method: :patch, class: 'button primary', form: { data: { turbo: true } } diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index a52761878..4716b0aa5 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -43,6 +43,8 @@ = t(:has_changes, scope: [:administrateurs, :revision_changes]) = render partial: 'revision_changes', locals: { changes: @procedure.revision_changes } +- if !@procedure.procedure_expires_when_termine_enabled? + = render partial: 'administrateurs/procedures/suggest_expires_when_termine', locals: { procedure: @procedure } .container %h2.procedure-admin-explanation Indispensable avant publication .procedure-grid diff --git a/app/views/instructeurs/archives/index.html.haml b/app/views/instructeurs/archives/index.html.haml index 033036ad2..5706939d0 100644 --- a/app/views/instructeurs/archives/index.html.haml +++ b/app/views/instructeurs/archives/index.html.haml @@ -20,43 +20,41 @@ Nous vous invitons à regarder = link_to 'la documentation', ARCHIVAGE_DOC_URL afin de voir les options à votre disposition pour mettre en place un système d’archive. - - if @procedure.feature_enabled?(:archive_zip_globale) - %table.table.hoverable.archive-table - %thead - %tr - %th   - %th.text-right Nombre de dossiers terminés - %th.text-right Poids estimé - %th.center Télécharger - %tbody - - @count_dossiers_termines_by_month.each do |count_by_month| - - month = count_by_month["month"].to_date - - nb_dossiers_termines = count_by_month["count"] - - matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month } - - weight = estimate_weight(matching_archive, nb_dossiers_termines, @average_dossier_weight) + %table.table.hoverable.archive-table + %thead + %tr + %th   + %th.text-right Nombre de dossiers terminés + %th.text-right Poids estimé + %th.center Télécharger - %tr - %td - = I18n.l(month, format: "%B %Y").capitalize - %td.text-right - = nb_dossiers_termines - %td.text-right - = number_to_human_size(weight) - %td.center - - if matching_archive.present? - - if matching_archive.status == 'generated' && matching_archive.file.attached? - = link_to url_for(matching_archive.file), class: 'button primary' do - %span.icon.download-white - = t(:archive_ready_html, scope: [:instructeurs, :procedure], generated_period: time_ago_in_words(matching_archive.updated_at)) - - else - %span.icon.retry - = t(:archive_pending_html, scope: [:instructeurs, :procedure], created_period: time_ago_in_words(matching_archive.created_at)) - - elsif weight < Archive::MAX_SIZE - = link_to instructeur_archives_path(@procedure, type:'monthly', month: month.strftime('%Y-%m')), method: :post, class: "button" do - %span.icon.new-folder - Demander la création + %tbody + - @count_dossiers_termines_by_month.each do |count_by_month| + - month = count_by_month["month"].to_date + - nb_dossiers_termines = count_by_month["count"] + - matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month } + - weight = estimate_weight(matching_archive, nb_dossiers_termines, @average_dossier_weight) + + %tr + %td + = I18n.l(month, format: "%B %Y").capitalize + %td.text-right + = nb_dossiers_termines + %td.text-right + = number_to_human_size(weight) + %td.center + - if matching_archive.present? + - if matching_archive.status == 'generated' && matching_archive.file.attached? + = link_to url_for(matching_archive.file), class: 'button primary' do + %span.icon.download-white + = t(:archive_ready_html, scope: [:instructeurs, :procedure], generated_period: time_ago_in_words(matching_archive.updated_at)) - else - Archive trop volumineuse - - else - %p Cet fonctionnalité est en cours de deploiement, merci de faire une demande à notre support pour que nous l'activions pour votre démarche + %span.icon.retry + = t(:archive_pending_html, scope: [:instructeurs, :procedure], created_period: time_ago_in_words(matching_archive.created_at)) + - elsif weight < Archive::MAX_SIZE + = link_to instructeur_archives_path(@procedure, type:'monthly', month: month.strftime('%Y-%m')), method: :post, class: "button" do + %span.icon.new-folder + Demander la création + - else + Archive trop volumineuse diff --git a/config/env.example.optional b/config/env.example.optional index 2504fe14f..6260df964 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -131,3 +131,5 @@ SENDINBLUE_BALANCING_VALUE="50" # When present, N % of emails will be sent using DoList # (and the others using the default SMTP provider) DOLIST_BALANCING_VALUE="50" +# Used only by a migration to choose your default regarding procedure archive dossiers after duree_conservation_dossiers_dans_ds +# DEFAULT_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED=true diff --git a/config/initializers/02_urls.rb b/config/initializers/02_urls.rb index c1dc8b0b6..05aaf8a43 100644 --- a/config/initializers/02_urls.rb +++ b/config/initializers/02_urls.rb @@ -33,6 +33,7 @@ API_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "graphql"].join("/") WEBHOOK_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "webhook"].join("/") ARCHIVAGE_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "archivage-longue-duree-des-demarches"].join("/") DOC_INTEGRATION_MONAVIS_URL = [DOC_URL, "tutoriels", "integration-du-bouton-mon-avis"].join("/") +DOC_PROCEDURE_EXPIRES_URL = [DOC_URL, "expiration-et-suppression-des-dossiers"].join("/") FAQ_URL = ENV.fetch("FAQ_URL", "https://faq.demarches-simplifiees.fr") FAQ_ADMIN_URL = [FAQ_URL, "collection", "1-administrateur-creation-dun-formulaire"].join("/") diff --git a/db/migrate/20220222150340_set_default_procedure_expires_when_termine_enabled_to_true.rb b/db/migrate/20220222150340_set_default_procedure_expires_when_termine_enabled_to_true.rb new file mode 100644 index 000000000..e7d871eaa --- /dev/null +++ b/db/migrate/20220222150340_set_default_procedure_expires_when_termine_enabled_to_true.rb @@ -0,0 +1,16 @@ +# usage DEFAULT_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED=true|false rails db:migrate:up VERSION=20220222150340 +class SetDefaultProcedureExpiresWhenTermineEnabledToTrue < ActiveRecord::Migration[6.1] + def up + change_column :procedures, + :procedure_expires_when_termine_enabled, + :boolean, + default: ENV.fetch('DEFAULT_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED') { true } + end + + def down + change_column :procedures, + :procedure_expires_when_termine_enabled, + :boolean, + default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index b8a86f85d..318c8452c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2022_04_26_140107) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "unaccent" @@ -651,7 +650,7 @@ ActiveRecord::Schema.define(version: 2022_04_26_140107) do t.string "organisation" t.bigint "parent_procedure_id" t.string "path", null: false - t.boolean "procedure_expires_when_termine_enabled", default: false + t.boolean "procedure_expires_when_termine_enabled", default: true t.datetime "published_at" t.bigint "published_revision_id" t.text "routing_criteria_name", default: "Votre ville" diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index b34663ef1..d79d1c08c 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -215,7 +215,7 @@ describe Administrateurs::ProceduresController, type: :controller do end describe 'PUT #update' do - let!(:procedure) { create(:procedure, :with_type_de_champ, administrateur: admin) } + let!(:procedure) { create(:procedure, :with_type_de_champ, administrateur: admin, procedure_expires_when_termine_enabled: false) } context 'when administrateur is not connected' do before do @@ -229,7 +229,7 @@ describe Administrateurs::ProceduresController, type: :controller do context 'when administrateur is connected' do def update_procedure - put :update, params: { id: procedure.id, procedure: procedure_params } + put :update, params: { id: procedure.id, procedure: procedure_params.merge(procedure_expires_when_termine_enabled: true) } procedure.reload end @@ -239,6 +239,7 @@ describe Administrateurs::ProceduresController, type: :controller do let(:organisation) { 'plop' } let(:direction) { 'plap' } let(:duree_conservation_dossiers_dans_ds) { 7 } + let(:procedure_expires_when_termine_enabled) { true } before { update_procedure } @@ -250,9 +251,10 @@ describe Administrateurs::ProceduresController, type: :controller do it { expect(subject.organisation).to eq(organisation) } it { expect(subject.direction).to eq(direction) } it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) } + it { expect(subject.procedure_expires_when_termine_enabled).to eq(true) } end - it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) } + it { is_expected.to redirect_to(admin_procedure_path id: procedure.id) } it { expect(flash[:notice]).to be_present } end diff --git a/spec/controllers/instructeurs/archives_controller_spec.rb b/spec/controllers/instructeurs/archives_controller_spec.rb index 0eb1ff266..36d8d8a2a 100644 --- a/spec/controllers/instructeurs/archives_controller_spec.rb +++ b/spec/controllers/instructeurs/archives_controller_spec.rb @@ -9,7 +9,6 @@ describe Instructeurs::ArchivesController, type: :controller do before do sign_in(instructeur.user) - Flipper.enable(:archive_zip_globale, procedure1) end after { Timecop.return } diff --git a/spec/system/administrateurs/procedure_update_spec.rb b/spec/system/administrateurs/procedure_update_spec.rb index f63328ba9..b33599eda 100644 --- a/spec/system/administrateurs/procedure_update_spec.rb +++ b/spec/system/administrateurs/procedure_update_spec.rb @@ -38,7 +38,7 @@ describe 'Administrateurs can edit procedures', js: true do click_on 'Enregistrer' - expect(page).to have_field('procedure_libelle', with: 'Ma petite démarche') + expect(page).to have_selector('.breadcrumbs li', text: 'Ma petite démarche') end end @@ -55,7 +55,7 @@ describe 'Administrateurs can edit procedures', js: true do click_on 'Enregistrer' - expect(page).to have_field('procedure_libelle', with: 'Ma petite démarche') + expect(page).to have_selector('.breadcrumbs li', text: 'Ma petite démarche') end end diff --git a/spec/views/administrateurs/procedures/show.html.haml_spec.rb b/spec/views/administrateurs/procedures/show.html.haml_spec.rb index d2d33cb0d..22a128550 100644 --- a/spec/views/administrateurs/procedures/show.html.haml_spec.rb +++ b/spec/views/administrateurs/procedures/show.html.haml_spec.rb @@ -57,4 +57,24 @@ describe 'administrateurs/procedures/show.html.haml', type: :view do it { expect(rendered).to have_content('Réactiver') } end end + + describe 'procedure with expiration disabled' do + let(:procedure) { create(:procedure, procedure_expires_when_termine_enabled: true) } + before do + render + end + it 'does not render partial to enable procedure_expires_when_termine_enabled' do + expect(rendered).not_to have_css("div[data-test-suggest_expires_when_termine]") + end + end + + describe 'procedure with expiration enabled' do + let(:procedure) { create(:procedure, procedure_expires_when_termine_enabled: false) } + before do + render + end + it 'renders a partial to enable procedure_expires_when_termine_enabled' do + expect(rendered).to have_css("div[data-test-suggest_expires_when_termine]") + end + end end diff --git a/spec/views/users/dossiers/show/_header.html.haml_spec.rb b/spec/views/users/dossiers/show/_header.html.haml_spec.rb index 4be3a6af1..3d75535cf 100644 --- a/spec/views/users/dossiers/show/_header.html.haml_spec.rb +++ b/spec/views/users/dossiers/show/_header.html.haml_spec.rb @@ -47,7 +47,7 @@ describe 'users/dossiers/show/header.html.haml', type: :view do context "when the procedure is discarded with a dossier terminé" do let(:procedure) { create(:procedure, :discarded) } - let(:dossier) { create(:dossier, state: "accepte", procedure: procedure) } + let(:dossier) { create(:dossier, :accepte, procedure: procedure) } it 'affiche que la démarche est supprimée' do expect(rendered).to have_text("La démarche liée à votre dossier est supprimée")