diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 86d7758..f87ec5d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -5,4 +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}" + user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}" diff --git a/plugin.rb b/plugin.rb index b3209ee..a013382 100644 --- a/plugin.rb +++ b/plugin.rb @@ -152,7 +152,7 @@ after_initialize do mount ::DiscourseStaffNotes::Engine, at: "/staff_notes" end - add_model_callback :user_warning, :after_create do + add_model_callback(UserWarning, :after_commit, on: :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) diff --git a/spec/user_history_spec.rb b/spec/user_history_spec.rb new file mode 100644 index 0000000..76e134b --- /dev/null +++ b/spec/user_history_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +describe UserHistory do + let(:user) { Fabricate(:user, suspended_till: 7.days.from_now) } + let(:admin) { Fabricate(:admin) } + + describe 'when a user suspension log is created' do + context "staff notes plugin is enabled" do + before do + SiteSetting.staff_notes_enabled = true + end + + it "should create staff note for suspension" do + UserHistory.create!({action: UserHistory.actions[:suspend_user], target_user_id: user.id, acting_user_id: admin.id}) + + expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present + end + end + end +end diff --git a/spec/user_warning_spec.rb b/spec/user_warning_spec.rb new file mode 100644 index 0000000..a3149a8 --- /dev/null +++ b/spec/user_warning_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +describe UserWarning do + let(:user) { Fabricate(:user) } + let(:admin) { Fabricate(:admin) } + let(:topic) { Fabricate(:topic) } + + describe 'when a user warning is created' do + context "staff notes plugin is enabled" do + before do + SiteSetting.staff_notes_enabled = true + end + + it "should create staff note for warning" do + UserWarning.create({topic_id: topic.id, user_id: user.id, created_by_id: admin.id}) + + expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present + end + end + end +end