Add random anti-trimming marker to mailer layout

What does this MR do and why?

Approval, unapproval and auto-merge notifications (approved_merge_request_email, unapproved_merge_request_email, merge_when_pipeline_succeeds_email) use the mailer layout (app/views/layouts/mailer.html.haml). That layout has no anti-trimming marker. In Gmail, when two approvals arrive in one MR thread, the second email hides its project, branch, author and reviewer details and the "View merge request" action behind the trimmed-content ellipsis.

This MR adds the same hidden random marker (SecureRandom.hex(16)) to the mailer.html.haml footer. The marker renders only when @target_url is set and randomize_notification_email_marker is enabled for @project. With the flag disabled, no marker renders. The marker markup moves to a new EmailsHelper#notification_email_marker helper, which both the notify and mailer layouts now use.

The marker applies to every email that uses the mailer layout and sets @target_url, not only the three above. Notify#email_with_layout uses this layout by default, so profile, access token, group, project, organization, and release emails also get it. This matches the notify layout, which already adds the marker to every email with @target_url. The shared layouts/_mailer partial is unchanged, so devise and unknown_user_mailer emails are unaffected.

The flag is already enabled globally, so this change goes live on deploy.

References

Screenshots or screen recordings

Not applicable - the marker is hidden, and the visible HTML is unchanged.

How to set up and validate locally

  1. Run bundle exec rspec spec/helpers/emails_helper_spec.rb spec/mailers/emails/merge_requests_spec.rb spec/mailers/emails/profile_spec.rb.
  2. After deploy, get two approvals from different approvers on one MR. In Gmail, check that the second approval email keeps its details visible.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

  • No changelog, because the change is behind a feature flag.

Merge request reports

Loading
Loading