diff --git a/app/controllers/manager/administrateurs_controller.rb b/app/controllers/manager/administrateurs_controller.rb index 238793ee7..e4e84f86c 100644 --- a/app/controllers/manager/administrateurs_controller.rb +++ b/app/controllers/manager/administrateurs_controller.rb @@ -40,16 +40,20 @@ module Manager def data_exports end - def export_last_month + def export_last_half_year administrateurs = Administrateur.joins(:user).where(created_at: 6.months.ago..).where.not(users: { email_verified_at: nil }) - csv = CSV.generate(headers: true) do |csv| - csv << ['ID', 'Email', 'Date de création'] - administrateurs.each do |administrateur| - csv << [administrateur.id, administrateur.email, administrateur.created_at] - end - end - send_data csv, filename: "administrateurs_#{Date.today.strftime('%d-%m-%Y')}.csv" + csv = generate_csv(administrateurs) + + send_data csv, filename: "administrateurs_recents_#{Date.today.strftime('%d-%m-%Y')}.csv" + end + + def export_with_publiee_procedure + administrateurs = Administrateur.joins(:user).where.not(users: { email_verified_at: nil }).joins(:procedures).where(procedures: { aasm_state: [:publiee] }) + + csv = generate_csv(administrateurs) + + send_data csv, filename: "administrateurs_actifs_#{Date.today.strftime('%d-%m-%Y')}.csv" end private diff --git a/app/controllers/manager/application_controller.rb b/app/controllers/manager/application_controller.rb index 5586966e2..c10ebfffb 100644 --- a/app/controllers/manager/application_controller.rb +++ b/app/controllers/manager/application_controller.rb @@ -56,5 +56,14 @@ module Manager payload[:to_log] = to_log end + + def generate_csv(users) + CSV.generate(headers: true) do |csv| + csv << ['ID', 'Email', 'Date de création'] + users.each do |user| + csv << [user.id, user.email, user.created_at] + end + end + end end end diff --git a/app/controllers/manager/instructeurs_controller.rb b/app/controllers/manager/instructeurs_controller.rb index 3acb6a784..072df90fc 100644 --- a/app/controllers/manager/instructeurs_controller.rb +++ b/app/controllers/manager/instructeurs_controller.rb @@ -23,16 +23,20 @@ module Manager redirect_to manager_instructeurs_path end - def export_last_month + def export_last_half_year instructeurs = Instructeur.joins(:user).where(created_at: 6.months.ago..).where.not(users: { email_verified_at: nil }) - csv = CSV.generate(headers: true) do |csv| - csv << ['ID', 'Email', 'Date de création'] - instructeurs.each do |instructeur| - csv << [instructeur.id, instructeur.email, instructeur.created_at] - end - end - send_data csv, filename: "instructeurs_#{Date.today.strftime('%d-%m-%Y')}.csv" + csv = generate_csv(instructeurs) + + send_data csv, filename: "instructeurs_recents_#{Date.today.strftime('%d-%m-%Y')}.csv" + end + + def export_currently_active + instructeurs = Instructeur.joins(:user).where(users: { current_sign_in_at: 6.months.ago.. }).where.not(users: { email_verified_at: nil }) + + csv = generate_csv(instructeurs) + + send_data csv, filename: "instructeurs_actifs_#{Date.today.strftime('%d-%m-%Y')}.csv" end end end diff --git a/app/views/manager/administrateurs/data_exports.html.erb b/app/views/manager/administrateurs/data_exports.html.erb index 061ec3280..1e3d897cd 100644 --- a/app/views/manager/administrateurs/data_exports.html.erb +++ b/app/views/manager/administrateurs/data_exports.html.erb @@ -1,6 +1,19 @@ -
+
+

+ Export des administrateurs et instructeurs +

+
+ +
+

Pour les invitations aux webinaires

-
+ +

Pour les newsletters

+ + diff --git a/config/routes.rb b/config/routes.rb index ceda9034e..e6440634a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -115,8 +115,10 @@ Rails.application.routes.draw do end get 'data_exports' => 'administrateurs#data_exports' - get 'exports/administrateurs/last_month' => 'administrateurs#export_last_month' - get 'exports/instructeurs/last_month' => 'instructeurs#export_last_month' + get 'exports/administrateurs/last_half_year' => 'administrateurs#export_last_half_year' + get 'exports/instructeurs/last_half_year' => 'instructeurs#export_last_half_year' + get 'exports/administrateurs/with_publiee_procedure' => 'administrateurs#export_with_publiee_procedure' + get 'exports/instructeurs/currently_active' => 'instructeurs#export_currently_active' get 'import_procedure_tags' => 'procedures#import_data' post 'import_tags' => 'procedures#import_tags'