feat: add manage-notification-preferences footer to agent notification emails (#15192)
## Description Agent notification emails (new conversation, assignment, mention, new message, SLA misses) currently carry no indication of why the recipient received them or how to turn them off. When recipients cannot easily manage these emails, some mark them as spam, which hurts sender reputation and overall deliverability. This adds a short footer line to agent notification emails only: > You're receiving this email because email notifications are enabled for your account. **Manage notification preferences**. The link points the recipient to their dashboard profile notification settings page (`/app/accounts/:account_id/profile/settings`) so they can disable notifications instead of marking the email as spam. This is a navigational link only, not a one-click unsubscribe (a real unsubscribe flow is a separate future change). Scoping: the mailer layout (`app/views/layouts/mailer/base.liquid`) is shared by all mailers via `ApplicationMailer`. To keep the footer on agent notification emails only, `AgentNotifications::ConversationNotificationsMailer` exposes a `notification_settings_url` liquid local (built from the existing `app_account_url` route helper), and the layout renders the footer line only when that local is present. Transactional and other emails do not set it, so they are unaffected. The enterprise SLA notification methods prepend into the same mailer class, so they inherit the footer automatically. Part of https://linear.app/chatwoot/issue/CW-7752 ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - `bundle exec rspec spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb spec/mailers/confirmation_instructions_spec.rb` — 26 examples, 0 failures. Asserts the footer link and settings URL are present in an agent notification email and absent from a non-notification (confirmation) email. - `bundle exec rspec spec/enterprise/mailers/enterprise/agent_notifications/conversation_notifications_mailer_spec.rb` — 6 examples, 0 failures (SLA notification emails). ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -57,6 +57,10 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
|
||||
|
||||
private
|
||||
|
||||
def liquid_locals
|
||||
super.merge({ notification_settings_url: "#{app_account_url(@conversation.account_id)}/profile/settings" })
|
||||
end
|
||||
|
||||
def liquid_droppables
|
||||
super.merge({
|
||||
user: @agent,
|
||||
|
||||
@@ -129,6 +129,14 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if notification_settings_url != nil and notification_settings_url != '' %}
|
||||
<tr style="margin: 0;">
|
||||
<td class="footer" style="padding: 8px 8px 0; text-align: center; color: #64748B; font-size: 13px; line-height: 21px;">
|
||||
You're receiving this email because email notifications are enabled for your account.
|
||||
<a href="{{ notification_settings_url }}" style="color: #2781F6; font-weight: 600; text-decoration: none;">Manage notification preferences</a>.
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -24,6 +24,11 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
|
||||
it 'renders the receiver email' do
|
||||
expect(mail.to).to eq([agent.email])
|
||||
end
|
||||
|
||||
it 'renders the manage notification preferences footer link' do
|
||||
expect(mail.body.encoded).to match('Manage notification preferences')
|
||||
expect(mail.body.encoded).to include("/app/accounts/#{account.id}/profile/settings")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'conversation_assignment' do
|
||||
|
||||
@@ -50,6 +50,10 @@ RSpec.describe 'Devise::Mailer' do
|
||||
expect(mail.body).not_to include('app/auth/password/edit')
|
||||
end
|
||||
|
||||
it 'does not render the agent notification preferences footer' do
|
||||
expect(mail_body).not_to include('Manage notification preferences')
|
||||
end
|
||||
|
||||
context 'when there is an inviter' do
|
||||
let(:inviter_val) { create(:user, :administrator, skip_confirmation: true, account: account) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user