mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Create logs for Group Moderator changes (#10271)
This commit is contained in:
@@ -1082,6 +1082,10 @@ describe Topic do
|
||||
end
|
||||
|
||||
context 'archived' do
|
||||
it 'should create a staff action log entry' do
|
||||
expect { topic.update_status('archived', true, @user) }.to change { UserHistory.where(action: UserHistory.actions[:topic_archived]).count }.by(1)
|
||||
end
|
||||
|
||||
context 'disable' do
|
||||
before do
|
||||
@archived_topic = Fabricate(:topic, archived: true, bumped_at: 1.hour.ago)
|
||||
@@ -1155,6 +1159,10 @@ describe Topic do
|
||||
|
||||
expect { topic.update_status(status, true, @user) }.to change(topic.group_archived_messages, :count).by(1)
|
||||
end
|
||||
|
||||
it 'should create a staff action log entry' do
|
||||
expect { topic.update_status(status, true, @user) }.to change { UserHistory.where(action: UserHistory.actions[:topic_closed]).count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'autoclosed' do
|
||||
|
||||
@@ -1805,6 +1805,7 @@ describe PostsController do
|
||||
expect(public_post.custom_fields[Post::NOTICE_TYPE]).to eq(Post.notices[:custom])
|
||||
expect(public_post.custom_fields[Post::NOTICE_ARGS]).to include('<p>Hello <em>world</em>!</p>')
|
||||
expect(public_post.custom_fields[Post::NOTICE_ARGS]).not_to include('onebox')
|
||||
expect(UserHistory.where(action: UserHistory.actions[:post_staff_note_create]).count).to eq(1)
|
||||
|
||||
put "/posts/#{public_post.id}/notice.json", params: { notice: nil }
|
||||
|
||||
@@ -1812,6 +1813,7 @@ describe PostsController do
|
||||
public_post.reload
|
||||
expect(public_post.custom_fields[Post::NOTICE_TYPE]).to eq(nil)
|
||||
expect(public_post.custom_fields[Post::NOTICE_ARGS]).to eq(nil)
|
||||
expect(UserHistory.where(action: UserHistory.actions[:post_staff_note_destroy]).count).to eq(1)
|
||||
end
|
||||
|
||||
describe 'group moderators' do
|
||||
|
||||
@@ -546,4 +546,53 @@ describe StaffActionLogger do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'log_topic_closed' do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
it "raises an error when argument is missing" do
|
||||
expect { logger.log_topic_closed(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "creates a new UserHistory record" do
|
||||
expect { logger.log_topic_closed(topic, closed: true) }.to change { UserHistory.where(action: UserHistory.actions[:topic_closed]).count }.by(1)
|
||||
expect { logger.log_topic_closed(topic, closed: false) }.to change { UserHistory.where(action: UserHistory.actions[:topic_opened]).count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'log_topic_archived' do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
it "raises an error when argument is missing" do
|
||||
expect { logger.log_topic_archived(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "creates a new UserHistory record" do
|
||||
expect { logger.log_topic_archived(topic, archived: true) }.to change { UserHistory.where(action: UserHistory.actions[:topic_archived]).count }.by(1)
|
||||
expect { logger.log_topic_archived(topic, archived: false) }.to change { UserHistory.where(action: UserHistory.actions[:topic_unarchived]).count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'log_post_staff_note' do
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
|
||||
it "raises an error when argument is missing" do
|
||||
expect { logger.log_topic_archived(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "creates a new UserHistory record" do
|
||||
expect { logger.log_post_staff_note(post, { new_raw_value: 'my note', old_value: nil }) }.to change { UserHistory.count }.by(1)
|
||||
user_history = UserHistory.last
|
||||
expect(user_history.action).to eq(UserHistory.actions[:post_staff_note_create])
|
||||
expect(user_history.new_value).to eq('my note')
|
||||
expect(user_history.previous_value).to eq(nil)
|
||||
|
||||
expect { logger.log_post_staff_note(post, { new_raw_value: '', old_value: 'my note' }) }.to change { UserHistory.count }.by(1)
|
||||
user_history = UserHistory.last
|
||||
expect(user_history.action).to eq(UserHistory.actions[:post_staff_note_destroy])
|
||||
expect(user_history.new_value).to eq(nil)
|
||||
expect(user_history.previous_value).to eq('my note')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user