Merge pull request #2491 from techAPJ/system-user-notifications

FEATURE: Send notification by system user for bulk invite
This commit is contained in:
Régis Hanol 2014-07-02 11:19:04 +02:00
commit d23c7cdc65
2 changed files with 20 additions and 2 deletions

View File

@ -112,9 +112,9 @@ module Jobs
def notify_user
if @current_user
if (@sent > 0 && @failed == 0)
SystemMessage.create(@current_user, :bulk_invite_succeeded, sent: @sent)
SystemMessage.create_from_system_user(@current_user, :bulk_invite_succeeded, sent: @sent)
else
SystemMessage.create(@current_user, :bulk_invite_failed, sent: @sent, failed: @failed, logs: @logs.join("\n"))
SystemMessage.create_from_system_user(@current_user, :bulk_invite_failed, sent: @sent, failed: @failed, logs: @logs.join("\n"))
end
end
end

View File

@ -9,6 +9,10 @@ class SystemMessage
self.new(recipient).create(type, params)
end
def self.create_from_system_user(recipient, type, params = {})
self.new(recipient).create_from_system_user(type, params)
end
def initialize(recipient)
@recipient = recipient
end
@ -27,6 +31,20 @@ class SystemMessage
subtype: TopicSubtype.system_message)
end
def create_from_system_user(type, params = {})
params = defaults.merge(params)
title = I18n.t("system_messages.#{type}.subject_template", params)
raw = I18n.t("system_messages.#{type}.text_body_template", params)
PostCreator.create(Discourse.system_user,
title: title,
raw: raw,
archetype: Archetype.private_message,
target_usernames: @recipient.username,
subtype: TopicSubtype.system_message)
end
def defaults
{
site_name: SiteSetting.title,