From d718ec31f7bd9b352d38a9f1b7d80abecaa626af Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 12 May 2017 20:48:47 +0530 Subject: [PATCH] FEATURE: add staff note when suspending user --- config/locales/server.en.yml | 1 + plugin.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 494fde0..86d7758 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -5,3 +5,4 @@ en: staff_notes: official_warning: "Received an official warning from @%{username} -- %{warning_link}" + user_suspended: "@%{username} suspended this account till %{suspended_till}. Reason: %{reason}" diff --git a/plugin.rb b/plugin.rb index b2123d7..b3209ee 100644 --- a/plugin.rb +++ b/plugin.rb @@ -160,4 +160,12 @@ after_initialize do ::DiscourseStaffNotes.add_note(user, raw_note, Discourse::SYSTEM_USER_ID) end + add_model_callback(UserHistory, :after_commit, on: :create) do + return unless self.action == UserHistory.actions[:suspend_user] + target_user = User.find_by_id(self.target_user_id) + created_by_user = User.find_by_id(self.acting_user_id) + raw_note = I18n.t("staff_notes.user_suspended", username: created_by_user.username, suspended_till: I18n.l(target_user.suspended_till, format: :date_only), reason: self.details) + ::DiscourseStaffNotes.add_note(target_user, raw_note, Discourse::SYSTEM_USER_ID) + end + end