demarches-normaliennes/app/controllers/instructeurs/archives_controller.rb
simon lehericey 83d60c7b63 archive for all the groups
Co-authored-by: Christophe Robillard <christophe.robillard@beta.gouv.fr>
2021-06-09 10:52:38 +02:00

47 lines
1.8 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Instructeurs
class ArchivesController < InstructeurController
before_action :ensure_procedure_enabled
def index
@procedure = procedure
@average_dossier_weight = procedure.average_dossier_weight
@count_dossiers_termines_by_month = Traitement.count_dossiers_termines_by_month(@procedure)
@nb_dossiers = @count_dossiers_termines_by_month.sum { |count_by_month| count_by_month["count"] }
@poids_total = @nb_dossiers * @average_dossier_weight
@archives = Archive
.for_groupe_instructeur(current_instructeur.groupe_instructeurs.where(procedure: @procedure))
.to_a
end
def create
type = params[:type]
month = Date.strptime(params[:month], '%Y-%m') if params[:month].present?
archive = ProcedureArchiveService.new(procedure).create_pending_archive(current_instructeur, type, month)
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 quelques minutes. Vous recevrez un courriel lorsque le fichier sera disponible."
else
flash[:notice] = "Cette archive a déjà été générée."
end
redirect_to instructeur_archives_path(procedure)
end
private
def ensure_procedure_enabled
if !procedure.feature_enabled?(:archive_zip_globale) || procedure.brouillon?
flash[:alert] = "L'accès aux archives nest pas disponible pour cette démarche, merci den faire la demande à l'équipe de démarches simplifiees"
return redirect_to instructeur_procedure_path(procedure)
end
end
def procedure
current_instructeur
.procedures
.find(params[:procedure_id])
end
end
end