Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification des mailers #1337

Merged
merged 3 commits into from
Oct 13, 2023
Merged
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
10 changes: 10 additions & 0 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ def low_sms_credits(university, credits)
merge_with_university_infos(university, {})
@credits = credits.to_i
mails = university.users.server_admin.pluck(:email)
I18n.locale = university.default_language.iso_code
subject = t('mailers.notifications.low_sms_credits.subject', credits: @credits)
mail(from: university.mail_from[:full], to: mails, subject: subject)
end

def new_registration(university, user)
merge_with_university_infos(university, {})
@user = user
mails = university.users.where.not(id: @user.id).where(role: [:server_admin, :admin]).pluck(:email)
I18n.locale = university.default_language.iso_code
subject = t('mailers.notifications.new_registration.subject', mail: @user.email)
mail(from: university.mail_from[:full], to: mails, subject: subject)
end

end
5 changes: 2 additions & 3 deletions app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# university_id :uuid not null, indexed
# user_id :uuid not null, indexed
# user_id :uuid indexed
#
# Indexes
#
Expand All @@ -24,11 +24,10 @@
#
class Import < ApplicationRecord
belongs_to :university
belongs_to :user
belongs_to :user, optional: true

has_one_attached_deletable :file


enum kind: { organizations: 0, alumni_cohorts: 1, people_experiences: 2 }, _prefix: :kind
enum status: { pending: 0, finished: 1, finished_with_errors: 2 }

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class User < ApplicationRecord

belongs_to :language
has_many :university_people, class_name: 'University::Person', dependent: :nullify
has_many :imports, class_name: 'Import', dependent: :nullify

scope :ordered, -> { order(:last_name, :first_name) }
scope :for_language, -> (language_id) { where(language_id: language_id) }
Expand Down
6 changes: 6 additions & 0 deletions app/models/user/with_registration_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module User::WithRegistrationContext

validate :extranet_access, on: :create, if: -> { registration_context.is_a?(Communication::Extranet) }

after_create :send_notification_to_admins, unless: -> { registration_context.is_a?(Communication::Extranet) }

private

def extranet_access
Expand All @@ -30,5 +32,9 @@ def user_is_contact?
registration_context.has_feature?(:contacts) && registration_context.connected_people.where(email: email).any?
end

def send_notification_to_admins
NotificationMailer.new_registration(university, self).deliver_later
end

end
end
9 changes: 8 additions & 1 deletion app/views/admin/imports/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

<div class="row">
<div class="col-md-6">
<p><%= t('imports.initiated_by') %> <%= link_to_if can?(:read, @import.user), @import.user, [:admin, @import.user] %></p>
<p>
<%= t('imports.initiated_by') %>
<% if @import.user %>
<%= link_to_if can?(:read, @import.user), @import.user, [:admin, @import.user] %>
<% else %>
<%= t('imports.deleted_user') %>
<% end %>
</p>
<% if @import.file.attached? %>
<p><%= link_to t('download_with_size', size: number_to_human_size(@import.file.byte_size)), url_for(@import.file), class: button_classes %></p>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/mailers/notifications/low_sms_credits.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= t('mailers.notifications.low_sms_credits.body_1_html', credits: @credits) %>
<br>
<%= t('mailers.notifications.low_sms_credits.body_2_html', link: 'https://app.sendinblue.com/billing/addon/customize/sms') %>
<p><%= t('mailers.notifications.low_sms_credits.body_1_html', credits: @credits) %></p>
<p><%= t('mailers.notifications.low_sms_credits.body_2_html', link: 'https://app.brevo.com/billing/account/customize/message-credits') %></p>
<p><%= t('mailers.yours') %></p>
3 changes: 3 additions & 0 deletions app/views/mailers/notifications/new_registration.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p><%= t('mailers.notifications.new_registration.body_1_html', username: @user.to_s) %></p>
<p><%= t('mailers.notifications.new_registration.body_2_html', link: admin_user_url(@user)) %></p>
<p><%= t('mailers.yours') %></p>
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ en:
hello: "Hello %{name}!"
home: Home
imports:
deleted_user: Deleted user
error_msg: "Line %{line}: %{error}"
errors: Errors
example_file_html: Download an <a href="%{link}" target="_blank">example file</a>
Expand Down Expand Up @@ -276,10 +277,14 @@ en:
body_1_html: "Warning, your SMS credits are low: %{credits} credits remaining!"
body_2_html: "Click <a href=\"%{link}\" target=\"_blank\" style=\"color: #c72b43;\">here</a> to refull."
subject: "Osuny - Low SMS Credits (%{credits})"
new_registration:
body_1_html: "A new user (%{username}) just registered."
body_2_html: "Click <a href=\"%{link}\" target=\"_blank\" style=\"color: #c72b43;\">here</a> to see the account."
subject: "A new user just registered: %{mail}"
website_invalid_access_token:
subject: "Expired access token for \"%{website}\""
text_line_1_html: "The access token used for the website \"%{website}\" has expired and does not allow the website to be updated anymore."
pabois marked this conversation as resolved.
Show resolved Hide resolved
text_line_2_html: "To solve this issue, please fill in a new access token by clicking <a href=\"%{url}\">here</a>."
text_line_2_html: "To solve this issue, please fill in a new access token by clicking <a href=\"%{url}\" target=\"_blank\" style=\"color: #c72b43;\">here</a>."
yours: Yours.
menu:
admin: Admin
Expand Down
7 changes: 6 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ fr:
hello: "Bonjour %{name} !"
home: Accueil
imports:
deleted_user: Utilisateur supprimé
error_msg: "Ligne %{line} : %{error}"
errors: Erreurs
example_file_html: Télécharger un <a href="%{link}" target="_blank">fichier d'exemple</a>
Expand Down Expand Up @@ -276,10 +277,14 @@ fr:
body_1_html: "Attention, vos crédits SMS sont bas : %{credits} crédits restants !"
body_2_html: "Cliquez <a href=\"%{link}\" target=\"_blank\" style=\"color: #c72b43;\">ici</a> pour recharger le compte."
subject: "Osuny - Credits SMS bas (%{credits})"
new_registration:
body_1_html: "Un nouvel utilisateur (%{username}) vient de s'enregistrer."
body_2_html: "Cliquez <a href=\"%{link}\" target=\"_blank\" style=\"color: #c72b43;\">ici</a> pour voir son compte."
subject: "Un nouvel utilisateur vient de s'inscrire : %{mail}"
website_invalid_access_token:
subject: Jeton d'accès expiré pour « %{website} »
text_line_1_html: Le jeton d'accès utilisé pour le site « %{website} » a expiré et ne permet plus la mise à jour du site.
text_line_2_html: Pour résoudre ce problème, veuillez renseigner un nouveau jeton d'accès en cliquant <a href=\"%{url}\">ici</a>.
text_line_2_html: "Pour résoudre ce problème, veuillez renseigner un nouveau jeton d'accès en cliquant <a href=\"%{url}\" target=\"_blank\" style=\"color: #c72b43;\">ici</a>."
yours: Cordialement.
menu:
admin: Admin
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231013090313_change_imports_user_nil.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeImportsUserNil < ActiveRecord::Migration[7.0]
def change
change_column_null :imports, :user_id, true
end
end
9 changes: 5 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/mailers/previews/notification_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ def low_sms_credits
NotificationMailer.low_sms_credits(university, credits)
end

# Preview this email at http://localhost:3000/rails/mailers/notification_mailer/new_registration
def new_registration
NotificationMailer.new_registration(university, user)
end


end
Loading