mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 08:13:45 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
39 lines
820 B
Ruby
39 lines
820 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AdminEmailTemplateSerializer < ApplicationSerializer
|
|
attributes :id, :title, :subject, :body, :can_revert?
|
|
|
|
def id
|
|
object
|
|
end
|
|
|
|
def title
|
|
if I18n.exists?("#{object}.title")
|
|
I18n.t("#{object}.title")
|
|
else
|
|
object.gsub(/.*\./, '').titleize
|
|
end
|
|
end
|
|
|
|
def subject
|
|
if I18n.exists?("#{object}.subject_template.other")
|
|
@subject = nil
|
|
else
|
|
@subject ||= I18n.t("#{object}.subject_template")
|
|
end
|
|
end
|
|
|
|
def body
|
|
@body ||= I18n.t("#{object}.text_body_template")
|
|
end
|
|
|
|
def can_revert?
|
|
current_body, current_subject = body, subject
|
|
|
|
I18n.overrides_disabled do
|
|
return I18n.t("#{object}.subject_template") != current_subject ||
|
|
I18n.t("#{object}.text_body_template") != current_body
|
|
end
|
|
end
|
|
end
|