From 663c39ea11e9140512a8c45e852e84e5aec7237c Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 25 Jun 2018 11:52:23 +0000 Subject: [PATCH 01/10] specs: improve speed of dossiers specs (12s -> 6s) --- spec/views/users/dossiers/index_html.haml_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/views/users/dossiers/index_html.haml_spec.rb b/spec/views/users/dossiers/index_html.haml_spec.rb index bd1c56f03..382248f3f 100644 --- a/spec/views/users/dossiers/index_html.haml_spec.rb +++ b/spec/views/users/dossiers/index_html.haml_spec.rb @@ -27,14 +27,16 @@ describe 'users/dossiers/index.html.haml', type: :view do subject { rendered } - describe 'columns' do - it { is_expected.to have_content(decorate_dossier_at_check.id) } - it { is_expected.to have_content(decorate_dossier_at_check.procedure.libelle) } - it { is_expected.to have_content(decorate_dossier_at_check.display_state) } - it { is_expected.to have_content(decorate_dossier_at_check.last_update) } + it 'displays the total count' do + expect(dossiers_to_display.count).to eq total_dossiers end - it { expect(dossiers_to_display.count).to eq total_dossiers } + it 'displays data in columns' do + expect(rendered).to have_content(decorate_dossier_at_check.id) + expect(rendered).to have_content(decorate_dossier_at_check.procedure.libelle) + expect(rendered).to have_content(decorate_dossier_at_check.display_state) + expect(rendered).to have_content(decorate_dossier_at_check.last_update) + end end describe 'on tab en construction' do From b9c8a1ffbe508456740285291ac3acf06f896e63 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 20 Jun 2018 15:29:52 +0200 Subject: [PATCH 02/10] dossiers: simpler display when there are not invited dossiers --- app/views/new_user/dossiers/index.html.haml | 9 ++-- .../new_user/dossiers/index.html.haml_spec.rb | 46 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 spec/views/new_user/dossiers/index.html.haml_spec.rb diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index cd6779443..67de116ae 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -1,13 +1,14 @@ .dossiers-headers.sub-header .container - %h1.page-title Les dossiers + - if @dossiers_invites.count == 0 + %h1.page-title Mes dossiers - %ul.tabs - - if @user_dossiers.count > 0 + - else + %h1.page-title Dossiers + %ul.tabs %li{ class: (@current_tab == 'mes-dossiers') ? 'active' : nil }> = link_to(dossiers_path(current_tab: 'mes-dossiers')) do mes dossiers - - if @dossiers_invites.count > 0 %li{ class: (@current_tab == 'dossiers-invites') ? 'active' : nil }> = link_to(dossiers_path(current_tab: 'dossiers-invites')) do dossiers invités diff --git a/spec/views/new_user/dossiers/index.html.haml_spec.rb b/spec/views/new_user/dossiers/index.html.haml_spec.rb new file mode 100644 index 000000000..37cb672a5 --- /dev/null +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -0,0 +1,46 @@ +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(:dossiers_invites) { [] } + let(:current_tab) { 'mes-dossiers' } + + before do + assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1)) + assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1)) + assign(:dossiers, Kaminari.paginate_array(user_dossiers).page(1)) + assign(:current_tab, current_tab) + render + end + + it 'affiche la liste des dossiers' do + expect(rendered).to have_selector('.dossiers-table tbody tr', count: 2) + end + + context 'quand il n’y a pas de dossiers invités' do + let(:dossiers_invites) { [] } + + it 'affiche un titre adapté' do + expect(rendered).to have_selector('h1', text: 'Mes dossiers') + end + + it 'n’affiche pas la barre d’onglets' do + expect(rendered).not_to have_selector('ul.tabs') + end + end + + context 'avec des dossiers invités' do + let(:dossiers_invites) { create_list(:dossier, 1) } + + it 'affiche un titre adapté' do + expect(rendered).to have_selector('h1', text: 'Dossiers') + end + + it 'affiche la barre d’onglets' do + expect(rendered).to have_selector('ul.tabs') + expect(rendered).to have_selector('ul.tabs li', count: 2) + expect(rendered).to have_selector('ul.tabs li.active', count: 1) + end + end +end From 8c680347dd2692185bc7c8b6799cf59a6dc59c66 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 20 Jun 2018 15:55:45 +0200 Subject: [PATCH 03/10] header: leave horizontal space for both "Procedure" and "Avis" --- app/assets/stylesheets/new_design/new_header.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/new_header.scss b/app/assets/stylesheets/new_design/new_header.scss index b7dccb4c1..8a07ab6cb 100644 --- a/app/assets/stylesheets/new_design/new_header.scss +++ b/app/assets/stylesheets/new_design/new_header.scss @@ -26,7 +26,7 @@ $landing-breakpoint: 1040px; margin-right: 4 * $default-spacer; img { - height: 36px; + height: 34px; @media (max-width: $landing-breakpoint) { height: 18px; From a569a566fcef0c75f11fe86fb571e5fe17ef80b2 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 20 Jun 2018 16:02:41 +0200 Subject: [PATCH 04/10] header: use active_link_to for setting the active class on links --- Gemfile | 3 +++ Gemfile.lock | 6 +++++- app/views/layouts/_new_header.haml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index ef32fe193..35094dfd9 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,9 @@ gem 'haml-rails' # bootstrap saas gem 'bootstrap-sass', '~> 3.3.5' +# Automatically set a class on active links +gem 'active_link_to' + # Pagination gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index 7924deba3..43089c584 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,9 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) + active_link_to (1.0.5) + actionpack + addressable active_model_serializers (0.10.7) actionpack (>= 4.1, < 6) activemodel (>= 4.1, < 6) @@ -785,6 +788,7 @@ PLATFORMS DEPENDENCIES aasm + active_link_to active_model_serializers administrate apipie-rails @@ -877,4 +881,4 @@ DEPENDENCIES xray-rails BUNDLED WITH - 1.16.1 + 1.16.2 diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index c984ee4e5..0176498f7 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -13,10 +13,10 @@ %ul.header-tabs - if current_gestionnaire.visible_procedures.count > 0 %li - = link_to "Procédures", gestionnaire_procedures_path, class: (controller_name != 'avis') ? "tab-link active" : 'tab-link' + = active_link_to "Procédures", gestionnaire_procedures_path, active: :inclusive, class: 'tab-link' - if current_gestionnaire.avis.count > 0 %li - = link_to gestionnaire_avis_index_path, class: (controller_name == 'avis') ? "tab-link active" : 'tab-link' do + = active_link_to gestionnaire_avis_index_path, active: :inclusive, class: 'tab-link' do Avis - avis_counter = current_gestionnaire.avis.without_answer.count - if avis_counter > 0 From f242c73974027f7c89e22f96efb62993e1902641 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 25 Jun 2018 12:47:13 +0000 Subject: [PATCH 05/10] dossiers: make link in the header point to the new UI --- app/views/layouts/_new_header.haml | 2 +- spec/views/layouts/_new_header_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 0176498f7..dad1e8d20 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 - = link_to "Mes dossiers", users_dossiers_path, 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? diff --git a/spec/views/layouts/_new_header_spec.rb b/spec/views/layouts/_new_header_spec.rb index 8ccbec46f..17ceb970b 100644 --- a/spec/views/layouts/_new_header_spec.rb +++ b/spec/views/layouts/_new_header_spec.rb @@ -15,6 +15,7 @@ describe 'layouts/_new_header.html.haml', type: :view do let(:profile) { :user } it { is_expected.to have_css("a.header-logo[href=\"#{users_dossiers_path}\"]") } + it { is_expected.to have_link("Dossiers", href: dossiers_path) } end context 'when rendering for gestionnaire' do From 06de1d6cee0f004035fbd18990bdd438f02e12a8 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 25 Jun 2018 11:34:48 +0000 Subject: [PATCH 06/10] dossiers: link individual dossiers to the old UI --- app/views/new_user/dossiers/index.html.haml | 10 +++++----- spec/views/new_user/dossiers/index.html.haml_spec.rb | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 67de116ae..5174cdfaa 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -26,19 +26,19 @@ - @dossiers.each do |dossier| %tr %td.folder-col - = link_to(modifier_dossier_path(dossier), class: 'cell-link') do + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do %span.icon.folder %td.number-col - = link_to(modifier_dossier_path(dossier), class: 'cell-link') do + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do = dossier.id %td - = link_to(modifier_dossier_path(dossier), class: 'cell-link') do + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do = dossier.procedure.libelle %td.status-col - = link_to(modifier_dossier_path(dossier), class: 'cell-link') do + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do = render partial: 'shared/dossiers/status', locals: { dossier: dossier } %td.updated-at-col - = link_to(modifier_dossier_path(dossier), class: 'cell-link') do + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do = dossier.updated_at.localtime.strftime("%d/%m/%Y") = paginate(@dossiers) 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 37cb672a5..446d7a5ee 100644 --- a/spec/views/new_user/dossiers/index.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -18,6 +18,13 @@ describe 'new_user/dossiers/index.html.haml', type: :view do expect(rendered).to have_selector('.dossiers-table tbody tr', count: 2) end + 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)) + end + context 'quand il n’y a pas de dossiers invités' do let(:dossiers_invites) { [] } From 8c36c8d26fed7cd323a7562358a757d87df6f6f5 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 25 Jun 2018 13:14:22 +0000 Subject: [PATCH 07/10] dossiers: add an empty state --- app/views/new_user/dossiers/index.html.haml | 57 ++++++++++--------- .../new_user/dossiers/index.html.haml_spec.rb | 15 ++++- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 5174cdfaa..1f27993db 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -14,31 +14,34 @@ dossiers invités .container - %table.table.dossiers-table.hoverable - %thead - %tr - %th.notification-col - %th.number-col Nº dossier - %th Procédure - %th.status-col Statut - %th.updated-at-col Mis à jour - %tbody - - @dossiers.each do |dossier| - %tr - %td.folder-col - = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do - %span.icon.folder - %td.number-col - = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do - = dossier.id - %td - = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do - = dossier.procedure.libelle - %td.status-col - = link_to(users_dossier_recapitulatif_path(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 - = dossier.updated_at.localtime.strftime("%d/%m/%Y") + - if @dossiers.present? + %table.table.dossiers-table.hoverable + %thead + %tr + %th.notification-col + %th.number-col Nº dossier + %th Procédure + %th.status-col Statut + %th.updated-at-col Mis à jour + %tbody + - @dossiers.each do |dossier| + %tr + %td.folder-col + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do + %span.icon.folder + %td.number-col + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do + = dossier.id + %td + = link_to(users_dossier_recapitulatif_path(dossier), class: 'cell-link') do + = dossier.procedure.libelle + %td.status-col + = link_to(users_dossier_recapitulatif_path(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 + = dossier.updated_at.localtime.strftime("%d/%m/%Y") + = paginate(@dossiers) - = paginate(@dossiers) + - else + %h2.empty-text Aucun dossier. 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 446d7a5ee..2251b9b08 100644 --- a/spec/views/new_user/dossiers/index.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -25,6 +25,19 @@ describe 'new_user/dossiers/index.html.haml', type: :view do expect(rendered).to have_link(dossier.id, href: users_dossier_recapitulatif_path(dossier)) end + context 'quand il n’y a aucun dossier' do + let(:user_dossiers) { [] } + let(:dossiers_invites) { [] } + + it 'n’affiche pas la table' do + expect(rendered).not_to have_selector('.dossiers-table') + end + + it 'affiche un message' do + expect(rendered).to have_text('Aucun dossier') + end + end + context 'quand il n’y a pas de dossiers invités' do let(:dossiers_invites) { [] } @@ -37,7 +50,7 @@ describe 'new_user/dossiers/index.html.haml', type: :view do end end - context 'avec des dossiers invités' do + context 'quand il y a des dossiers invités' do let(:dossiers_invites) { create_list(:dossier, 1) } it 'affiche un titre adapté' do From 20aeae5029f938c03fca449a5db7b8a9f0299897 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Jun 2018 15:00:01 +0000 Subject: [PATCH 08/10] dossiers: ask heavy users for feedback --- .../stylesheets/new_design/_colors.scss | 1 + app/assets/stylesheets/new_design/card.scss | 21 +++++++++++++++---- app/views/new_user/dossiers/index.html.haml | 8 +++++++ app/views/root/patron.html.haml | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/new_design/_colors.scss b/app/assets/stylesheets/new_design/_colors.scss index 7efd6e516..086abb191 100644 --- a/app/assets/stylesheets/new_design/_colors.scss +++ b/app/assets/stylesheets/new_design/_colors.scss @@ -14,3 +14,4 @@ $light-green: lighten($green, 25%); $dark-green: darken($green, 20%); $orange: #F28900; $orange-bg: lighten($orange, 35%); +$light-yellow: #FFFFDE; diff --git a/app/assets/stylesheets/new_design/card.scss b/app/assets/stylesheets/new_design/card.scss index c7c982d3c..01866755d 100644 --- a/app/assets/stylesheets/new_design/card.scss +++ b/app/assets/stylesheets/new_design/card.scss @@ -6,6 +6,12 @@ border: 1px solid $border-grey; margin-bottom: $default-spacer * 2; + .card-title { + font-weight: bold; + font-size: 20px; + margin-bottom: $default-spacer * 2; + } + &.featured { border-top: 8px solid $blue; @@ -14,9 +20,16 @@ } } - .card-title { - font-weight: bold; - font-size: 20px; - margin-bottom: $default-spacer * 2; + &.feedback { + max-width: 600px; + margin: 30px auto; + padding: ($default-spacer * 2) ($default-spacer * 4); + font-size: small; + border: 1px dashed $border-grey; + background: $light-yellow; + + .card-title { + margin-bottom: $default-spacer; + } } } diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 1f27993db..f0d292699 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -15,6 +15,14 @@ .container - if @dossiers.present? + - if @dossiers.total_pages >= 2 + .card.feedback + .card-title Nous avons redesigné la liste des dossiers. + %p + Une suggestion pour améliorer cette page ? Votre avis nous intéresse ! Écrivez-nous à + = mail_to CONTACT_EMAIL, CONTACT_EMAIL, subject: "Amélioration de la liste des dossiers" + \. + %table.table.dossiers-table.hoverable %thead %tr diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index be81ce4d7..af646f8b5 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -84,6 +84,11 @@ Titre de la carte mise en avant Et voici le contenu de la carte + .card.feedback + .card-title + Titre de la carte pour demander un avis + Utilisez cette carte pour informer d’une nouveauté produit ou demander l’avis des utilisateurs. + %h1 Table %table.table From 9f70e72d834dcf9152e58d68e1890a089a0fd6be Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Jun 2018 16:04:04 +0000 Subject: [PATCH 09/10] dossiers: add a button to start a new demarche --- app/assets/stylesheets/new_design/dossiers_headers.scss | 5 +++++ app/assets/stylesheets/new_design/dossiers_table.scss | 4 ++++ app/controllers/new_user/dossiers_controller.rb | 6 ++++++ app/views/new_user/dossiers/index.html.haml | 6 +++++- spec/views/new_user/dossiers/index.html.haml_spec.rb | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/new_design/dossiers_headers.scss diff --git a/app/assets/stylesheets/new_design/dossiers_headers.scss b/app/assets/stylesheets/new_design/dossiers_headers.scss new file mode 100644 index 000000000..4f2425483 --- /dev/null +++ b/app/assets/stylesheets/new_design/dossiers_headers.scss @@ -0,0 +1,5 @@ +.dossiers-headers { + .new-demarche { + float: right; + } +} diff --git a/app/assets/stylesheets/new_design/dossiers_table.scss b/app/assets/stylesheets/new_design/dossiers_table.scss index b3cd92a4e..7c9b6d15d 100644 --- a/app/assets/stylesheets/new_design/dossiers_table.scss +++ b/app/assets/stylesheets/new_design/dossiers_table.scss @@ -77,3 +77,7 @@ padding-right: $default-spacer; } } + +.dossiers-table-empty { + text-align: center; +} diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 44b0faef4..905f78ebe 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -1,5 +1,7 @@ module NewUser class DossiersController < UserController + helper_method :new_demarche_url + before_action :ensure_ownership!, except: [:index, :modifier, :update] before_action :ensure_ownership_or_invitation!, only: [:modifier, :update] before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update] @@ -112,6 +114,10 @@ module NewUser end end + def new_demarche_url + "https://doc.demarches-simplifiees.fr/listes-des-demarches" + end + private def ensure_dossier_can_be_updated diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index f0d292699..266cd06fb 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -1,5 +1,7 @@ .dossiers-headers.sub-header .container + = link_to "Commencer une nouvelle démarche", new_demarche_url, class: "button secondary new-demarche" + - if @dossiers_invites.count == 0 %h1.page-title Mes dossiers @@ -52,4 +54,6 @@ = paginate(@dossiers) - else - %h2.empty-text Aucun dossier. + .dossiers-table-empty + %h2.empty-text Aucun dossier. + = link_to "Commencer une nouvelle démarche", new_demarche_url, class: "button primary" 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 2251b9b08..2b53ab43f 100644 --- a/spec/views/new_user/dossiers/index.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -7,6 +7,7 @@ describe 'new_user/dossiers/index.html.haml', type: :view do let(:current_tab) { 'mes-dossiers' } before do + allow(view).to receive(:new_demarche_url).and_return('#') assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1)) assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1)) assign(:dossiers, Kaminari.paginate_array(user_dossiers).page(1)) From ec0119406862d720fffddcfb37cbb368a8ceeaae Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 26 Jun 2018 17:17:29 +0200 Subject: [PATCH 10/10] Rake task to remove champs with dossier_id = 0 (created by old preview) --- lib/tasks/2018_06_26_purge_preview_dossiers.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/tasks/2018_06_26_purge_preview_dossiers.rake diff --git a/lib/tasks/2018_06_26_purge_preview_dossiers.rake b/lib/tasks/2018_06_26_purge_preview_dossiers.rake new file mode 100644 index 000000000..15f15c218 --- /dev/null +++ b/lib/tasks/2018_06_26_purge_preview_dossiers.rake @@ -0,0 +1,16 @@ +require Rails.root.join("lib", "tasks", "task_helper") + +namespace :'2018_06_26_purge_preview_dossiers' do + task run: :environment do + # We use delete_all and manually destroy associations because it’s so much faster that Champ.where(dossier_id: 0).destroy_all + + c_count = Commentaire.joins(:champ).where(champs: { dossier_id: 0 }).delete_all + rake_puts("Deleted #{c_count} commentaires\n") + a_count = ActiveStorage::Attachment.joins('join champs ON active_storage_attachments.record_id = champs.id').where(champs: { dossier_id: 0 }).delete_all + rake_puts("Deleted #{a_count} attachments\n") + v_count = VirusScan.joins(:champ).where(champs: { dossier_id: 0 }).delete_all + rake_puts("Deleted #{v_count} virus scans\n") + ch_count = Champ.where(dossier_id: 0).delete_all + rake_puts("Deleted #{ch_count} champs\n") + end +end