From 30dc14de7d6ca72f7737f8bb2657786bdb9f9126 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 13 Feb 2018 17:45:57 -0500 Subject: [PATCH] Log user silences in the staff notes automatically --- config/locales/server.en.yml | 1 + plugin.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index f87ec5d..5f08317 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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}" diff --git a/plugin.rb b/plugin.rb index fc94efc..44aa741 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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