commit
d375da1fd4
16 changed files with 116 additions and 112 deletions
|
@ -479,7 +479,7 @@ GEM
|
||||||
byebug (~> 11.0)
|
byebug (~> 11.0)
|
||||||
pry (~> 0.13.0)
|
pry (~> 0.13.0)
|
||||||
public_suffix (4.0.6)
|
public_suffix (4.0.6)
|
||||||
puma (5.6.2)
|
puma (5.6.4)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
pundit (2.1.0)
|
pundit (2.1.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
|
|
|
@ -53,7 +53,10 @@ class API::V1::DossiersController < APIController
|
||||||
end
|
end
|
||||||
|
|
||||||
order = ORDER_DIRECTIONS.fetch(params[:order], :asc)
|
order = ORDER_DIRECTIONS.fetch(params[:order], :asc)
|
||||||
@dossiers = @procedure.dossiers.state_not_brouillon.order_by_created_at(order)
|
@dossiers = @procedure
|
||||||
|
.dossiers
|
||||||
|
.visible_by_administration
|
||||||
|
.order_by_created_at(order)
|
||||||
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render json: {}, status: :not_found
|
render json: {}, status: :not_found
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Instructeurs
|
module Instructeurs
|
||||||
class ArchivesController < InstructeurController
|
class ArchivesController < InstructeurController
|
||||||
before_action :ensure_procedure_enabled
|
before_action :ensure_procedure_enabled, only: [:create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@procedure = procedure
|
@procedure = procedure
|
||||||
|
|
|
@ -72,7 +72,10 @@ module Types
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:)
|
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:)
|
||||||
dossiers = object.dossiers.state_not_brouillon.for_api_v2
|
dossiers = object
|
||||||
|
.dossiers
|
||||||
|
.visible_by_administration
|
||||||
|
.for_api_v2
|
||||||
|
|
||||||
if state.present?
|
if state.present?
|
||||||
dossiers = dossiers.where(state: state)
|
dossiers = dossiers.where(state: state)
|
||||||
|
|
|
@ -10,7 +10,10 @@ module Types
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers(updated_since: nil, created_since: nil, state: nil, order:)
|
def dossiers(updated_since: nil, created_since: nil, state: nil, order:)
|
||||||
dossiers = object.dossiers.state_not_brouillon.for_api_v2
|
dossiers = object
|
||||||
|
.dossiers
|
||||||
|
.visible_by_administration
|
||||||
|
.for_api_v2
|
||||||
|
|
||||||
if state.present?
|
if state.present?
|
||||||
dossiers = dossiers.where(state: state)
|
dossiers = dossiers.where(state: state)
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Archive < ApplicationRecord
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
RETENTION_DURATION = 4.days
|
RETENTION_DURATION = 4.days
|
||||||
|
MAX_SIZE = 100.gigabytes
|
||||||
|
|
||||||
has_and_belongs_to_many :groupe_instructeurs
|
has_and_belongs_to_many :groupe_instructeurs
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,7 @@ class Dossier < ApplicationRecord
|
||||||
.where(hidden_by_administration_at: nil)
|
.where(hidden_by_administration_at: nil)
|
||||||
.merge(visible_by_user.or(state_not_en_construction))
|
.merge(visible_by_user.or(state_not_en_construction))
|
||||||
}
|
}
|
||||||
|
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
|
||||||
|
|
||||||
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) }
|
||||||
|
@ -298,13 +299,18 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
scope :interval_brouillon_close_to_expiration, -> do
|
scope :interval_brouillon_close_to_expiration, -> do
|
||||||
state_brouillon.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
state_brouillon
|
||||||
|
.visible_by_user
|
||||||
|
.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :interval_en_construction_close_to_expiration, -> do
|
scope :interval_en_construction_close_to_expiration, -> do
|
||||||
state_en_construction.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
state_en_construction
|
||||||
|
.visible_by_user_or_administration
|
||||||
|
.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :interval_termine_close_to_expiration, -> do
|
scope :interval_termine_close_to_expiration, -> do
|
||||||
state_termine
|
state_termine
|
||||||
|
.visible_by_user_or_administration
|
||||||
.where(procedures: { procedure_expires_when_termine_enabled: true })
|
.where(procedures: { procedure_expires_when_termine_enabled: true })
|
||||||
.where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
.where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||||
end
|
end
|
||||||
|
@ -336,14 +342,17 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
scope :brouillon_expired, -> do
|
scope :brouillon_expired, -> do
|
||||||
state_brouillon
|
state_brouillon
|
||||||
|
.visible_by_user
|
||||||
.where("brouillon_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
.where("brouillon_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :en_construction_expired, -> do
|
scope :en_construction_expired, -> do
|
||||||
state_en_construction
|
state_en_construction
|
||||||
|
.visible_by_user_or_administration
|
||||||
.where("en_construction_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
.where("en_construction_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :termine_expired, -> do
|
scope :termine_expired, -> do
|
||||||
state_termine
|
state_termine
|
||||||
|
.visible_by_user_or_administration
|
||||||
.where("termine_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
.where("termine_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -361,11 +370,13 @@ class Dossier < ApplicationRecord
|
||||||
# select users who have submitted dossier for the given 'procedures.id'
|
# select users who have submitted dossier for the given 'procedures.id'
|
||||||
users_who_submitted =
|
users_who_submitted =
|
||||||
state_not_brouillon
|
state_not_brouillon
|
||||||
|
.visible_by_user
|
||||||
.joins(:revision)
|
.joins(:revision)
|
||||||
.where("procedure_revisions.procedure_id = procedures.id")
|
.where("procedure_revisions.procedure_id = procedures.id")
|
||||||
.select(:user_id)
|
.select(:user_id)
|
||||||
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
|
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
|
||||||
state_brouillon
|
state_brouillon
|
||||||
|
.visible_by_user
|
||||||
.with_notifiable_procedure
|
.with_notifiable_procedure
|
||||||
.where("procedures.auto_archive_on - INTERVAL :before_closing = :now", { now: Time.zone.today, before_closing: INTERVAL_BEFORE_CLOSING })
|
.where("procedures.auto_archive_on - INTERVAL :before_closing = :now", { now: Time.zone.today, before_closing: INTERVAL_BEFORE_CLOSING })
|
||||||
.where.not(user: users_who_submitted)
|
.where.not(user: users_who_submitted)
|
||||||
|
|
|
@ -161,6 +161,7 @@ class Instructeur < ApplicationRecord
|
||||||
groupe_instructeur_ids = Dossier
|
groupe_instructeur_ids = Dossier
|
||||||
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
||||||
.merge(followed_dossiers)
|
.merge(followed_dossiers)
|
||||||
|
.visible_by_administration
|
||||||
.with_notifications
|
.with_notifications
|
||||||
.select(:groupe_instructeur_id)
|
.select(:groupe_instructeur_id)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ProcedureArchiveService
|
||||||
end
|
end
|
||||||
|
|
||||||
attachments = create_list_of_attachments(dossiers)
|
attachments = create_list_of_attachments(dossiers)
|
||||||
download_and_zip(attachments) do |zip_filepath|
|
download_and_zip(archive, attachments) do |zip_filepath|
|
||||||
ArchiveUploader.new(procedure: @procedure, archive: archive, filepath: zip_filepath)
|
ArchiveUploader.new(procedure: @procedure, archive: archive, filepath: zip_filepath)
|
||||||
.upload
|
.upload
|
||||||
end
|
end
|
||||||
|
@ -46,10 +46,10 @@ class ProcedureArchiveService
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def download_and_zip(attachments, &block)
|
def download_and_zip(archive, attachments, &block)
|
||||||
Dir.mktmpdir(nil, ARCHIVE_CREATION_DIR) do |tmp_dir|
|
Dir.mktmpdir(nil, ARCHIVE_CREATION_DIR) do |tmp_dir|
|
||||||
archive_dir = File.join(tmp_dir, zip_root_folder)
|
archive_dir = File.join(tmp_dir, zip_root_folder(archive))
|
||||||
zip_path = File.join(ARCHIVE_CREATION_DIR, "#{zip_root_folder}.zip")
|
zip_path = File.join(ARCHIVE_CREATION_DIR, "#{zip_root_folder(archive)}.zip")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FileUtils.remove_entry_secure(archive_dir) if Dir.exist?(archive_dir)
|
FileUtils.remove_entry_secure(archive_dir) if Dir.exist?(archive_dir)
|
||||||
|
@ -60,7 +60,7 @@ class ProcedureArchiveService
|
||||||
|
|
||||||
Dir.chdir(tmp_dir) do
|
Dir.chdir(tmp_dir) do
|
||||||
File.delete(zip_path) if File.exist?(zip_path)
|
File.delete(zip_path) if File.exist?(zip_path)
|
||||||
system 'zip', '-0', '-r', zip_path, zip_root_folder
|
system 'zip', '-0', '-r', zip_path, zip_root_folder(archive)
|
||||||
end
|
end
|
||||||
yield(zip_path)
|
yield(zip_path)
|
||||||
ensure
|
ensure
|
||||||
|
@ -70,8 +70,8 @@ class ProcedureArchiveService
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def zip_root_folder
|
def zip_root_folder(archive)
|
||||||
"procedure-#{@procedure.id}"
|
"procedure-#{@procedure.id}-#{archive.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_list_of_attachments(dossiers)
|
def create_list_of_attachments(dossiers)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
%p
|
%p
|
||||||
Ce fichier est
|
Ce fichier est
|
||||||
%b valide une semaine
|
%b valide #{distance_of_time_in_words(Archive::RETENTION_DURATION)}
|
||||||
et peut-être téléchargé
|
et peut-être téléchargé
|
||||||
%b plusieurs fois.
|
%b plusieurs fois.
|
||||||
|
|
||||||
|
|
|
@ -10,51 +10,53 @@
|
||||||
.card.featured
|
.card.featured
|
||||||
.card-title Gestion de vos archives
|
.card-title Gestion de vos archives
|
||||||
%p
|
%p
|
||||||
Vous pouvez télécharger les archives des dossiers terminés depuis la publication de la procédure au format Zip.
|
L'archivage de votre démarche se fait mensuellement. Ainsi pour chaque mois depuis la publication de votre démarche vous pouvez faire une demande de création d'archive.
|
||||||
|
|
||||||
%p
|
%p
|
||||||
Cet export contient les demande déposée par l'usager et la liste des pièces justificatives transmises.
|
Cette archive contient uniquement les dossiers terminés, les demandes déposées par l'usager et la liste des pièces justificatives transmises.
|
||||||
|
|
||||||
%p
|
%p
|
||||||
Cet export n’est pas possible pour le moment pour les démarches à forte volumétrie.
|
Les archives dont le poid est estimé à plus de #{number_to_human_size(Archive::MAX_SIZE)} ne sont pas supportées.
|
||||||
Nous vous invitons à regarder
|
Nous vous invitons à regarder
|
||||||
= link_to 'la documentation', ARCHIVAGE_DOC_URL
|
= link_to 'la documentation', ARCHIVAGE_DOC_URL
|
||||||
afin de voir les options à votre disposition pour mettre en place un système d’archive.
|
afin de voir les options à votre disposition pour mettre en place un système d’archive.
|
||||||
|
- if @procedure.feature_enabled?(:archive_zip_globale)
|
||||||
|
%table.table.hoverable.archive-table
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th
|
||||||
|
%th.text-right Nombre de dossiers terminés
|
||||||
|
%th.text-right Poids estimé
|
||||||
|
%th.center Télécharger
|
||||||
|
|
||||||
%table.table.hoverable.archive-table
|
%tbody
|
||||||
%thead
|
- @count_dossiers_termines_by_month.each do |count_by_month|
|
||||||
%tr
|
- month = count_by_month["month"].to_date
|
||||||
%th
|
- nb_dossiers_termines = count_by_month["count"]
|
||||||
%th.text-right Nombre de dossiers terminés
|
- matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month }
|
||||||
%th.text-right Poids estimé
|
- weight = estimate_weight(matching_archive, nb_dossiers_termines, @average_dossier_weight)
|
||||||
%th.center Télécharger
|
|
||||||
|
|
||||||
%tbody
|
%tr
|
||||||
- @count_dossiers_termines_by_month.each do |count_by_month|
|
%td
|
||||||
- month = count_by_month["month"].to_date
|
= I18n.l(month, format: "%B %Y").capitalize
|
||||||
- nb_dossiers_termines = count_by_month["count"]
|
%td.text-right
|
||||||
- matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month }
|
= nb_dossiers_termines
|
||||||
- weight = estimate_weight(matching_archive, nb_dossiers_termines, @average_dossier_weight)
|
%td.text-right
|
||||||
|
= number_to_human_size(weight)
|
||||||
%tr
|
%td.center
|
||||||
%td
|
- if matching_archive.present?
|
||||||
= I18n.l(month, format: "%B %Y").capitalize
|
- if matching_archive.status == 'generated' && matching_archive.file.attached?
|
||||||
%td.text-right
|
= link_to url_for(matching_archive.file), class: 'button primary' do
|
||||||
= nb_dossiers_termines
|
%span.icon.download-white
|
||||||
%td.text-right
|
= t(:archive_ready_html, scope: [:instructeurs, :procedure], generated_period: time_ago_in_words(matching_archive.updated_at))
|
||||||
= number_to_human_size(weight)
|
- else
|
||||||
%td.center
|
%span.icon.retry
|
||||||
- if matching_archive.present?
|
= t(:archive_pending_html, scope: [:instructeurs, :procedure], created_period: time_ago_in_words(matching_archive.created_at))
|
||||||
- if matching_archive.status == 'generated' && matching_archive.file.attached?
|
- elsif weight < Archive::MAX_SIZE
|
||||||
= link_to url_for(matching_archive.file), class: 'button primary' do
|
= link_to instructeur_archives_path(@procedure, type:'monthly', month: month.strftime('%Y-%m')), method: :post, class: "button" do
|
||||||
%span.icon.download-white
|
%span.icon.new-folder
|
||||||
= t(:archive_ready_html, scope: [:instructeurs, :procedure], generated_period: time_ago_in_words(matching_archive.updated_at))
|
Demander la création
|
||||||
- else
|
- else
|
||||||
%span.icon.retry
|
Archive trop volumineuse
|
||||||
= t(:archive_pending_html, scope: [:instructeurs, :procedure], created_period: time_ago_in_words(matching_archive.created_at))
|
- else
|
||||||
- elsif weight < 1.gigabyte
|
%p Cet fonctionnalité est en cours de deploiement, merci de faire une demande à notre support pour que nous l'activions pour votre démarche
|
||||||
= link_to instructeur_archives_path(@procedure, type:'monthly', month: month.strftime('%Y-%m')), method: :post, class: "button" do
|
|
||||||
%span.icon.new-folder
|
|
||||||
Demander la création
|
|
||||||
- else
|
|
||||||
Archive trop volumineuse
|
|
||||||
|
|
|
@ -15,6 +15,5 @@
|
||||||
- else
|
- else
|
||||||
%span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) }
|
%span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) }
|
||||||
= t("export_#{time_span_type}_pending_html", export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure])
|
= t("export_#{time_span_type}_pending_html", export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure])
|
||||||
- if procedure.feature_enabled?(:archive_zip_globale)
|
%li
|
||||||
%li
|
= link_to t(:download_archive, scope: [:instructeurs, :procedure]), instructeur_archives_path(procedure)
|
||||||
= link_to t(:download_archive, scope: [:instructeurs, :procedure]), instructeur_archives_path(procedure)
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
= form_for(commentaire, url: form_url, html: { class: 'form', data: { persisted_content_id: @dossier.present? ? @dossier.id : "bulk-message-#{@procedure.id}" } }) do |f|
|
= form_for(commentaire, url: form_url, html: { class: 'form', data: { persisted_content_id: @dossier.present? ? @dossier.id : "bulk-message-#{@procedure.id}" } }) do |f|
|
||||||
- dossier = commentaire.dossier
|
- dossier = commentaire.dossier
|
||||||
- placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder')
|
- placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder')
|
||||||
- if instructeur_signed_in? || administrateur_signed_in?
|
- if instructeur_signed_in? || administrateur_signed_in? || expert_signed_in?
|
||||||
- placeholder = t('views.shared.dossiers.messages.form.write_message_placeholder')
|
- placeholder = t('views.shared.dossiers.messages.form.write_message_placeholder')
|
||||||
= f.text_area :body, rows: 5, placeholder: placeholder, title: placeholder, required: true, class: 'message-textarea persisted-input'
|
= f.text_area :body, rows: 5, placeholder: placeholder, title: placeholder, required: true, class: 'message-textarea persisted-input'
|
||||||
.flex.justify-between.wrap
|
.flex.justify-between.wrap
|
||||||
|
|
|
@ -55,11 +55,11 @@ describe ProcedureArchiveService do
|
||||||
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
||||||
|
|
||||||
structure = [
|
structure = [
|
||||||
"procedure-#{procedure.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/attestation-dossier--05-03-2021-00-00-#{dossier.attestation.pdf.id % 10000}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/attestation-dossier--05-03-2021-00-00-#{dossier.attestation.pdf.id % 10000}.pdf",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf"
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf"
|
||||||
]
|
]
|
||||||
expect(files.map(&:filename)).to match_array(structure)
|
expect(files.map(&:filename)).to match_array(structure)
|
||||||
end
|
end
|
||||||
|
@ -75,11 +75,11 @@ describe ProcedureArchiveService do
|
||||||
archive.file.open do |f|
|
archive.file.open do |f|
|
||||||
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
||||||
structure = [
|
structure = [
|
||||||
"procedure-#{procedure.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf",
|
||||||
"procedure-#{procedure.id}/LISEZMOI.txt"
|
"procedure-#{procedure.id}-#{archive.id}/LISEZMOI.txt"
|
||||||
]
|
]
|
||||||
expect(files.map(&:filename)).to match_array(structure)
|
expect(files.map(&:filename)).to match_array(structure)
|
||||||
end
|
end
|
||||||
|
@ -122,16 +122,16 @@ describe ProcedureArchiveService do
|
||||||
archive.file.open do |f|
|
archive.file.open do |f|
|
||||||
zip_entries = ZipTricks::FileReader.read_zip_structure(io: f)
|
zip_entries = ZipTricks::FileReader.read_zip_structure(io: f)
|
||||||
structure = [
|
structure = [
|
||||||
"procedure-#{procedure.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/export-dossier-05-03-2020-00-00-1.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/export-dossier-05-03-2020-00-00-1.pdf",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2021-00-00-#{dossier.id}.pdf",
|
||||||
"procedure-#{procedure.id}/LISEZMOI.txt"
|
"procedure-#{procedure.id}-#{archive.id}/LISEZMOI.txt"
|
||||||
]
|
]
|
||||||
expect(zip_entries.map(&:filename)).to match_array(structure)
|
expect(zip_entries.map(&:filename)).to match_array(structure)
|
||||||
zip_entries.map do |entry|
|
zip_entries.map do |entry|
|
||||||
next unless entry.filename == "procedure-#{procedure.id}/LISEZMOI.txt"
|
next unless entry.filename == "procedure-#{procedure.id}-#{archive.id}/LISEZMOI.txt"
|
||||||
extracted_content = ""
|
extracted_content = ""
|
||||||
extractor = entry.extractor_from(f)
|
extractor = entry.extractor_from(f)
|
||||||
extracted_content << extractor.extract(1024 * 1024) until extractor.eof?
|
extracted_content << extractor.extract(1024 * 1024) until extractor.eof?
|
||||||
|
@ -158,15 +158,15 @@ describe ProcedureArchiveService do
|
||||||
archive.file.open do |f|
|
archive.file.open do |f|
|
||||||
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
||||||
structure = [
|
structure = [
|
||||||
"procedure-#{procedure.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/pieces_justificatives/attestation-dossier--05-03-2020-00-00-#{dossier.attestation.pdf.id % 10000}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/pieces_justificatives/attestation-dossier--05-03-2020-00-00-#{dossier.attestation.pdf.id % 10000}.pdf",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2020-00-00-#{dossier.id}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier.id}/export-#{dossier.id}-05-03-2020-00-00-#{dossier.id}.pdf",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier_2020.id}/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier_2020.id}/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier_2020.id}/export-#{dossier_2020.id}-05-03-2020-00-00-#{dossier_2020.id}.pdf",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier_2020.id}/export-#{dossier_2020.id}-05-03-2020-00-00-#{dossier_2020.id}.pdf",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier_2020.id}/pieces_justificatives/",
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier_2020.id}/pieces_justificatives/",
|
||||||
"procedure-#{procedure.id}/dossier-#{dossier_2020.id}/pieces_justificatives/attestation-dossier--05-03-2020-00-00-#{dossier_2020.attestation.pdf.id % 10000}.pdf"
|
"procedure-#{procedure.id}-#{archive.id}/dossier-#{dossier_2020.id}/pieces_justificatives/attestation-dossier--05-03-2020-00-00-#{dossier_2020.attestation.pdf.id % 10000}.pdf"
|
||||||
]
|
]
|
||||||
expect(files.map(&:filename)).to match_array(structure)
|
expect(files.map(&:filename)).to match_array(structure)
|
||||||
end
|
end
|
||||||
|
@ -176,29 +176,30 @@ describe ProcedureArchiveService do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#download_and_zip' do
|
describe '#download_and_zip' do
|
||||||
|
let(:archive) { build(:archive, id: '3') }
|
||||||
it 'create a tmpdir while block is running' do
|
it 'create a tmpdir while block is running' do
|
||||||
previous_dir_list = Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR)
|
previous_dir_list = Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR)
|
||||||
|
|
||||||
service.send(:download_and_zip, []) do |_zip_file|
|
service.send(:download_and_zip, archive, []) do |_zip_file|
|
||||||
new_dir_list = Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR)
|
new_dir_list = Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR)
|
||||||
expect(previous_dir_list).not_to eq(new_dir_list)
|
expect(previous_dir_list).not_to eq(new_dir_list)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans up its tmpdir after block execution' do
|
it 'cleans up its tmpdir after block execution' do
|
||||||
expect { service.send(:download_and_zip, []) { |zip_file| } }
|
expect { service.send(:download_and_zip, archive, []) { |zip_file| } }
|
||||||
.not_to change { Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR) }
|
.not_to change { Dir.entries(ProcedureArchiveService::ARCHIVE_CREATION_DIR) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a zip with zip utility' do
|
it 'creates a zip with zip utility' do
|
||||||
expected_zip_path = File.join(ProcedureArchiveService::ARCHIVE_CREATION_DIR, "#{service.send(:zip_root_folder)}.zip")
|
expected_zip_path = File.join(ProcedureArchiveService::ARCHIVE_CREATION_DIR, "#{service.send(:zip_root_folder, archive)}.zip")
|
||||||
expect(service).to receive(:system).with('zip', '-0', '-r', expected_zip_path, an_instance_of(String))
|
expect(service).to receive(:system).with('zip', '-0', '-r', expected_zip_path, an_instance_of(String))
|
||||||
service.send(:download_and_zip, []) { |zip_path| }
|
service.send(:download_and_zip, archive, []) { |zip_path| }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans up its generated zip' do
|
it 'cleans up its generated zip' do
|
||||||
expected_zip_path = File.join(ProcedureArchiveService::ARCHIVE_CREATION_DIR, "#{service.send(:zip_root_folder)}.zip")
|
expected_zip_path = File.join(ProcedureArchiveService::ARCHIVE_CREATION_DIR, "#{service.send(:zip_root_folder, archive)}.zip")
|
||||||
service.send(:download_and_zip, []) do |_zip_path|
|
service.send(:download_and_zip, archive, []) do |_zip_path|
|
||||||
expect(File.exist?(expected_zip_path)).to be_truthy
|
expect(File.exist?(expected_zip_path)).to be_truthy
|
||||||
end
|
end
|
||||||
expect(File.exist?(expected_zip_path)).to be_falsey
|
expect(File.exist?(expected_zip_path)).to be_falsey
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
describe 'instructeurs/procedures/_download_dossiers.html.haml', type: :view do
|
|
||||||
let(:current_instructeur) { create(:instructeur) }
|
|
||||||
let(:procedure) { create(:procedure) }
|
|
||||||
|
|
||||||
subject { render 'instructeurs/procedures/download_dossiers.html.haml', procedure: procedure, exports: {} }
|
|
||||||
|
|
||||||
context "when procedure has at least 1 dossier" do
|
|
||||||
it { is_expected.to include("Télécharger tous les dossiers") }
|
|
||||||
|
|
||||||
context "With zip archive enabled" do
|
|
||||||
before { Flipper.enable(:archive_zip_globale, procedure) }
|
|
||||||
it { is_expected.to include("Télécharger une archive au format .zip") }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "With zip archive disabled" do
|
|
||||||
before { Flipper.disable(:archive_zip_globale, procedure) }
|
|
||||||
it { is_expected.not_to include("Télécharger une archive au format .zip") }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -8940,9 +8940,9 @@ minimist-options@4.1.0:
|
||||||
kind-of "^6.0.3"
|
kind-of "^6.0.3"
|
||||||
|
|
||||||
minimist@^1.2.0, minimist@^1.2.5:
|
minimist@^1.2.0, minimist@^1.2.5:
|
||||||
version "1.2.5"
|
version "1.2.6"
|
||||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
|
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
|
||||||
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
|
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
|
||||||
|
|
||||||
minipass-collect@^1.0.2:
|
minipass-collect@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
|
|
Loading…
Reference in a new issue