mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
More extensibility for custom silence/suspend messages
This commit is contained in:
parent
3cec2394b2
commit
a8b46df4bd
|
@ -1,3 +1,5 @@
|
|||
require_dependency 'staff_message_format'
|
||||
|
||||
# Responsible for logging the actions of admins and moderators.
|
||||
class StaffActionLogger
|
||||
|
||||
|
@ -170,8 +172,7 @@ class StaffActionLogger
|
|||
def log_user_suspend(user, reason, opts = {})
|
||||
raise Discourse::InvalidParameters.new(:user) unless user
|
||||
|
||||
details = (reason || '').dup
|
||||
details << "\n\n#{opts[:message]}" if opts[:message].present?
|
||||
details = StaffMessageFormat.new(:suspend, reason, opts[:message]).format
|
||||
|
||||
args = params(opts).merge(
|
||||
action: UserHistory.actions[:suspend_user],
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_dependency 'staff_message_format'
|
||||
|
||||
class UserSilencer
|
||||
|
||||
attr_reader :user_history
|
||||
|
@ -21,8 +23,11 @@ class UserSilencer
|
|||
if @user.save
|
||||
message_type = @opts[:message] || :silenced_by_staff
|
||||
|
||||
details = (@opts[:reason] || '').dup
|
||||
details << "\n\n#{@opts[:message_body]}" if @opts[:message_body].present?
|
||||
details = StaffMessageFormat.new(
|
||||
:silence,
|
||||
@opts[:reason],
|
||||
@opts[:message_body]
|
||||
).format
|
||||
|
||||
context = "#{message_type}: '#{post.topic&.title rescue ''}' #{@opts[:reason]}"
|
||||
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
|
Loading…
Reference in New Issue
Block a user