From cd8c22b3d16585a2a9eb88fdf394fb81d024ab7c Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 4 Apr 2016 18:57:18 +0530 Subject: [PATCH] FEATURE: auto create a staff note when an official warning is created --- config/locales/server.en.yml | 3 +++ plugin.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 18ef2a3..494fde0 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2,3 +2,6 @@ en: site_settings: staff_notes_enabled: "Allow staff users to attach notes to users" staff_notes_moderators_delete: "Allow moderators to delete staff notes" + + staff_notes: + official_warning: "Received an official warning from @%{username} -- %{warning_link}" diff --git a/plugin.rb b/plugin.rb index 6464fcf..044758e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -151,4 +151,12 @@ after_initialize do mount ::DiscourseStaffNotes::Engine, at: "/staff_notes" end + add_model_callback :warning, :after_create do + user = User.find_by_id(self.user_id) + created_by_user = User.find_by_id(self.created_by_id) + warning_topic = Topic.find_by_id(self.topic_id) + raw_note = I18n.t("staff_notes.official_warning", username: created_by_user.username, warning_link: "[#{warning_topic.title}](#{warning_topic.url})") + ::DiscourseStaffNotes.add_note(user, raw_note, Discourse::SYSTEM_USER_ID) + end + end