commit
f20739bbe4
6 changed files with 50 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue