Skip to content

Commit

Permalink
Overwrite Devise views to enable TermCustomizer
Browse files Browse the repository at this point in the history
Add translation keys

Update mailers:
- [x] confirmamtion_instructions
- [x] email_changed
- [x] invitation_instructions
- [x] invite_admin
- [x] invite_collaborator
- [x] invite_private_user
- [x] organization_admin_invitation_instructions
- [x] password_change
- [x] reset_password_instructions
- [x] unlock_instructions
  • Loading branch information
Kagemaru committed Oct 6, 2022
1 parent ce400b1 commit 6094ce5
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/views/devise/mailer/confirmation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<% if @resource.unconfirmed_email.blank? %>
<p class="email-greeting">
<%= t('.greeting', scope: scope, recipient: @email) %>
</p>
<% end %>

<p class="email-instructions"><%= t('.instruction', scope: scope) %></p>

<p class="email-button email-button__cta"><%= link_to t('.action', scope: scope), confirmation_url(@resource, confirmation_token: @token, host: @resource.organization.host) %></p>
9 changes: 9 additions & 0 deletions app/views/devise/mailer/email_changed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p><%=t('.greeting', scope: scope, recipient: @email) %></p>

<% if @resource.try(:unconfirmed_email?) %>
<p><%= t('.message_unconfirmed', scope: scope, email: @resource.unconfirmed_email) %></p>
<% else %>
<p><%= t('.message', scope: scope, email: @resource.email) %></p>
<% end %>
15 changes: 15 additions & 0 deletions app/views/devise/mailer/invitation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t(".hello", scope: scope, email: @resource.name) %></p>

<p class="email-instructions">
<%= t(".someone_invited_you", scope: scope, application: @resource.organization.name) %>
</p>

<p class="email-button email-button__cta"><%= link_to t(".accept", scope: scope), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim.root_path, host: @resource.organization.host) %></p>

<% if @resource.invitation_due_at %>
<p class="email-small"><%= t(".accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %></p>
<% end %>

<p class="email-small email-closing"><%= t(".ignore", scope: scope).html_safe %></p>
13 changes: 13 additions & 0 deletions app/views/devise/mailer/invitation_instructions.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<%= t(".hello", scope: scope, email: @resource.name) %>

<%= t(".someone_invited_you", scope: scope, application: @resource.organization.name) %>

<%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim.root_path, host: @resource.organization.host) %>

<% if @resource.invitation_due_at %>
<%= t(".accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %>
<% end %>

<%= strip_tags t(".ignore", scope: scope) %>
19 changes: 19 additions & 0 deletions app/views/devise/mailer/invite_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %></p>

<p class="email-instructions">
<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", scope: scope, application: @resource.organization.name) %>
<% end %>
</p>

<p class="email-button email-button__cta"><%= link_to t("devise.mailer.invitation_instructions.accept", scope: scope), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %></p>

<% if @resource.invitation_due_at %>
<p class="email-small"><%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %></p>
<% end %>

<p class="email-small email-closing"><%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %></p>
17 changes: 17 additions & 0 deletions app/views/devise/mailer/invite_admin.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %>

<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", scope: scope, application: @resource.organization.name) %>
<% end %>

<%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

<% if @resource.invitation_due_at %>
<%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %>
<% end %>

<%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %>
19 changes: 19 additions & 0 deletions app/views/devise/mailer/invite_collaborator.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %></p>

<p class="email-instructions">
<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", scope: scope, application: @resource.organization.name) %>
<% end %>
</p>

<p class="email-button email-button__cta"><%= link_to t("devise.mailer.invitation_instructions.accept", scope: scope), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %></p>

<% if @resource.invitation_due_at %>
<p class="email-small"><%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %></p>
<% end %>

<p class="email-small email-closing"><%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %></p>
17 changes: 17 additions & 0 deletions app/views/devise/mailer/invite_collaborator.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %>

<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", scope: scope, application: @resource.organization.name) %>
<% end %>

<%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

<% if @resource.invitation_due_at %>
<%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %>
<% end %>

<%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %>
19 changes: 19 additions & 0 deletions app/views/devise/mailer/invite_private_user.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %></p>

<p class="email-instructions">
<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_private_user", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_private_user", scope: scope, application: @resource.organization.name) %>
<% end %>
</p>

<p class="email-button email-button__cta"><%= link_to t("devise.mailer.invitation_instructions.accept", scope: scope), accept_invitation_url(@resource, invitation_token: @token, host: @resource.organization.host) %></p>

<% if @resource.invitation_due_at %>
<p class="email-small"><%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %></p>
<% end %>

<p class="email-small email-closing"><%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %></p>
17 changes: 17 additions & 0 deletions app/views/devise/mailer/invite_private_user.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.name) %>

<% if @resource.invited_by.present? %>
<%= t("devise.mailer.invitation_instructions.invited_you_as_private_user", scope: scope, invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<% else %>
<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_private_user", scope: scope, application: @resource.organization.name) %>
<% end %>

<%= accept_invitation_url(@resource, invitation_token: @token, host: @resource.organization.host) %>

<% if @resource.invitation_due_at %>
<%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %>
<% end %>

<%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.email) %></p>

<p class="email-instructions"><%= t("devise.mailer.invitation_instructions.someone_invited_you", scope: scope, application: @resource.organization.name) %></p>

<p class="email-button email-button__cta"><%= link_to t("devise.mailer.invitation_instructions.accept", scope: scope), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %></p>

<% if @resource.invitation_due_at %>
<p class="email-small"><%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %></p>
<% end %>

<p class="email-small email-closing"><%= t("devise.mailer.invitation_instructions.ignore", scope: scope).html_safe %></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<%= t("devise.mailer.invitation_instructions.hello", scope: scope, email: @resource.email) %>

<%= t("devise.mailer.invitation_instructions.someone_invited_you", scope: scope, application: @resource.organization.name) %>

<%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %>

<% if @resource.invitation_due_at %>
<%= t("devise.mailer.invitation_instructions.accept_until", scope: scope, due_date: l(@resource.invitation_due_at, format: :long)) %>
<% end %>

<%= strip_tags t("devise.mailer.invitation_instructions.ignore", scope: scope) %>
5 changes: 5 additions & 0 deletions app/views/devise/mailer/password_change.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t(".greeting", scope: scope, recipient: @resource.email) %></p>

<p class="email-instructions"><%= t(".message", scope: scope) %></p>
11 changes: 11 additions & 0 deletions app/views/devise/mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t(".greeting", scope: scope, recipient: @resource.email) %></p>

<p class="email-instructions"><%= t(".instruction", scope: scope) %></p>

<p class="email-button email-button__cta"><%= link_to t(".action", scope: scope), edit_password_url(@resource, reset_password_token: @token, host: @resource.organization.host) %></p>

<p class="email-instruction email-small"><%= t(".instruction_2", scope: scope) %></p>

<p class="email-instruction email-small"><%= t(".instruction_3", scope: scope) %></p>
9 changes: 9 additions & 0 deletions app/views/devise/mailer/unlock_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% scope = Decidim.config.devise_custom_scope.(@organization) %>

<p class="email-greeting"><%= t(".greeting", scope: scope, recipient: @resource.email) %></p>

<p class="email-instructions"><%= t(".message", scope: scope) %></p>

<p class="email-instructions"><%= t(".instruction", scope: scope) %></p>

<p class="email-button email-button__cta"><%= link_to t(".action", scope: scope), unlock_url(@resource, unlock_token: @token, host: @resource.organization.host) %></p>
6 changes: 5 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
config.active_storage.service = ENV['ACTIVE_STORAGE_SERVICE']&.to_sym || :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :letter_opener_web

LetterOpenerWeb.configure do |config|
config.letters_location = Rails.root.join('tmp/letter_opener')
end
config.action_mailer.default_url_options = { port: 3000 }

config.action_mailer.perform_caching = false
Expand Down
17 changes: 17 additions & 0 deletions config/initializers/decidim_ocl_customization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@

# v Specially handled things (here be dragons) v

# Add the Devise custom scope to the Decidim config
# Find all instances with: <% scope = Decidim.config.devise_custom_scope.(@organization) %>
Decidim.config[:devise_custom_scope] = lambda { |org, base = nil|
base ||= %i[decidim_ocl devise]

org_scope =
case org.id

This comment has been minimized.

Copy link
@carlobeltrame

carlobeltrame Dec 5, 2022

Collaborator

@Kagemaru Könnten wir das mit dem tenant_type Setting auf Organization lösen anstatt IDs zu hardcoden? Genau für solche Dinge ist der tenant_type gedacht. Wir müssten dazu nur:

  1. In https://github.com/stadtluzern/decidim-ocl/blob/master/app/views/decidim/system/organizations/_smtp_settings.html.erb#L29 die noch fehlenden Werte für tenant_type ergänzen
  2. Das case Statement hier von org.tenant_type abhängig machen
  3. Nach Deployment auf Integration und Produktion im System Dashboard bei jedem Tenant den Tenant Type (heisst "Spezial-Features" im UI) korrekt setzen

This comment has been minimized.

Copy link
@carlobeltrame

carlobeltrame Dec 5, 2022

Collaborator

Siehe #244

This comment has been minimized.

Copy link
@Kagemaru

Kagemaru Dec 5, 2022

Author Collaborator

Ja sicher, wenn es da schon was gibt, sehr gerne.

when 2 then :dialogluzern
when 7 then :deinklima
when 8 then :gemeinsamerspace
else :other
end

# Ensure that the current tenant is using custom translations for the devise mails
base + [org_scope] if I18n.t(org_scope, scope: base, default: nil)
}

# Setup a controller hook to setup the sms gateway before the
# request is processed. This is done through a notification to
# get access to the `current_*` environment variables within
Expand Down
61 changes: 60 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,46 @@ de:
data_portability_export:
click_button: 'Klicken Sie auf die Schaltfläche "Herunterladen". <br/> Sie haben die Datei bis %{date} verfügbar. <br/> Um die Datei zu öffnen, brauchen Sie <a href=''https://www.7-zip.org/''>7-Zip</a>. Password: %{password}'
decidim_ocl:
devise:
dialogluzern:
devise:
mailer:
confirmation_instructions:
action: Bestätige dein Konto
greeting: Willkommen %{recipient}!
instruction: "Du kannst deine E-Mail-Adresse über den folgenden Link bestätigen:"
email_changed:
greeting: Hallo %{recipient}!
message: Wir schreiben dir, um dich darüber zu informieren, dass deine E-Mail-Adresse zu %{email} geändert wurde.
message_unconfirmed: Wir schreiben dir, um dich darüber zu informieren, dass deine E-Mail-Adresse zu %{email} geändert wurde.
invitation_instructions:
accept: Die Einladung annehmen
accept_until: Diese Einladung wird in %{due_date} fällig.
decline: Einladung ablehnen
hello: Hallo %{email},
ignore: "Wenn du die Einladung nicht annehmen möchtest, ignoriere diese E-Mail.<br /> Dein Konto wird erst erstellt, Wenn du auf den obigen Link zugreifst und deinen Benutzernamen und dein Passwort festlegst."
invited_you_as_admin: "%{invited_by} hat dich als Admin von %{application} eingeladen. Du kannst es über den folgenden Link akzeptieren."
invited_you_as_private_user: "%{invited_by} hat dich als private/n Benutzer/in von %{application} eingeladen. Du kannst es über den folgenden Link akzeptieren."
someone_invited_you: Jemand hat dich zu %{application} eingeladen. Du kannst die Einladung über den folgenden Link akzeptieren.
someone_invited_you_as_admin: Jemand hat dich als Admin von %{application} eingeladen, du kannst die Einladung über den untenstehenden Link akzeptieren.
someone_invited_you_as_private_user: Jemand hat dich als private_user von %{application} eingeladen, du kannst die Einladung über den folgenden Link akzeptieren.
password_change:
greeting: Hallo %{recipient}!
message: Wir kontaktieren dich, um dich darüber zu informieren, dass dein Passwort geändert wurde.
subject: Passwort geändert
reset_password_instructions:
action: Mein Passwort ändern
greeting: Hallo %{recipient}!
instruction: "Jemand hat einen Link angefordert, um dein Passwort zu ändern. Falls du das selbst warst, dann folge diesem Link:"
instruction_2: Falls du das nicht selbst warst, kannst du diese E-Mail ignorieren.
instruction_3: Dein Passwort ändert sich erst, wenn du auf den obigen Link zugreifst und ein neues Passwort erstellst.
unlock_instructions:
action: Entsperre mein Konto
greeting: Hallo %{recipient}!
instruction: "Klicke auf den folgenden Link, um dein Konto zu entsperren:"
message: Dein Konto wurde aufgrund einer übermässigen Anzahl fehlgeschlagener Anmeldeversuche gesperrt.
# deinklima: null
# gemeinsamerspace: null
surveys:
survey_answered_mailer:
answered:
Expand All @@ -1116,7 +1156,7 @@ de:
confirmed: Deine E-Mail-Adresse wurde erfolgreich bestätigt.
mailer:
confirmation_instructions:
subject: "Open Community Luzern: E-Mail bestätigen"
subject: "E-Mail bestätigen"
reset_password_instructions:
action: Mein Passwort ändern
greeting: Hallo %{recipient}!
Expand All @@ -1126,6 +1166,25 @@ de:
subject: Passwort zurücksetzen
invitation_instructions:
hello: Hallo %{email}
subject: Anweisungen zur Einladung
email_changed:
subject: E-Mail geändert
invite_admin:
subject: Du wurdest eingeladen, %{organization} zu verwalten
invite_collaborator:
subject: Du wurdest eingeladen, an %{organization} mitzuarbeiten
invite_private_user:
subject: Du wurdest zu einem privaten Partizipationsprozess auf %{organization} eingeladen
join_conference:
subject: Einladung zur Teilnahme an einer Konferenz
join_meeting:
subject: Einladung zu einer Veranstaltung
organization_admin_invitation_instructions:
subject: Du wurdest eingeladen, %{organization} zu verwalten
password_change:
subject: Passwort geändert
unlock_instructions:
subject: Anweisungen zum Entsperren
passwords:
new:
forgot_your_password: Hast du dein Passwort vergessen?
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ en:
devise:
mailer:
confirmation_instructions:
subject: "Open Community Luzern: Confirm E-Mail"
subject: "Confirm E-Mail"
reset_password_instructions:
action: Change my password
greeting: Hello %{recipient}!
Expand Down

0 comments on commit 6094ce5

Please sign in to comment.