1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# frozen_string_literal: true
class NotePresenter < Gitlab::View::Presenter::Delegated # rubocop:disable Gitlab/NamespacedClass -- Note is not namespaced
include MarkupHelper
presents ::Note, as: :object # because we also have a #note method
delegator_override :note
def note
obfuscate_participants_emails_in_system_note(object.note)
end
delegator_override :note_html
def note_html
# Always use `markdown_field` because it removes references based on the current user context.
text = markdown_field(object, :note)
obfuscate_participants_emails_in_system_note(text)
end
def external_author
return unless object.note_metadata&.external_author
if can?(current_user, :read_external_emails, object)
object.note_metadata.external_author
else
Gitlab::Utils::Email.obfuscated_email(object.note_metadata.external_author, deform: true)
end
end
private
def obfuscate_participants_emails_in_system_note(text)
return text unless object.system?
return text if can?(current_user, :read_external_emails, object.project)
return text if object.system_note_metadata&.action != 'issue_email_participants'
Gitlab::Utils::Email.obfuscate_emails_in_text(text)
end
end
|