mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: Send notification by system user for bulk invite
This commit is contained in:
parent
df59f0a6e1
commit
aeec5067d5
2 changed files with 20 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue