Merge pull request #1 from techAPJ/warning

FEATURE: auto create a staff note when an official warning is created
This commit is contained in:
Robin Ward 2016-04-04 11:55:45 -04:00
commit b6975e6d79
2 changed files with 11 additions and 0 deletions

View File

@ -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}"

View File

@ -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