diff --git a/Gemfile b/Gemfile
index 9eef378288..a4aeeb55fa 100644
--- a/Gemfile
+++ b/Gemfile
@@ -104,6 +104,7 @@ group :development do
gem "annotaterb"
gem "better_errors"
gem "binding_of_caller"
+ gem "letter_opener_web"
gem "listen", "~> 3.10"
gem "rack-mini-profiler", "~> 4.0"
gem "spring"
diff --git a/Gemfile.lock b/Gemfile.lock
index 62e4c21ca3..4b7c935bdf 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -213,6 +213,8 @@ GEM
caxlsx (>= 4.0)
cgi (0.5.2)
chartkick (5.2.1)
+ childprocess (5.1.0)
+ logger (~> 1.5)
citeproc (1.1.0)
date
forwardable
@@ -420,9 +422,20 @@ GEM
kaminari-core (1.2.2)
languagetool-widget (8.3.4)
rails
+ launchy (3.1.1)
+ addressable (~> 2.8)
+ childprocess (~> 5.0)
+ logger (~> 1.6)
leaflet-rails (1.9.5)
actionpack (>= 4.2.0)
railties (>= 4.2.0)
+ letter_opener (1.10.0)
+ launchy (>= 2.2, < 4)
+ letter_opener_web (3.0.0)
+ actionmailer (>= 6.1)
+ letter_opener (~> 1.9)
+ railties (>= 6.1)
+ rexml
libretranslate (0.1.0)
json
net-http
@@ -831,6 +844,7 @@ DEPENDENCIES
kaminari
languagetool-widget
leaflet-rails
+ letter_opener_web
libretranslate
listen (~> 3.10)
lucide-rails
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 36682a1b56..7674c94453 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -18,8 +18,4 @@ def merge_with_university_infos(university, opts)
opts[:from] = opts[:reply_to] = university.mail_from[:full]
opts
end
-
- def should_send?(email)
- Rails.env.production? || email.end_with?(*Rails.application.config.internal_domains)
- end
end
diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb
index 0761157f37..5796201ee9 100644
--- a/app/mailers/devise_mailer.rb
+++ b/app/mailers/devise_mailer.rb
@@ -7,7 +7,7 @@ def confirmation_instructions(record, token, opts={})
@record = record
opts = merge_with_university_infos(record.university, opts)
I18n.with_locale(record.language.iso_code.to_sym) do
- super if should_send?(record.email)
+ super
end
end
@@ -15,7 +15,7 @@ def reset_password_instructions(record, token, opts={})
@record = record
opts = merge_with_university_infos(record.university, opts)
I18n.with_locale(record.language.iso_code.to_sym) do
- super if should_send?(record.email)
+ super
end
end
@@ -23,7 +23,7 @@ def unlock_instructions(record, token, opts={})
@record = record
opts = merge_with_university_infos(record.university, opts)
I18n.with_locale(record.language.iso_code.to_sym) do
- super if should_send?(record.email)
+ super
end
end
@@ -31,7 +31,7 @@ def email_changed(record, opts={})
@record = record
opts = merge_with_university_infos(record.university, opts)
I18n.with_locale(record.language.iso_code.to_sym) do
- super if should_send?(record.email)
+ super
end
end
@@ -39,7 +39,7 @@ def password_change(record, opts={})
@record = record
opts = merge_with_university_infos(record.university, opts)
I18n.with_locale(record.language.iso_code.to_sym) do
- super if should_send?(record.email)
+ super
end
end
@@ -49,7 +49,7 @@ def two_factor_authentication_code(record, code, opts = {})
@code = code
@duration = ActiveSupport::Duration.build(Rails.application.config.devise.direct_otp_valid_for).inspect
I18n.with_locale(record.language.iso_code.to_sym) do
- devise_mail(record, :two_factor_authentication_code, opts) if should_send?(record.email)
+ devise_mail(record, :two_factor_authentication_code, opts)
end
end
@@ -69,8 +69,4 @@ def merge_with_university_infos(university, opts)
opts
end
- def should_send?(email)
- Rails.env.production? || email.end_with?(*Rails.application.config.internal_domains)
- end
-
end
diff --git a/app/mailers/extranet_mailer.rb b/app/mailers/extranet_mailer.rb
index 6fbab626cc..7db7c884ae 100644
--- a/app/mailers/extranet_mailer.rb
+++ b/app/mailers/extranet_mailer.rb
@@ -17,7 +17,7 @@ def invitation_message(extranet, person)
I18n.with_locale(@language.iso_code.to_sym) do
mail from: @university.mail_from[:full],
to: @email,
- subject: @l10n.invitation_message_subject if should_send?(@email)
+ subject: @l10n.invitation_message_subject
end
end
diff --git a/app/mailers/group_notification_mailer.rb b/app/mailers/group_notification_mailer.rb
index f738d317ce..ac4975cdb6 100644
--- a/app/mailers/group_notification_mailer.rb
+++ b/app/mailers/group_notification_mailer.rb
@@ -9,9 +9,9 @@ def low_sms_credits(university, credits)
subject = t('mailers.notifications.low_sms_credits.subject', credits: @credits)
mail(
from: university.mail_from[:full],
- bcc: whitelisted_mails,
+ bcc: server_admin_emails,
subject: subject
- ) if whitelisted_mails.any?
+ ) if server_admin_emails.any?
end
end
@@ -22,22 +22,18 @@ def new_registration(university, user)
subject = t('mailers.notifications.new_registration.subject', mail: @user.email)
mail(
from: university.mail_from[:full],
- bcc: whitelisted_mails,
+ bcc: server_admin_emails,
subject: subject
- ) if whitelisted_mails.any?
+ ) if server_admin_emails.any?
end
end
protected
- def whitelisted_mails
- @whitelisted_mails ||= users_emails.select { |mail| should_send?(mail) }
- end
-
- def users_emails
- admin_users = @university.users.where(role: [:server_admin, :admin])
- admin_users = admin_users.where.not(id: @user.id) if @user
- admin_users.pluck(:email)
+ def server_admin_emails
+ @university.users
+ .where(role: [:server_admin])
+ .pluck(:email)
end
end
\ No newline at end of file
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index 81c5b4b8de..f225d3ac26 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -13,7 +13,7 @@ def import(import)
from: import.university.mail_from[:full],
to: import.user.email,
subject: subject
- ) if should_send?(import.user.email)
+ )
end
end
@@ -26,7 +26,7 @@ def emergency_message(emergency_message, user, lang)
from: user.university.mail_from[:full],
to: user.email,
subject: subject
- ) if should_send?(user.email)
+ )
end
end
@@ -40,7 +40,7 @@ def website_invalid_access_token(website, user)
from: user.university.mail_from[:full],
to: user.email,
subject: subject
- ) if should_send?(user.email)
+ )
end
end
@@ -52,7 +52,7 @@ def gdpr_deletion_incoming(university, user)
from: university.mail_from[:full],
to: user.email,
subject: subject
- ) if should_send?(user.email)
+ )
end
end
diff --git a/app/services/brevo/contact_service.rb b/app/services/brevo/contact_service.rb
index 17eaa02b46..455b85dad0 100644
--- a/app/services/brevo/contact_service.rb
+++ b/app/services/brevo/contact_service.rb
@@ -2,10 +2,12 @@ module Brevo
class ContactService
def self.sync(user)
+ return unless Brevo.active?
new(user).sync
end
def self.destroy(contact_id, university_id)
+ return unless Brevo.active?
api_instance = Brevo::ContactsApi.new
other_user = User.where(brevo_contact_id: contact_id).first
diff --git a/app/services/brevo/sms_service.rb b/app/services/brevo/sms_service.rb
index 1a333784b1..dc6696a4d0 100644
--- a/app/services/brevo/sms_service.rb
+++ b/app/services/brevo/sms_service.rb
@@ -4,6 +4,7 @@ class SmsService
SMS_CREDITS_LIMIT = 500
def self.send_mfa_code(user, code)
+ return unless Brevo.active?
duration = ActiveSupport::Duration.build(Rails.application.config.devise.direct_otp_valid_for).inspect
context = user.registration_context.respond_to?(:to_s_in) ? user.registration_context.to_s_in(user.language)
: user.registration_context.to_s
@@ -12,6 +13,7 @@ def self.send_mfa_code(user, code)
end
def sms_credits
+ return unless Brevo.active?
@sms_credits ||= plan.detect { |plan| plan.type == 'sms' }&.credits
end
diff --git a/app/views/application/_bugsnag.html.erb b/app/views/application/_bugsnag.html.erb
index 435d2667b1..3d47b1f157 100644
--- a/app/views/application/_bugsnag.html.erb
+++ b/app/views/application/_bugsnag.html.erb
@@ -1,4 +1,4 @@
-<% unless Rails.env.development? %>
+<% if ENV['BUGSNAG_JAVASCRIPT_KEY'].present? && !Rails.env.development? %>