Commit 7043c940 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '208393-fix-markdown-email-rendering-permissions' into 'master'

Pass current_user when rendering Markdown in email

See merge request gitlab-org/gitlab!75635
parents 6a8f2b60 d789d73f
...@@ -5,18 +5,18 @@ module Emails ...@@ -5,18 +5,18 @@ module Emails
def new_issue_email(recipient_id, issue_id, reason = nil) def new_issue_email(recipient_id, issue_id, reason = nil)
setup_issue_mail(issue_id, recipient_id) setup_issue_mail(issue_id, recipient_id)
mail_new_thread(@issue, issue_thread_options(@issue.author_id, recipient_id, reason)) mail_new_thread(@issue, issue_thread_options(@issue.author_id, reason))
end end
def issue_due_email(recipient_id, issue_id, reason = nil) def issue_due_email(recipient_id, issue_id, reason = nil)
setup_issue_mail(issue_id, recipient_id) setup_issue_mail(issue_id, recipient_id)
mail_answer_thread(@issue, issue_thread_options(@issue.author_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(@issue.author_id, reason))
end end
def new_mention_in_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) def new_mention_in_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
setup_issue_mail(issue_id, recipient_id) setup_issue_mail(issue_id, recipient_id)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
...@@ -26,7 +26,7 @@ module Emails ...@@ -26,7 +26,7 @@ module Emails
@previous_assignees = [] @previous_assignees = []
@previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any? @previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -34,9 +34,8 @@ module Emails ...@@ -34,9 +34,8 @@ module Emails
setup_issue_mail(issue_id, recipient_id, closed_via: closed_via) setup_issue_mail(issue_id, recipient_id, closed_via: closed_via)
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
@recipient = User.find(recipient_id)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id, reason = nil) def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id, reason = nil)
...@@ -44,13 +43,13 @@ module Emails ...@@ -44,13 +43,13 @@ module Emails
@label_names = label_names @label_names = label_names
@labels_url = project_labels_url(@project) @labels_url = project_labels_url(@project)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
def removed_milestone_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) def removed_milestone_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
setup_issue_mail(issue_id, recipient_id) setup_issue_mail(issue_id, recipient_id)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
def changed_milestone_issue_email(recipient_id, issue_id, milestone, updated_by_user_id, reason = nil) def changed_milestone_issue_email(recipient_id, issue_id, milestone, updated_by_user_id, reason = nil)
...@@ -58,7 +57,7 @@ module Emails ...@@ -58,7 +57,7 @@ module Emails
@milestone = milestone @milestone = milestone
@milestone_url = milestone_url(@milestone) @milestone_url = milestone_url(@milestone)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason).merge({ mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason).merge({
template_name: 'changed_milestone_email' template_name: 'changed_milestone_email'
})) }))
end end
...@@ -68,7 +67,7 @@ module Emails ...@@ -68,7 +67,7 @@ module Emails
@issue_status = status @issue_status = status
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
def issue_moved_email(recipient, issue, new_issue, updated_by_user, reason = nil) def issue_moved_email(recipient, issue, new_issue, updated_by_user, reason = nil)
...@@ -77,7 +76,7 @@ module Emails ...@@ -77,7 +76,7 @@ module Emails
@new_issue = new_issue @new_issue = new_issue
@new_project = new_issue.project @new_project = new_issue.project
@can_access_project = recipient.can?(:read_project, @new_project) @can_access_project = recipient.can?(:read_project, @new_project)
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason)) mail_answer_thread(issue, issue_thread_options(updated_by_user.id, reason))
end end
def issue_cloned_email(recipient, issue, new_issue, updated_by_user, reason = nil) def issue_cloned_email(recipient, issue, new_issue, updated_by_user, reason = nil)
...@@ -87,7 +86,7 @@ module Emails ...@@ -87,7 +86,7 @@ module Emails
@issue = issue @issue = issue
@new_issue = new_issue @new_issue = new_issue
@can_access_project = recipient.can?(:read_project, @new_issue.project) @can_access_project = recipient.can?(:read_project, @new_issue.project)
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason)) mail_answer_thread(issue, issue_thread_options(updated_by_user.id, reason))
end end
def import_issues_csv_email(user_id, project_id, results) def import_issues_csv_email(user_id, project_id, results)
...@@ -124,14 +123,15 @@ module Emails ...@@ -124,14 +123,15 @@ module Emails
@project = @issue.project @project = @issue.project
@target_url = project_issue_url(@project, @issue) @target_url = project_issue_url(@project, @issue)
@closed_via = closed_via @closed_via = closed_via
@recipient = User.find(recipient_id)
@sent_notification = SentNotification.record(@issue, recipient_id, reply_key) @sent_notification = SentNotification.record(@issue, recipient_id, reply_key)
end end
def issue_thread_options(sender_id, recipient_id, reason) def issue_thread_options(sender_id, reason)
{ {
from: sender(sender_id), from: sender(sender_id),
to: User.find(recipient_id).notification_email_for(@project.group), to: @recipient.notification_email_for(@project.group),
subject: subject("#{@issue.title} (##{@issue.iid})"), subject: subject("#{@issue.title} (##{@issue.iid})"),
'X-GitLab-NotificationReason' => reason 'X-GitLab-NotificationReason' => reason
} }
......
...@@ -5,13 +5,13 @@ module Emails ...@@ -5,13 +5,13 @@ module Emails
def new_merge_request_email(recipient_id, merge_request_id, reason = nil) def new_merge_request_email(recipient_id, merge_request_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id, present: true) setup_merge_request_mail(merge_request_id, recipient_id, present: true)
mail_new_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id, reason)) mail_new_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, reason))
end end
def new_mention_in_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil) def new_mention_in_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id, present: true) setup_merge_request_mail(merge_request_id, recipient_id, present: true)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def push_to_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil, new_commits: [], existing_commits: []) def push_to_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil, new_commits: [], existing_commits: [])
...@@ -20,7 +20,7 @@ module Emails ...@@ -20,7 +20,7 @@ module Emails
@existing_commits = existing_commits @existing_commits = existing_commits
@updated_by_user = User.find(updated_by_user_id) @updated_by_user = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def change_in_merge_request_draft_status_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil) def change_in_merge_request_draft_status_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
...@@ -28,7 +28,7 @@ module Emails ...@@ -28,7 +28,7 @@ module Emails
@updated_by_user = User.find(updated_by_user_id) @updated_by_user = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
...@@ -38,7 +38,7 @@ module Emails ...@@ -38,7 +38,7 @@ module Emails
@previous_assignees = [] @previous_assignees = []
@previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any? @previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -49,7 +49,7 @@ module Emails ...@@ -49,7 +49,7 @@ module Emails
@previous_reviewers = [] @previous_reviewers = []
@previous_reviewers = User.where(id: previous_reviewer_ids) if previous_reviewer_ids.any? @previous_reviewers = User.where(id: previous_reviewer_ids) if previous_reviewer_ids.any?
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -58,13 +58,13 @@ module Emails ...@@ -58,13 +58,13 @@ module Emails
@label_names = label_names @label_names = label_names
@labels_url = project_labels_url(@project) @labels_url = project_labels_url(@project)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def removed_milestone_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil) def removed_milestone_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def changed_milestone_merge_request_email(recipient_id, merge_request_id, milestone, updated_by_user_id, reason = nil) def changed_milestone_merge_request_email(recipient_id, merge_request_id, milestone, updated_by_user_id, reason = nil)
...@@ -72,7 +72,7 @@ module Emails ...@@ -72,7 +72,7 @@ module Emails
@milestone = milestone @milestone = milestone
@milestone_url = milestone_url(@milestone) @milestone_url = milestone_url(@milestone)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason).merge({ mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason).merge({
template_name: 'changed_milestone_email' template_name: 'changed_milestone_email'
})) }))
end end
...@@ -81,27 +81,27 @@ module Emails ...@@ -81,27 +81,27 @@ module Emails
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil) def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def request_review_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil) def request_review_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def attention_requested_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil) def attention_requested_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id, reason = nil) def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id, reason = nil)
...@@ -109,27 +109,27 @@ module Emails ...@@ -109,27 +109,27 @@ module Emails
@mr_status = status @mr_status = status
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def merge_request_unmergeable_email(recipient_id, merge_request_id, reason = nil) def merge_request_unmergeable_email(recipient_id, merge_request_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
mail_answer_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, reason))
end end
def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id, reason = nil) def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@resolved_by = User.find(resolved_by_user_id) @resolved_by = User.find(resolved_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, reason))
end end
def merge_when_pipeline_succeeds_email(recipient_id, merge_request_id, mwps_set_by_user_id, reason = nil) def merge_when_pipeline_succeeds_email(recipient_id, merge_request_id, mwps_set_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@mwps_set_by = ::User.find(mwps_set_by_user_id) @mwps_set_by = ::User.find(mwps_set_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(mwps_set_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(mwps_set_by_user_id, reason))
end end
def merge_requests_csv_email(user, project, csv_data, export_status) def merge_requests_csv_email(user, project, csv_data, export_status)
...@@ -154,19 +154,19 @@ module Emails ...@@ -154,19 +154,19 @@ module Emails
@merge_request = MergeRequest.find(merge_request_id) @merge_request = MergeRequest.find(merge_request_id)
@project = @merge_request.project @project = @merge_request.project
@target_url = project_merge_request_url(@project, @merge_request) @target_url = project_merge_request_url(@project, @merge_request)
@recipient = User.find(recipient_id)
if present if present
recipient = User.find(recipient_id) @mr_presenter = @merge_request.present(current_user: @recipient)
@mr_presenter = @merge_request.present(current_user: recipient)
end end
@sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key) @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
end end
def merge_request_thread_options(sender_id, recipient_id, reason = nil) def merge_request_thread_options(sender_id, reason = nil)
{ {
from: sender(sender_id), from: sender(sender_id),
to: User.find(recipient_id).notification_email_for(@project.group), to: @recipient.notification_email_for(@project.group),
subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})"), subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})"),
'X-GitLab-NotificationReason' => reason 'X-GitLab-NotificationReason' => reason
} }
......
...@@ -7,7 +7,7 @@ module Emails ...@@ -7,7 +7,7 @@ module Emails
@commit = @note.noteable @commit = @note.noteable
@target_url = project_commit_url(*note_target_url_options) @target_url = project_commit_url(*note_target_url_options)
mail_answer_note_thread(@commit, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(@commit, @note, note_thread_options(reason))
end end
def note_issue_email(recipient_id, note_id, reason = nil) def note_issue_email(recipient_id, note_id, reason = nil)
...@@ -15,7 +15,7 @@ module Emails ...@@ -15,7 +15,7 @@ module Emails
@issue = @note.noteable @issue = @note.noteable
@target_url = project_issue_url(*note_target_url_options) @target_url = project_issue_url(*note_target_url_options)
mail_answer_note_thread(@issue, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(@issue, @note, note_thread_options(reason))
end end
def note_merge_request_email(recipient_id, note_id, reason = nil) def note_merge_request_email(recipient_id, note_id, reason = nil)
...@@ -23,7 +23,7 @@ module Emails ...@@ -23,7 +23,7 @@ module Emails
@merge_request = @note.noteable @merge_request = @note.noteable
@target_url = project_merge_request_url(*note_target_url_options) @target_url = project_merge_request_url(*note_target_url_options)
mail_answer_note_thread(@merge_request, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(@merge_request, @note, note_thread_options(reason))
end end
def note_snippet_email(recipient_id, note_id, reason = nil) def note_snippet_email(recipient_id, note_id, reason = nil)
...@@ -37,7 +37,7 @@ module Emails ...@@ -37,7 +37,7 @@ module Emails
@target_url = gitlab_snippet_url(@note.noteable) @target_url = gitlab_snippet_url(@note.noteable)
end end
mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(@snippet, @note, note_thread_options(reason))
end end
def note_design_email(recipient_id, note_id, reason = nil) def note_design_email(recipient_id, note_id, reason = nil)
...@@ -49,7 +49,7 @@ module Emails ...@@ -49,7 +49,7 @@ module Emails
design.issue, design.issue,
note_target_url_query_params.merge(vueroute: design.filename) note_target_url_query_params.merge(vueroute: design.filename)
) )
mail_answer_note_thread(design, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(design, @note, note_thread_options(reason))
end end
private private
...@@ -62,10 +62,10 @@ module Emails ...@@ -62,10 +62,10 @@ module Emails
{ anchor: "note_#{@note.id}" } { anchor: "note_#{@note.id}" }
end end
def note_thread_options(recipient_id, reason) def note_thread_options(reason)
{ {
from: sender(@note.author_id), from: sender(@note.author_id),
to: User.find(recipient_id).notification_email_for(@project&.group || @group), to: @recipient.notification_email_for(@project&.group || @group),
subject: subject("#{@note.noteable.title} (#{@note.noteable.reference_link_text})"), subject: subject("#{@note.noteable.title} (#{@note.noteable.reference_link_text})"),
'X-GitLab-NotificationReason' => reason 'X-GitLab-NotificationReason' => reason
} }
...@@ -76,6 +76,7 @@ module Emails ...@@ -76,6 +76,7 @@ module Emails
@note = note_id.is_a?(Note) ? note_id : Note.find(note_id) @note = note_id.is_a?(Note) ? note_id : Note.find(note_id)
@project = @note.project @project = @note.project
@group = @note.noteable.try(:group) @group = @note.noteable.try(:group)
@recipient = User.find(recipient_id)
if (@project || @group) && @note.persisted? if (@project || @group) && @note.persisted?
@sent_notification = SentNotification.record_note(@note, recipient_id, reply_key) @sent_notification = SentNotification.record_note(@note, recipient_id, reply_key)
......
...@@ -9,11 +9,10 @@ module Emails ...@@ -9,11 +9,10 @@ module Emails
namespace_id: @project.namespace, namespace_id: @project.namespace,
project_id: @project project_id: @project
) )
@recipient = User.find(user_id)
user = User.find(user_id)
mail( mail(
to: user.notification_email_for(@project.group), to: @recipient.notification_email_for(@project.group),
subject: subject(release_email_subject) subject: subject(release_email_subject)
) )
end end
......
...@@ -34,4 +34,4 @@ ...@@ -34,4 +34,4 @@
email: true } email: true }
%div{ style: note_style } %div{ style: note_style }
= markdown(note.note, pipeline: :email, author: note.author) = markdown(note.note, pipeline: :email, author: note.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
- if @issue.description - if @issue.description
%div %div
= markdown(@issue.description, pipeline: :email, author: @issue.author) = markdown(@issue.description, pipeline: :email, author: @issue.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
- if @issue.description - if @issue.description
%div %div
= markdown(@issue.description, pipeline: :email, author: @issue.author) = markdown(@issue.description, pipeline: :email, author: @issue.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
- if @merge_request.description - if @merge_request.description
%div %div
= markdown(@merge_request.description, pipeline: :email, author: @merge_request.author) = markdown(@merge_request.description, pipeline: :email, author: @merge_request.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
%p %p
%h4= _("Release notes:") %h4= _("Release notes:")
= markdown(@release.description, pipeline: :email, author: @release.author) = markdown(@release.description, pipeline: :email, author: @release.author, current_user: @recipient)
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
%div %div
= _("%{author_link} wrote:").html_safe % { author_link: link_to(@note.author_name, user_url(@note.author)) } = _("%{author_link} wrote:").html_safe % { author_link: link_to(@note.author_name, user_url(@note.author)) }
%div %div
= markdown(@note.note, pipeline: :email, author: @note.author) = markdown(@note.note, pipeline: :email, author: @note.author, issuable_reference_expansion_enabled: true)
...@@ -6,7 +6,7 @@ module EE ...@@ -6,7 +6,7 @@ module EE
def removed_iteration_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) def removed_iteration_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
setup_issue_mail(issue_id, recipient_id) setup_issue_mail(issue_id, recipient_id)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason))
end end
def changed_iteration_issue_email(recipient_id, issue_id, iteration, updated_by_user_id, reason = nil) def changed_iteration_issue_email(recipient_id, issue_id, iteration, updated_by_user_id, reason = nil)
...@@ -14,7 +14,7 @@ module EE ...@@ -14,7 +14,7 @@ module EE
@iteration = iteration @iteration = iteration
@iteration_url = iteration_url(@iteration) @iteration_url = iteration_url(@iteration)
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason).merge({ mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason).merge({
template_name: 'changed_iteration_email' template_name: 'changed_iteration_email'
})) }))
end end
......
...@@ -7,21 +7,21 @@ module EE ...@@ -7,21 +7,21 @@ module EE
setup_merge_request_mail(merge_request_id, recipient_id, present: true) setup_merge_request_mail(merge_request_id, recipient_id, present: true)
@updated_by = ::User.find(updated_by_user_id) @updated_by = ::User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, reason))
end end
def approved_merge_request_email(recipient_id, merge_request_id, approved_by_user_id, reason = nil) def approved_merge_request_email(recipient_id, merge_request_id, approved_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@approved_by = ::User.find(approved_by_user_id) @approved_by = ::User.find(approved_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(approved_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(approved_by_user_id, reason))
end end
def unapproved_merge_request_email(recipient_id, merge_request_id, unapproved_by_user_id, reason = nil) def unapproved_merge_request_email(recipient_id, merge_request_id, unapproved_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id) setup_merge_request_mail(merge_request_id, recipient_id)
@unapproved_by = ::User.find(unapproved_by_user_id) @unapproved_by = ::User.find(unapproved_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(unapproved_by_user_id, recipient_id, reason)) mail_answer_thread(@merge_request, merge_request_thread_options(unapproved_by_user_id, reason))
end end
end end
end end
......
...@@ -9,7 +9,7 @@ module EE ...@@ -9,7 +9,7 @@ module EE
@epic = @note.noteable @epic = @note.noteable
@target_url = group_epic_url(*note_target_url_options) @target_url = group_epic_url(*note_target_url_options)
mail_answer_note_thread(@epic, @note, note_thread_options(recipient_id, reason)) mail_answer_note_thread(@epic, @note, note_thread_options(reason))
end end
end end
end end
......
...@@ -8,7 +8,7 @@ module Emails ...@@ -8,7 +8,7 @@ module Emails
setup_epic_mail(recipient_id) setup_epic_mail(recipient_id)
mail_new_thread(@epic, epic_thread_options(@epic.author_id, recipient_id, reason)) mail_new_thread(@epic, epic_thread_options(@epic.author_id, reason))
end end
def epic_status_changed_email(recipient_id, epic_id, status, updated_by_user_id, reason = nil) def epic_status_changed_email(recipient_id, epic_id, status, updated_by_user_id, reason = nil)
...@@ -20,7 +20,7 @@ module Emails ...@@ -20,7 +20,7 @@ module Emails
@status = status @status = status
@updated_by = User.find(updated_by_user_id) @updated_by = User.find(updated_by_user_id)
mail_answer_thread(@epic, epic_thread_options(updated_by_user_id, recipient_id, reason)) mail_answer_thread(@epic, epic_thread_options(updated_by_user_id, reason))
end end
private private
...@@ -28,16 +28,17 @@ module Emails ...@@ -28,16 +28,17 @@ module Emails
def setup_epic_mail(recipient_id) def setup_epic_mail(recipient_id)
@group = @epic.group @group = @epic.group
@target_url = group_epic_url(@epic.group, @epic) @target_url = group_epic_url(@epic.group, @epic)
@recipient = User.find(recipient_id)
add_group_headers add_group_headers
@sent_notification = SentNotification.record(@epic, recipient_id, reply_key) @sent_notification = SentNotification.record(@epic, recipient_id, reply_key)
end end
def epic_thread_options(sender_id, recipient_id, reason) def epic_thread_options(sender_id, reason)
{ {
from: sender(sender_id), from: sender(sender_id),
to: User.find(recipient_id).notification_email_for(@epic.group), to: @recipient.notification_email_for(@epic.group),
subject: subject("#{@epic.title} (#{@epic.to_reference})"), subject: subject("#{@epic.title} (#{@epic.to_reference})"),
'X-GitLab-NotificationReason' => reason 'X-GitLab-NotificationReason' => reason
} }
......
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
- if @merge_request.description - if @merge_request.description
%div %div
= markdown(@merge_request.description, pipeline: :email, author: @merge_request.author) = markdown(@merge_request.description, pipeline: :email, author: @merge_request.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
- if @epic.description - if @epic.description
%div %div
= markdown(@epic.description, pipeline: :email, author: @epic.author) = markdown(@epic.description, pipeline: :email, author: @epic.author, current_user: @recipient, issuable_reference_expansion_enabled: true)
...@@ -613,6 +613,28 @@ RSpec.describe Notify do ...@@ -613,6 +613,28 @@ RSpec.describe Notify do
it 'has References header including the notes and issue of the discussion' do it 'has References header including the notes and issue of the discussion' do
expect(subject.header['References'].message_ids).to include("issue_#{note.noteable.id}@#{host}") expect(subject.header['References'].message_ids).to include("issue_#{note.noteable.id}@#{host}")
end end
context 'with private references accessible to the recipient' do
let_it_be(:private_project) { create(:project, :private) }
let_it_be(:private_issue) { create(:issue, :closed, project: private_project) }
before_all do
private_project.add_guest(recipient)
note.update!(note: "#{private_issue.to_reference(full: true)}")
end
let(:html_part) { subject.body.parts.last.to_s }
it 'does not redact the reference' do
expect(html_part).to include("data-reference-type=\"issue\"")
expect(html_part).to include("title=\"#{private_issue.title}\"")
end
it 'renders expanded issue references' do
expect(html_part).to include("#{private_issue.to_reference(full: true)} (closed)")
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment