DEV: Add option to send system message to groups (#12256)

This commit is contained in:
Gerhard Schlager 2021-03-02 18:51:50 +01:00 committed by GitHub
parent 8fd46c04ea
commit a96a5db0fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -26,12 +26,12 @@ module Jobs
end
def notify_user(ex)
post = SystemMessage.create_from_system_user(
SystemMessage.create_from_system_user(
Discourse.system_user,
:backup_failed,
target_group_names: Group[:admins].name,
logs: "#{ex}\n" + ex.backtrace.join("\n")
)
post.topic.invite_group(Discourse.system_user, Group[:admins])
end
end
end

View File

@ -18,15 +18,16 @@ class SystemMessage
end
def create(type, params = {})
from_system = params.delete(:from_system)
target_group_names = params.delete(:target_group_names)
params = defaults.merge(params)
from_system = params[:from_system] || false
title = params[:message_title] || I18n.with_locale(@recipient.effective_locale) { I18n.t("system_messages.#{type}.subject_template", params) }
raw = params[:message_raw] || I18n.with_locale(@recipient.effective_locale) { I18n.t("system_messages.#{type}.text_body_template", params) }
if from_system
user = Discourse.system_user
target_group_names = nil
else
user = Discourse.site_contact_user
target_group_names = Group.exists?(name: SiteSetting.site_contact_group_name) ? SiteSetting.site_contact_group_name : nil