FEATURE: add staff note when suspending user

This commit is contained in:
Arpit Jalan 2017-05-12 20:48:47 +05:30
parent 8c28557df9
commit d718ec31f7
2 changed files with 9 additions and 0 deletions

View File

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

View File

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