FEATURE: auto create a staff note when an official warning is created

This commit is contained in:
Arpit Jalan 2016-04-04 18:57:18 +05:30
parent 228462b159
commit cd8c22b3d1
2 changed files with 11 additions and 0 deletions

View File

@ -2,3 +2,6 @@ en:
site_settings: site_settings:
staff_notes_enabled: "Allow staff users to attach notes to users" staff_notes_enabled: "Allow staff users to attach notes to users"
staff_notes_moderators_delete: "Allow moderators to delete staff notes" staff_notes_moderators_delete: "Allow moderators to delete staff notes"
staff_notes:
official_warning: "Received an official warning from @%{username} -- %{warning_link}"

View File

@ -151,4 +151,12 @@ after_initialize do
mount ::DiscourseStaffNotes::Engine, at: "/staff_notes" mount ::DiscourseStaffNotes::Engine, at: "/staff_notes"
end 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 end