diff --git a/app/controllers/manager/administrateurs_controller.rb b/app/controllers/manager/administrateurs_controller.rb index 33cd99d46..37587cc83 100644 --- a/app/controllers/manager/administrateurs_controller.rb +++ b/app/controllers/manager/administrateurs_controller.rb @@ -35,6 +35,21 @@ module Manager redirect_to manager_administrateurs_path end + def data_exports + end + + def export_last_month + 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" + end + private def create_administrateur_params diff --git a/app/controllers/manager/instructeurs_controller.rb b/app/controllers/manager/instructeurs_controller.rb index 1cd9c0b9c..9155fabce 100644 --- a/app/controllers/manager/instructeurs_controller.rb +++ b/app/controllers/manager/instructeurs_controller.rb @@ -20,5 +20,17 @@ module Manager redirect_to manager_instructeurs_path end + + def export_last_month + 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" + end end end diff --git a/app/views/manager/administrateurs/data_exports.html.erb b/app/views/manager/administrateurs/data_exports.html.erb new file mode 100644 index 000000000..061ec3280 --- /dev/null +++ b/app/views/manager/administrateurs/data_exports.html.erb @@ -0,0 +1,6 @@ +
diff --git a/app/views/manager/application/_navigation.html.erb b/app/views/manager/application/_navigation.html.erb index f2358dd28..83dc6da3e 100644 --- a/app/views/manager/application/_navigation.html.erb +++ b/app/views/manager/application/_navigation.html.erb @@ -29,6 +29,7 @@ as defined by the routes in the `admin/` namespace <%= link_to "Features", manager_flipper_path, class: "navigation__link" %> <%= link_to "Annonces", super_admins_release_notes_path, class: "navigation__link" %> <%= link_to "Import data via CSV", manager_import_procedure_tags_path, class: "navigation__link" %> + <%= link_to "Export CSV data", manager_data_exports_path, class: "navigation__link" %> <% if Rails.application.secrets.sendinblue[:enabled] && ENV["SAML_IDP_ENABLED"] == "enabled" %> <%= link_to "Sendinblue", ENV.fetch("SENDINBLUE_LOGIN_URL"), class: "navigation__link", target: '_blank' %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index f19f49861..06f613da0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -110,6 +110,10 @@ Rails.application.routes.draw do mount Sidekiq::Web => "/sidekiq" 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 'import_procedure_tags' => 'procedures#import_data' post 'import_tags' => 'procedures#import_tags' root to: "administrateurs#index"