Log user silences in the staff notes automatically

This commit is contained in:
Robin Ward 2018-02-13 17:45:57 -05:00
parent 5f944944da
commit 30dc14de7d
2 changed files with 21 additions and 0 deletions

View File

@ -6,3 +6,4 @@ en:
staff_notes:
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}"

View File

@ -236,4 +236,24 @@ after_initialize do
)
end
on(:user_silenced) do |details|
raw_note = I18n.t(
"staff_notes.user_silenced",
username: details[:user].username,
silenced_till: I18n.l(details[:silenced_till], format: :date_only),
reason: details[:reason]
)
note_args = {}
if post = Post.with_deleted.where(id: details[:post_id]).first
note_args = { post_id: post.id, topic_id: post.topic_id }
end
::DiscourseStaffNotes.add_note(
details[:user],
raw_note,
Discourse::SYSTEM_USER_ID,
note_args
)
end
end