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

Invitation Extranet #2596

Merged
merged 2 commits into from
Jan 23, 2025
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
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ 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
24 changes: 24 additions & 0 deletions app/mailers/extranet_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ExtranetMailer < ApplicationMailer
helper :application # gives access to all helpers defined within `application_helper`.
default template_path: 'mailers/extranet'

def invitation_message(extranet, person)
@extranet = extranet
@person = person
university = @extranet.university
merge_with_university_infos(university, {})

@user = @person.user
# If the person has a user, we use the user's email in priority as it can be used for login.
@email = @user.try(:email) || @person.email

language = @user.try(:language) || university.default_language
@extranet_name = @extranet.to_s_in(language)

I18n.with_locale(language.iso_code) do
subject = t('mailers.extranet.invitation_message.subject', extranet: @extranet_name)
mail(from: university.mail_from[:full], to: @email, subject: subject) if should_send?(@email)
end
end

end
10 changes: 10 additions & 0 deletions app/models/communication/extranet/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ class Communication::Extranet::Connection < ApplicationRecord
belongs_to :extranet, class_name: 'Communication::Extranet'
belongs_to :about, polymorphic: true

after_create_commit :send_invitation_to_person, if: -> { about.is_a?(University::Person) }

def self.permitted_about_classes
[University::Organization, University::Person]
end

protected

def send_invitation_to_person
# Do not send invitation if there is no email on the person's user or the person itself
return unless about.user.try(:email).present? || about.email.present?
ExtranetMailer.invitation_message(extranet, about).deliver_later
end
end
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="col-lg-6">
<%= f.input :email,
required: true,
input_html: { autocomplete: "email" } %>
input_html: { autocomplete: "email", value: params[:email] } %>
<%= f.input :first_name,
required: true,
autofocus: true,
Expand Down
15 changes: 15 additions & 0 deletions app/views/mailers/extranet/invitation_message.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p><%= t('mailers.extranet.invitation_message.text_line_1_html', extranet: @extranet_name) %></p>
<% if @user.present? %>
<p>
<%= t('mailers.extranet.invitation_message.text_line_2_with_user_html',
email: @email,
sign_in_url: new_user_session_url(email: @email, host: @extranet.host)) %>
</p>
<% else %>
<p>
<%= t('mailers.extranet.invitation_message.text_line_2_without_user_html',
email: @email,
sign_up_url: new_user_registration_url(email: @email, host: @extranet.host)) %>
</p>
<% end %>
<p><%= t('mailers.yours') %></p>
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ en:
subtitle: Sign in to your account to continue
look_feel: Look & feel
mailers:
extranet:
invitation_message:
subject: You now have access to the “%{extranet}” extranet
text_line_1_html: You now have access to the “%{extranet}” extranet.
text_line_2_with_user_html: You can sign in with your email address <b>%{email}</b> by clicking <a href="%{sign_in_url}">here</a>.
text_line_2_without_user_html: You can sign up with your email address <b>%{email}</b> by clicking <a href="%{sign_up_url}">here</a>.
notifications:
import:
subject_with_errors: Your import has been processed with errors
Expand Down
6 changes: 6 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ fr:
subtitle: Vous devez être authentifié pour continuer
look_feel: Look & feel
mailers:
extranet:
invitation_message:
subject: Vous avez désormais accès à l'extranet « %{extranet} »
text_line_1_html: Vous avez désormais accès à l'extranet « %{extranet} ».
text_line_2_with_user_html: Vous pouvez vous y connecter avec votre adresse email <b>%{email}</b> en cliquant <a href="%{sign_in_url}">ici</a>.
text_line_2_without_user_html: Vous pouvez vous y inscrire avec votre adresse email <b>%{email}</b> en cliquant <a href="%{sign_up_url}">ici</a>.
notifications:
import:
subject_with_errors: Votre import a bien été traité mais comporte des erreurs
Expand Down
8 changes: 8 additions & 0 deletions test/mailers/previews/base_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ def user
@user ||= university.users.first
end

def person
@person ||= university.people.first
end

def website
@website ||= university.communication_websites.first
end

def extranet
@extranet ||= university.communication_extranets.first
end

def organizations_import
@organizations_import ||= Import.new(
id: SecureRandom.uuid,
Expand Down
10 changes: 10 additions & 0 deletions test/mailers/previews/extranet_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Preview all emails at http://localhost:3000/rails/mailers/extranet_mailer

class ExtranetMailerPreview < BaseMailerPreview

# Preview this email at http://localhost:3000/rails/mailers/extranet_mailer/invitation_message
def invitation_message
ExtranetMailer.invitation_message(extranet, person)
end

end
Loading