fix(archives): only export dossiers in archive groupe_instructeurs

fix #6793
This commit is contained in:
Paul Chavard 2022-01-13 12:35:07 +01:00
parent 44e30f9866
commit 7937e58caa
4 changed files with 24 additions and 13 deletions

View file

@ -209,7 +209,7 @@ class Dossier < ApplicationRecord
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
scope :visible_by_user, -> { where(hidden_by_user_at: nil) }
scope :visible_by_administration, -> { where("hidden_by_administration_at IS NULL AND NOT (hidden_by_user_at IS NOT NULL AND state = 'en_construction')") }
scope :visible_by_administration, -> { where("hidden_by_administration_at IS NULL AND NOT (hidden_by_user_at IS NOT NULL AND dossiers.state = 'en_construction')") }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }

View file

@ -97,7 +97,8 @@ class Export < ApplicationRecord
end
def io(since: nil)
dossiers = Dossier.where(groupe_instructeur: groupe_instructeurs)
dossiers = Dossier.visible_by_administration
.where(groupe_instructeur: groupe_instructeurs)
if since.present?
dossiers = dossiers.where('dossiers.depose_at > ?', since)
end

View file

@ -24,11 +24,13 @@ class ProcedureArchiveService
end
def new_collect_files_archive(archive, instructeur)
## faux, ca ne doit prendre que certains groupe instructeur ?
if archive.time_span_type == 'everything'
dossiers = @procedure.dossiers.state_termine
dossiers = Dossier.visible_by_administration
.where(groupe_instructeur: archive.groupe_instructeurs)
dossiers = if archive.time_span_type == 'everything'
dossiers.state_termine
else
dossiers = @procedure.dossiers.processed_in_month(archive.month)
dossiers.processed_in_month(archive.month)
end
attachments = create_list_of_attachments(dossiers)
@ -44,10 +46,13 @@ class ProcedureArchiveService
end
def old_collect_files_archive(archive, instructeur)
if archive.time_span_type == 'everything'
dossiers = @procedure.dossiers.state_termine
dossiers = Dossier.visible_by_administration
.where(groupe_instructeur: archive.groupe_instructeurs)
dossiers = if archive.time_span_type == 'everything'
dossiers.state_termine
else
dossiers = @procedure.dossiers.processed_in_month(archive.month)
dossiers.processed_in_month(archive.month)
end
files = create_list_of_attachments(dossiers)

View file

@ -5,6 +5,11 @@ describe ProcedureArchiveService do
let(:year) { 2020 }
let(:month) { 3 }
let(:date_month) { Date.strptime("#{year}-#{month}", "%Y-%m") }
let(:groupe_instructeurs) { instructeur.groupe_instructeurs }
before do
procedure.defaut_groupe_instructeur.add(instructeur)
end
describe '#create_pending_archive' do
context 'for a specific month' do
@ -37,7 +42,7 @@ describe ProcedureArchiveService do
after { Timecop.return }
context 'for a specific month' do
let(:archive) { create(:archive, time_span_type: 'monthly', status: 'pending', month: date_month) }
let(:archive) { create(:archive, time_span_type: 'monthly', status: 'pending', month: date_month, groupe_instructeurs: groupe_instructeurs) }
let(:year) { 2021 }
let(:mailer) { double('mailer', deliver_later: true) }
@ -99,7 +104,7 @@ describe ProcedureArchiveService do
end
context 'for all months' do
let(:archive) { create(:archive, time_span_type: 'everything', status: 'pending') }
let(:archive) { create(:archive, time_span_type: 'everything', status: 'pending', groupe_instructeurs: groupe_instructeurs) }
let(:mailer) { double('mailer', deliver_later: true) }
it 'collect files' do
@ -125,7 +130,7 @@ describe ProcedureArchiveService do
after { Timecop.return }
context 'for a specific month' do
let(:archive) { create(:archive, time_span_type: 'monthly', status: 'pending', month: date_month) }
let(:archive) { create(:archive, time_span_type: 'monthly', status: 'pending', month: date_month, groupe_instructeurs: groupe_instructeurs) }
let(:year) { 2021 }
let(:mailer) { double('mailer', deliver_later: true) }
@ -228,7 +233,7 @@ describe ProcedureArchiveService do
end
context 'for all months' do
let(:archive) { create(:archive, time_span_type: 'everything', status: 'pending') }
let(:archive) { create(:archive, time_span_type: 'everything', status: 'pending', groupe_instructeurs: groupe_instructeurs) }
let(:mailer) { double('mailer', deliver_later: true) }
it 'collect files' do