discourse/lib/email_templates_finder.rb
Osama Sayegh e9aa2c96e1
FIX: Add new/missing email templates to the email templates editor (#28075)
We have a dedicated admin page (`/admin/customize/email_templates`) that lets admins customize all emails that Discourse sends to users. The way this page works is that it lists all translations strings that are used for emails, and the list of translation strings is currently hardcoded and hasn't been updated in years. We've had a number of new emails that Discourse sends, so we should add those templates to the list to let admins easily customize those templates.

Meta topic: https://meta.discourse.org/t/3-2-x-still-ignores-some-custom-email-templates/308203.
2024-07-30 00:27:41 +03:00

34 lines
662 B
Ruby

# frozen_string_literal: true
class EmailTemplatesFinder
def self.list
path = File.join(Rails.root, "config", "locales", "server.en.yml")
yaml = YAML.load_file(path, aliases: true)
new(yaml).list
end
attr_reader :list
def initialize(obj)
@obj = obj
@list = []
check(@obj, "")
@list.sort!
end
private
def check(obj, path)
obj.each do |key, val|
if Hash === val
next_path = "#{path}#{key}"
if val.key?("text_body_template") && val.key?("subject_template")
@list << next_path.sub("en.", "")
else
check(val, "#{next_path}.")
end
end
end
end
end