mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
More extensibility for custom silence/suspend messages
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
require_dependency 'staff_message_format'
|
||||||
|
|
||||||
# Responsible for logging the actions of admins and moderators.
|
# Responsible for logging the actions of admins and moderators.
|
||||||
class StaffActionLogger
|
class StaffActionLogger
|
||||||
|
|
||||||
@ -170,8 +172,7 @@ class StaffActionLogger
|
|||||||
def log_user_suspend(user, reason, opts = {})
|
def log_user_suspend(user, reason, opts = {})
|
||||||
raise Discourse::InvalidParameters.new(:user) unless user
|
raise Discourse::InvalidParameters.new(:user) unless user
|
||||||
|
|
||||||
details = (reason || '').dup
|
details = StaffMessageFormat.new(:suspend, reason, opts[:message]).format
|
||||||
details << "\n\n#{opts[:message]}" if opts[:message].present?
|
|
||||||
|
|
||||||
args = params(opts).merge(
|
args = params(opts).merge(
|
||||||
action: UserHistory.actions[:suspend_user],
|
action: UserHistory.actions[:suspend_user],
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require_dependency 'staff_message_format'
|
||||||
|
|
||||||
class UserSilencer
|
class UserSilencer
|
||||||
|
|
||||||
attr_reader :user_history
|
attr_reader :user_history
|
||||||
@ -21,8 +23,11 @@ class UserSilencer
|
|||||||
if @user.save
|
if @user.save
|
||||||
message_type = @opts[:message] || :silenced_by_staff
|
message_type = @opts[:message] || :silenced_by_staff
|
||||||
|
|
||||||
details = (@opts[:reason] || '').dup
|
details = StaffMessageFormat.new(
|
||||||
details << "\n\n#{@opts[:message_body]}" if @opts[:message_body].present?
|
:silence,
|
||||||
|
@opts[:reason],
|
||||||
|
@opts[:message_body]
|
||||||
|
).format
|
||||||
|
|
||||||
context = "#{message_type}: '#{post.topic&.title rescue ''}' #{@opts[:reason]}"
|
context = "#{message_type}: '#{post.topic&.title rescue ''}' #{@opts[:reason]}"
|
||||||
SystemMessage.create(@user, message_type)
|
SystemMessage.create(@user, message_type)
|
||||||
|
5
lib/moderator_message_format.rb
Normal file
5
lib/moderator_message_format.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Use this class to format messages for when an
|
||||||
|
class ModeratorMessageFormat
|
||||||
|
def initialize(reason, message = nil)
|
||||||
|
end
|
||||||
|
end
|
23
lib/staff_message_format.rb
Normal file
23
lib/staff_message_format.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# This is used for formatting Suspension/Silencing messages.
|
||||||
|
# It can be extended by plugins to provide custom message formats.
|
||||||
|
class StaffMessageFormat
|
||||||
|
def initialize(type, reason, message = nil)
|
||||||
|
@type = type
|
||||||
|
@reason = reason
|
||||||
|
@message = message
|
||||||
|
|
||||||
|
after_initialize
|
||||||
|
end
|
||||||
|
|
||||||
|
# Plugins can overwrite this to munge values before formatting
|
||||||
|
def after_initialize
|
||||||
|
end
|
||||||
|
|
||||||
|
# Overwrite this to change formatting
|
||||||
|
def format
|
||||||
|
result = ""
|
||||||
|
result << @reason if @reason.present?
|
||||||
|
result << "\n\n#{@message}" if @message.present?
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user