From 1781a49932b2fbd369c40fbe140dc4e65ba5e094 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 20 Jun 2019 12:11:39 +0200 Subject: [PATCH 1/4] Add order param to API --- app/controllers/api/v1/dossiers_controller.rb | 4 +++- .../api/v1/dossiers_controller_spec.rb | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 5eb8eaadd..980ba7e81 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -2,6 +2,7 @@ class API::V1::DossiersController < APIController before_action :fetch_procedure_and_check_token DEFAULT_PAGE_SIZE = 100 + ORDER_DIRECTIONS = { 'asc' => :asc, 'desc' => :desc } def index dossiers = @dossiers.page(params[:page]).per(per_page) @@ -45,7 +46,8 @@ class API::V1::DossiersController < APIController render json: {}, status: :unauthorized end - @dossiers = @procedure.dossiers.state_not_brouillon.order_for_api + order = ORDER_DIRECTIONS.fetch(params[:order], :asc) + @dossiers = @procedure.dossiers.state_not_brouillon.order_for_api(order) rescue ActiveRecord::RecordNotFound render json: {}, status: :not_found diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index cee273d56..0e8a01186 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -24,7 +24,8 @@ describe API::V1::DossiersController do end describe 'GET index' do - let(:retour) { get :index, params: { token: token, procedure_id: procedure_id } } + let(:order) { nil } + let(:retour) { get :index, params: { token: token, procedure_id: procedure_id, order: order }.compact } subject { retour } @@ -80,6 +81,23 @@ describe API::V1::DossiersController do it { expect(subject[:state]).to eq("initiated") } it { expect(subject.keys.size).to eq(4) } end + + describe 'order' do + let!(:dossier1) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) } + let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) } + + context 'asc' do + let(:order) { 'asc' } + + it { expect(subject.map { |dossier| dossier[:id] }).to eq([dossier.id, dossier1.id, dossier2.id]) } + end + + context 'desc' do + let(:order) { 'desc' } + + it { expect(subject.map { |dossier| dossier[:id] }).to eq([dossier2.id, dossier1.id, dossier.id]) } + end + end end context 'when there are multiple pages' do From 0e519679ceb4c421df51dac8787c4b03702e103c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 20 Jun 2019 16:27:49 +0200 Subject: [PATCH 2/4] Remove orphaned piece_justificatives --- ..._purge_unattached_piece_justificative.rake | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake diff --git a/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake b/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake new file mode 100644 index 000000000..08d341254 --- /dev/null +++ b/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake @@ -0,0 +1,21 @@ +namespace :after_party do + desc 'Deployment task: purge_unattached_piece_justificative' + task purge_unattached_piece_justificative: :environment do + puts "Running deploy task 'purge_unattached_piece_justificative'" + + piece_justificatives = PieceJustificative.where(type_de_piece_justificative_id: nil) + progress = ProgressReport.new(piece_justificatives.count) + piece_justificatives.find_each do |pj| + # detach from dossier to ensure we do not trigger touch + pj.update_column(:dossier_id, nil) + pj.remove_content! + pj.destroy + progress.inc + end + progress.finish + + # 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: '20190521131030' + end +end From 44b9a2ef12c808c3a384f59062580d0dbc04e053 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Fri, 21 Jun 2019 09:50:33 +0200 Subject: [PATCH 3/4] Include application_helper in ApplicationMailer fixes a crash in activate_before_expiration.haml (sentry RAILS-40) --- app/mailers/application_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 8700d4539..a2612765e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base + helper :application # gives access to all helpers defined within `application_helper`. default from: "demarches-simplifiees.fr <#{CONTACT_EMAIL}>" layout 'mailer' end From 50cf6059e654b3c9d8f666974798278525a15ac7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Jun 2019 15:49:02 +0200 Subject: [PATCH 4/4] =?UTF-8?q?tasks:=20ensure=20creating=20an=20empty=20c?= =?UTF-8?q?hamp=20doesn=E2=80=99t=20display=20a=20notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...justificative_to_champ_piece_jointe_migration_service.rb | 6 ++++-- ...ficative_to_champ_piece_jointe_migration_service_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/services/piece_justificative_to_champ_piece_jointe_migration_service.rb b/app/services/piece_justificative_to_champ_piece_jointe_migration_service.rb index 48b228266..69cebd114 100644 --- a/app/services/piece_justificative_to_champ_piece_jointe_migration_service.rb +++ b/app/services/piece_justificative_to_champ_piece_jointe_migration_service.rb @@ -85,8 +85,10 @@ class PieceJustificativeToChampPieceJointeMigrationService ) else champ.update_columns( - updated_at: dossier.updated_at, - created_at: dossier.created_at + created_at: dossier.created_at, + # Set an updated_at date that won't cause notifications to appear + # on gestionnaires' dashboard. + updated_at: dossier.created_at ) end diff --git a/spec/services/piece_justificative_to_champ_piece_jointe_migration_service_spec.rb b/spec/services/piece_justificative_to_champ_piece_jointe_migration_service_spec.rb index df63d3014..48b60b32b 100644 --- a/spec/services/piece_justificative_to_champ_piece_jointe_migration_service_spec.rb +++ b/spec/services/piece_justificative_to_champ_piece_jointe_migration_service_spec.rb @@ -113,9 +113,9 @@ describe PieceJustificativeToChampPieceJointeMigrationService do dossier.reload end - it 'the champ has the same timestamps as the dossier' do + it 'the champ doesn’t trigger a notification' do expect(dossier.champs.last.created_at).to eq(initial_dossier_timestamps[:created_at]) - expect(dossier.champs.last.updated_at).to eq(initial_dossier_timestamps[:updated_at]) + expect(dossier.champs.last.updated_at).to eq(initial_dossier_timestamps[:created_at]) end it 'does not change the dossier timestamps' do