Skip to content
Snippets Groups Projects
Unverified Commit 618a911e authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

Merge branch 'main' into upgrade-rails-7-1

parents 80d708d0 ae4fea71
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 27 deletions
......@@ -34,8 +34,18 @@ class NotificationMailer < ApplicationMailer
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
......@@ -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
#
......@@ -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 }
......
......@@ -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) }
......
......@@ -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
......@@ -30,5 +32,9 @@ module User::WithRegistrationContext
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
......@@ -5,6 +5,7 @@ module User::WithSyncBetweenUniversities
attr_accessor :skip_server_admin_sync
after_save :sync_between_universities, if: Proc.new { |user| user.server_admin? && !user.skip_server_admin_sync }
after_destroy :remove_from_all_universities, if: Proc.new { |user| user.server_admin? }
def self.synchronize_server_admin_users(source_university, target_university)
source_university.users.server_admin.each do |user|
......@@ -48,4 +49,9 @@ module User::WithSyncBetweenUniversities
user.update_column(:encrypted_password, self.encrypted_password) if user.valid?
end
def remove_from_all_universities
# As a "server_admin" is synced between universities, any removal destroys the accounts of the concerned user in every university
User.where(email: email, role: :server_admin).destroy_all
end
end
......@@ -13,8 +13,17 @@
<span class="close_text"><%= t 'folder.close' %></span>
<% end %>
<div class="btn-group ms-auto" role="group">
<%= edit_link category %>
<%= destroy_link category %>
<%= link_to t('show'),
admin_communication_website_category_path(website_id: @website.id, id: category.id),
class: 'action ps-3' %>
<%= link_to t('edit'),
edit_admin_communication_website_category_path(website_id: @website.id, id: category.id),
class: 'action ps-3' %>
<%= link_to t('delete'),
admin_communication_website_category_path(website_id: @website.id, id: category.id),
method: :delete,
data: { confirm: t('please_confirm') },
class: 'action text-danger ps-3' %>
</div>
</div>
<ul class="list-unstyled treeview__children js-treeview-children js-treeview-sortable-container ms-4" data-id="<%= category.id %>">
......
<% content_for :title, "#{Communication::Website::Category.model_name.human(count: 2)} (#{@categories.count})" %>
<%= render 'admin/communication/websites/sidebar' do %>
<div class="card">
<div class="card-body">
<ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container"
data-id=""
data-sort-url="<%= reorder_admin_communication_website_categories_path %>">
<%= render 'treebranch', categories: @root_categories %>
</ul>
</div>
</div>
<% end %>
<% content_for :action_bar_right do %>
<%= create_link Communication::Website::Category %>
<%
action = create_link Communication::Website::Category
%>
<%= osuny_panel Communication::Website::Category.model_name.human(count: 2), action: action do %>
<ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container"
data-id=""
data-sort-url="<%= reorder_admin_communication_website_categories_path %>">
<%= render 'treebranch', categories: @root_categories %>
</ul>
<% end %>
<% end %>
......@@ -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 %>
......
<%= 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') %>
\ No newline at end of file
<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>
\ No newline at end of file
<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>
\ No newline at end of file
......@@ -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>
......@@ -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."
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
......
......@@ -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>
......@@ -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
......
class ChangeImportsUserNil < ActiveRecord::Migration[7.0]
def change
change_column_null :imports, :user_id, true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do
ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
......@@ -229,6 +229,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do
t.text "home_sentence"
t.text "sass"
t.text "css"
t.boolean "allow_experiences_modification", default: true
t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about"
t.index ["university_id"], name: "index_communication_extranets_on_university_id"
end
......@@ -389,7 +390,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do
t.index ["university_id"], name: "index_communication_website_pages_on_university_id"
end
create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "website_id", null: false
t.string "about_type", null: false
......@@ -650,7 +651,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do
t.integer "kind"
t.integer "status", default: 0
t.uuid "university_id", null: false
t.uuid "user_id", null: false
t.uuid "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["university_id"], name: "index_imports_on_university_id"
......
......@@ -23,5 +23,10 @@ class NotificationMailerPreview < BaseMailerPreview
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment