diff options
author | Alex Kalderimis <akalderimis@gitlab.com> | 2019-08-21 19:23:27 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-08-21 19:23:27 +0000 |
commit | ac94033b2db012f6d9e2dcca2bf48f7ac94f38a0 (patch) | |
tree | b8971803961b85ab06c293b5fbfdff0a398b582e /app/mailers | |
parent | 2ef59c7e4bf133b6d92277b081fb1eb76bc3d0d9 (diff) | |
download | gitlab-ce-ac94033b2db012f6d9e2dcca2bf48f7ac94f38a0.tar.gz |
Handle namespaced models
We encountered issues with setting module headers for namespaced models.
These changes address this. We retain the namespacing, but transform the
classnames to make them into safe email headers.
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/notify.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 5d292094a05..3683f2ea9a9 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -125,9 +125,8 @@ class Notify < BaseMailer def mail_thread(model, headers = {}) add_project_headers add_unsubscription_headers_and_links + add_model_headers(model) - headers["X-GitLab-#{model.class.name}-ID"] = model.id - headers["X-GitLab-#{model.class.name}-IID"] = model.iid if model.respond_to?(:iid) headers['X-GitLab-Reply-Key'] = reply_key @reason = headers['X-GitLab-NotificationReason'] @@ -196,6 +195,18 @@ class Notify < BaseMailer @reply_key ||= SentNotification.reply_key end + # This method applies threading headers to the email to identify + # the instance we are discussing. + # + # All model instances must have `#id`, and may implement `#iid`. + def add_model_headers(object) + # Use replacement so we don't strip the module. + prefix = "X-GitLab-#{object.class.name.gsub(/::/, '-')}" + + headers["#{prefix}-ID"] = object.id + headers["#{prefix}-IID"] = object.iid if object.respond_to?(:iid) + end + def add_project_headers return unless @project |