Skip to content

Commit

Permalink
Maintenance task to examine dossier champs
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Sep 23, 2024
1 parent cf17491 commit 757278c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/mailers/administrateur_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def api_token_expiration(user, tokens)
reply_to: CONTACT_EMAIL)
end

def champ_description(user, champs)
@subject = "Visa description"
@champs = champs
mail(to: user.email, subject: @subject, reply_to: CONTACT_EMAIL)
end

def self.critical_email?(action_name)
action_name == "activate_before_expiration"
end
Expand Down
10 changes: 2 additions & 8 deletions app/tasks/maintenance/dossier_attributes_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ class DossierAttributesTask < MaintenanceTasks::Task
no_collection

def process
Champ.private_only.where(dossier:)
champs = Champ.private_only.where(dossier:)
.joins(type_de_champ: :revision_types_de_champ)
.left_joins(parent: { type_de_champ: :revision_types_de_champ })
.includes(type_de_champ: :revision_type_de_champ)
.order(Arel.sql("coalesce(revision_types_de_champ_types_de_champ.position, procedure_revision_types_de_champ.position)," +
" COALESCE(champs.row_id,' '), procedure_revision_types_de_champ.position"))
.each do |champ|
Rails.logger.info("#{champ.dossier_id}:" +
(champ.parent_id ? champ.parent.libelle + '.' : '').to_s +
"#{champ.libelle}=#{champ.value}" +
":#{champ.type_de_champ.revision_type_de_champ.revision_id}" +
":#{champ.type_de_champ.revision_type_de_champ.id}")
end
AdministrateurMailer.champ_description(User.find(2), champs).deliver_now
end
end
end
22 changes: 22 additions & 0 deletions app/views/administrateur_mailer/champ_description.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- content_for(:title, @subject)

%p
Bonjour,
Voici la description du dossier.

%table.table
%thead
%tr
%th= 'dossier'
%th= 'libelle'
%th= 'Value'
%th= 'Revision'
%th= 'Champ Revision'
%tbody
- @champs.each do |champ|
%tr
%td= champ.dossier_id
%td= (champ.parent_id ? champ.parent.libelle + '.' : '') + champ.libelle
%td= champ.value
%td= champ.type_de_champ.revision_type_de_champ.revision_id
%td= champ.type_de_champ.revision_type_de_champ.id

0 comments on commit 757278c

Please sign in to comment.