From 91de43de57b3b8ab6ebdb8172e05b27cc539e192 Mon Sep 17 00:00:00 2001 From: davidg73 <david.gunnarsson@univie.ac.at> Date: Wed, 7 May 2025 10:55:43 +0200 Subject: [PATCH] Create route to send test email to admins --- app/controllers/avo/tests_controller.rb | 11 +++++++++++ app/mailers/admins_mailer.rb | 4 ++++ app/views/admins_mailer/test_email.html.erb | 3 +++ app/views/admins_mailer/test_email.text.erb | 3 +++ config/routes.rb | 4 ++++ 5 files changed, 25 insertions(+) create mode 100644 app/controllers/avo/tests_controller.rb create mode 100644 app/views/admins_mailer/test_email.html.erb create mode 100644 app/views/admins_mailer/test_email.text.erb diff --git a/app/controllers/avo/tests_controller.rb b/app/controllers/avo/tests_controller.rb new file mode 100644 index 0000000..bd4a16d --- /dev/null +++ b/app/controllers/avo/tests_controller.rb @@ -0,0 +1,11 @@ +module Avo + class TestsController < ApplicationController + rate_limit to: 1, within: 1.minute, only: :send_test_email, with: -> { redirect_to avo.avo_dashboards_path.concat("/home"), alert: "You can only send one test email every 60 seconds." } + + def send_test_email + AdminsMailer.test_email.deliver_later + + redirect_to avo.avo_dashboards_path.concat("/home"), notice: "Test email sent successfully!" + end + end +end diff --git a/app/mailers/admins_mailer.rb b/app/mailers/admins_mailer.rb index 37703ae..cbda443 100644 --- a/app/mailers/admins_mailer.rb +++ b/app/mailers/admins_mailer.rb @@ -5,4 +5,8 @@ class AdminsMailer < ApplicationMailer @user = user mail(to: ADMINS_EMAIL, subject: "Facem: New User Created") end + + def test_email + mail(to: ADMINS_EMAIL, subject: "Facem: Test Email for Admins") + end end diff --git a/app/views/admins_mailer/test_email.html.erb b/app/views/admins_mailer/test_email.html.erb new file mode 100644 index 0000000..4a8902f --- /dev/null +++ b/app/views/admins_mailer/test_email.html.erb @@ -0,0 +1,3 @@ +<p>Hey there,</p> + +<p>this is just a test email to check how admin emails are distributed.</p> diff --git a/app/views/admins_mailer/test_email.text.erb b/app/views/admins_mailer/test_email.text.erb new file mode 100644 index 0000000..06eb098 --- /dev/null +++ b/app/views/admins_mailer/test_email.text.erb @@ -0,0 +1,3 @@ +Hey there, + +this is just a test email to check how admin emails are distributed. \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ff09c04..985409e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,5 +22,9 @@ if defined? ::Avo get "change_password", to: "settings#edit_password", as: :settings_password put "change_password", to: "settings#update_password" end + + scope :tests do + get "send_email_to_admins", to: "tests#send_test_email", as: :test_email_send + end end end -- GitLab