Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -831,6 +844,7 @@ DEPENDENCIES
kaminari
languagetool-widget
leaflet-rails
letter_opener_web
libretranslate
listen (~> 3.10)
lucide-rails
Expand Down
4 changes: 0 additions & 4 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 6 additions & 10 deletions app/mailers/devise_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@ 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

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

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

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

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

Expand All @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion app/mailers/extranet_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 8 additions & 12 deletions app/mailers/group_notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
8 changes: 4 additions & 4 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/services/brevo/contact_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/services/brevo/sms_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_bugsnag.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% unless Rails.env.development? %>
<% if ENV['BUGSNAG_JAVASCRIPT_KEY'].present? && !Rails.env.development? %>
<script src="//d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js"></script>
<script type="text/javascript" nonce="<%= request.content_security_policy_nonce %>">
Bugsnag.start({
Expand Down
8 changes: 3 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ class Application < Rails::Application
config.i18n.enforce_available_locales = false
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.yml"]

config.internal_domains = ['@noesya.coop', '@osuny.org'].freeze

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp-relay.brevo.com",
port: 587,
address: ENV['SMTP_ADDRESS'].presence || "smtp-relay.brevo.com",
port: ENV['SMTP_PORT'].presence&.to_i || 587,
user_name: ENV['SMTP_USER'],
password: ENV['SMTP_PASSWORD'],
authentication: :plain
authentication: ENV['SMTP_AUTHENTICATION'].presence&.to_sym || :plain
}

# Need for +repage, because of https://github.com/rails/rails/commit/b2ab8dd3a4a184f3115e72b55c237c7b66405bd9
Expand Down
4 changes: 4 additions & 0 deletions config/application.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ SECRET_KEY_BASE:

SKYLIGHT_AUTHENTICATION:

# If not provided, fallback to smtp-relay.brevo.com / 587 / plain
SMTP_ADDRESS:
SMTP_PORT:
SMTP_AUTHENTICATION:
SMTP_PASSWORD:
SMTP_USER:

Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Intercept emails and display them in the browser at /letter_opener
config.action_mailer.delivery_method = :letter_opener_web
Comment thread
jtraulle marked this conversation as resolved.

# Make template changes take effect immediately.
config.action_mailer.perform_caching = false

Expand Down
9 changes: 6 additions & 3 deletions config/initializers/brevo.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Load the gem
require 'brevo'

# Setup authorization
Brevo.configure do |config|
config.api_key['api-key'] = ENV['BREVO_API_KEY']
config.api_key['partner-key'] = ENV['BREVO_API_KEY']
end if ENV['BREVO_API_KEY'].present?

Brevo.class_eval do
def self.active?
ENV['BREVO_API_KEY'].present?
end
end

api_instance = Brevo::AccountApi.new
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/bugsnag.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
return if ENV['BUGSNAG_RUBY_KEY'].blank?

Bugsnag.configure do |config|
config.api_key = ENV['BUGSNAG_RUBY_KEY']
config.release_stage = ENV['APPLICATION_ENV']
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
draw 'showcase'
constraints host: ENV['OSUNY_TRANSPARENCY'] do
get '/' => 'transparency/home#index'
Expand Down
Loading