refactor(export/archives): holds user profile asking for the archive or export
This commit is contained in:
parent
4dfb3b86ef
commit
72a3f6e89c
18 changed files with 51 additions and 17 deletions
|
@ -14,7 +14,7 @@ module Administrateurs
|
|||
|
||||
def create
|
||||
type = params[:type]
|
||||
archive = Archive.find_or_create_archive(type, year_month, all_groupe_instructeurs)
|
||||
archive = Archive.find_or_create_archive(type, year_month, all_groupe_instructeurs, current_administrateur)
|
||||
if archive.pending?
|
||||
ArchiveCreationJob.perform_later(@procedure, archive, current_administrateur)
|
||||
flash[:notice] = "Votre demande a été prise en compte. Selon le nombre de dossiers, cela peut prendre de quelques minutes à plusieurs heures. Vous recevrez un courriel lorsque le fichier sera disponible."
|
||||
|
|
|
@ -4,7 +4,7 @@ module Administrateurs
|
|||
before_action :ensure_not_super_admin!
|
||||
|
||||
def download
|
||||
export = Export.find_or_create_fresh_export(export_format, all_groupe_instructeurs, current_administrateur.instructeur, **export_options)
|
||||
export = Export.find_or_create_fresh_export(export_format, all_groupe_instructeurs, current_administrateur, **export_options)
|
||||
@dossiers_count = export.count
|
||||
|
||||
if export.available?
|
||||
|
|
|
@ -13,7 +13,7 @@ module Instructeurs
|
|||
|
||||
def create
|
||||
type = params[:type]
|
||||
archive = Archive.find_or_create_archive(type, year_month, groupe_instructeurs)
|
||||
archive = Archive.find_or_create_archive(type, year_month, groupe_instructeurs, current_instructeur)
|
||||
if archive.pending?
|
||||
ArchiveCreationJob.perform_later(@procedure, archive, current_instructeur)
|
||||
flash[:notice] = "Votre demande a été prise en compte. Selon le nombre de dossiers, cela peut prendre de quelques minutes à plusieurs heures. Vous recevrez un courriel lorsque le fichier sera disponible."
|
||||
|
|
|
@ -9,7 +9,8 @@ class Administrateur < ApplicationRecord
|
|||
has_many :api_tokens, inverse_of: :administrateur, dependent: :destroy
|
||||
has_many :commentaire_groupe_gestionnaires, as: :sender
|
||||
has_and_belongs_to_many :default_zones, class_name: 'Zone', join_table: 'default_zones_administrateurs'
|
||||
|
||||
has_many :archives, as: :user_profile
|
||||
has_many :exports, as: :user_profile
|
||||
belongs_to :user
|
||||
belongs_to :groupe_gestionnaire, optional: true
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ class Archive < ApplicationRecord
|
|||
has_and_belongs_to_many :groupe_instructeurs
|
||||
|
||||
has_one_attached :file
|
||||
belongs_to :user_profile, polymorphic: true, optional: true
|
||||
|
||||
scope :for_groupe_instructeur, -> (groupe_instructeur) {
|
||||
joins(:archives_groupe_instructeurs)
|
||||
|
@ -30,9 +31,9 @@ class Archive < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.find_or_create_archive(time_span_type, month, groupe_instructeurs)
|
||||
def self.find_or_create_archive(time_span_type, month, groupe_instructeurs, user_profile)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs)
|
||||
.create_or_find_by(time_span_type: time_span_type, month: month, key: generate_cache_key(groupe_instructeurs))
|
||||
.create_or_find_by(time_span_type:, month:, user_profile:, key: generate_cache_key(groupe_instructeurs))
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -30,6 +30,7 @@ class Export < ApplicationRecord
|
|||
has_and_belongs_to_many :groupe_instructeurs
|
||||
belongs_to :procedure_presentation, optional: true
|
||||
belongs_to :instructeur, optional: true
|
||||
belongs_to :user_profile, polymorphic: true, optional: true
|
||||
|
||||
has_one_attached :file
|
||||
|
||||
|
@ -65,7 +66,7 @@ class Export < ApplicationRecord
|
|||
procedure_presentation_id.present?
|
||||
end
|
||||
|
||||
def self.find_or_create_fresh_export(format, groupe_instructeurs, instructeur, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil)
|
||||
def self.find_or_create_fresh_export(format, groupe_instructeurs, user_profile, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil)
|
||||
attributes = {
|
||||
format:,
|
||||
time_span_type:,
|
||||
|
@ -81,7 +82,7 @@ class Export < ApplicationRecord
|
|||
return recent_export if recent_export.present?
|
||||
|
||||
create!(**attributes, groupe_instructeurs:,
|
||||
instructeur:,
|
||||
user_profile:,
|
||||
procedure_presentation:,
|
||||
procedure_presentation_snapshot: procedure_presentation&.snapshot)
|
||||
end
|
||||
|
@ -146,7 +147,7 @@ class Export < ApplicationRecord
|
|||
end
|
||||
|
||||
def blob
|
||||
service = ProcedureExportService.new(procedure, dossiers_for_export)
|
||||
service = ProcedureExportService.new(procedure, dossiers_for_export, user_profile)
|
||||
|
||||
case format.to_sym
|
||||
when :csv
|
||||
|
|
|
@ -18,8 +18,9 @@ class Instructeur < ApplicationRecord
|
|||
has_many :followed_dossiers, through: :follows, source: :dossier
|
||||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :trusted_device_tokens, dependent: :destroy
|
||||
has_many :archives
|
||||
has_many :bulk_messages, dependent: :destroy
|
||||
has_many :exports, as: :user_profile
|
||||
has_many :archives, as: :user_profile
|
||||
|
||||
belongs_to :user
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class ProcedureArchiveService
|
|||
dossiers.processed_in_month(archive.month)
|
||||
end
|
||||
|
||||
attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers, with_bills: true, include_infos_administration: true, with_champs_private: true)
|
||||
attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers:, user_profile: archive.user_profile)
|
||||
|
||||
DownloadableFileService.download_and_zip(@procedure, attachments, zip_root_folder(archive)) do |zip_filepath|
|
||||
ArchiveUploader.new(procedure: @procedure, filename: archive.filename(@procedure), filepath: zip_filepath)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
class ProcedureExportService
|
||||
attr_reader :procedure, :dossiers
|
||||
|
||||
def initialize(procedure, dossiers)
|
||||
def initialize(procedure, dossiers, user_profile)
|
||||
@procedure = procedure
|
||||
@dossiers = dossiers
|
||||
@user_profile = user_profile
|
||||
end
|
||||
|
||||
def to_csv
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue