Merge pull request #6813 from tchak/fix-archives-export
fix(archives): only export dossiers in archive groupe_instructeurs
This commit is contained in:
commit
914c2a62f8
4 changed files with 24 additions and 13 deletions
|
@ -209,7 +209,7 @@ class Dossier < ApplicationRecord
|
||||||
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
|
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
|
||||||
scope :hidden_by_administration, -> { where.not(hidden_by_administration_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_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_updated_at, -> (order = :desc) { order(updated_at: order) }
|
||||||
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }
|
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }
|
||||||
|
|
|
@ -97,7 +97,8 @@ class Export < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def io(since: nil)
|
def io(since: nil)
|
||||||
dossiers = Dossier.where(groupe_instructeur: groupe_instructeurs)
|
dossiers = Dossier.visible_by_administration
|
||||||
|
.where(groupe_instructeur: groupe_instructeurs)
|
||||||
if since.present?
|
if since.present?
|
||||||
dossiers = dossiers.where('dossiers.depose_at > ?', since)
|
dossiers = dossiers.where('dossiers.depose_at > ?', since)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,11 +24,13 @@ class ProcedureArchiveService
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_collect_files_archive(archive, instructeur)
|
def new_collect_files_archive(archive, instructeur)
|
||||||
## faux, ca ne doit prendre que certains groupe instructeur ?
|
dossiers = Dossier.visible_by_administration
|
||||||
if archive.time_span_type == 'everything'
|
.where(groupe_instructeur: archive.groupe_instructeurs)
|
||||||
dossiers = @procedure.dossiers.state_termine
|
|
||||||
|
dossiers = if archive.time_span_type == 'everything'
|
||||||
|
dossiers.state_termine
|
||||||
else
|
else
|
||||||
dossiers = @procedure.dossiers.processed_in_month(archive.month)
|
dossiers.processed_in_month(archive.month)
|
||||||
end
|
end
|
||||||
|
|
||||||
attachments = create_list_of_attachments(dossiers)
|
attachments = create_list_of_attachments(dossiers)
|
||||||
|
@ -44,10 +46,13 @@ class ProcedureArchiveService
|
||||||
end
|
end
|
||||||
|
|
||||||
def old_collect_files_archive(archive, instructeur)
|
def old_collect_files_archive(archive, instructeur)
|
||||||
if archive.time_span_type == 'everything'
|
dossiers = Dossier.visible_by_administration
|
||||||
dossiers = @procedure.dossiers.state_termine
|
.where(groupe_instructeur: archive.groupe_instructeurs)
|
||||||
|
|
||||||
|
dossiers = if archive.time_span_type == 'everything'
|
||||||
|
dossiers.state_termine
|
||||||
else
|
else
|
||||||
dossiers = @procedure.dossiers.processed_in_month(archive.month)
|
dossiers.processed_in_month(archive.month)
|
||||||
end
|
end
|
||||||
|
|
||||||
files = create_list_of_attachments(dossiers)
|
files = create_list_of_attachments(dossiers)
|
||||||
|
|
|
@ -5,6 +5,11 @@ describe ProcedureArchiveService do
|
||||||
let(:year) { 2020 }
|
let(:year) { 2020 }
|
||||||
let(:month) { 3 }
|
let(:month) { 3 }
|
||||||
let(:date_month) { Date.strptime("#{year}-#{month}", "%Y-%m") }
|
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
|
describe '#create_pending_archive' do
|
||||||
context 'for a specific month' do
|
context 'for a specific month' do
|
||||||
|
@ -37,7 +42,7 @@ describe ProcedureArchiveService do
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
|
||||||
context 'for a specific month' do
|
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(:year) { 2021 }
|
||||||
let(:mailer) { double('mailer', deliver_later: true) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
|
@ -99,7 +104,7 @@ describe ProcedureArchiveService do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for all months' do
|
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) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
it 'collect files' do
|
it 'collect files' do
|
||||||
|
@ -125,7 +130,7 @@ describe ProcedureArchiveService do
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
|
||||||
context 'for a specific month' do
|
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(:year) { 2021 }
|
||||||
let(:mailer) { double('mailer', deliver_later: true) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
|
@ -228,7 +233,7 @@ describe ProcedureArchiveService do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for all months' do
|
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) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
it 'collect files' do
|
it 'collect files' do
|
||||||
|
|
Loading…
Reference in a new issue