FEATURE: add staff action log for post approvals

This commit is contained in:
Arpit Jalan 2018-04-23 11:18:53 +05:30
parent c148500d51
commit 0a442977b3
6 changed files with 41 additions and 2 deletions

View File

@ -77,6 +77,9 @@ class QueuedPost < ActiveRecord::Base
unless created_post && creator.errors.blank?
raise StandardError.new(creator.errors.full_messages.join(" "))
else
# Log post approval
StaffActionLogger.new(approved_by).log_post_approved(created_post)
end
end

View File

@ -71,7 +71,8 @@ class UserHistory < ActiveRecord::Base
disabled_second_factor: 52,
post_edit: 53,
topic_published: 54,
recover_topic: 55
recover_topic: 55,
post_approved: 56
)
end
@ -121,7 +122,8 @@ class UserHistory < ActiveRecord::Base
:disabled_second_factor,
:post_edit,
:topic_published,
:recover_topic
:recover_topic,
:post_approved
]
end

View File

@ -410,6 +410,14 @@ class StaffActionLogger
context: topic.relative_url))
end
def log_post_approved(post, opts = {})
raise Discourse::InvalidParameters.new(:post) unless post && post.is_a?(Post)
UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:post_approved],
post_id: post.id)
)
end
private
def params(opts = nil)

View File

@ -3387,6 +3387,7 @@ en:
check_personal_message: "check personal message"
disabled_second_factor: "disable Two Factor Authentication"
topic_published: "topic published"
post_approved: "post approved"
screened_emails:
title: "Screened Emails"
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."

View File

@ -69,6 +69,11 @@ describe QueuedPost do
expect(post).to be_present
end
it "logs post approvals" do
qp.approve!(admin)
expect(UserHistory.where(action: UserHistory.actions[:post_approved]).count).to eq(1)
end
it "follows the correct workflow for rejection" do
qp.create_pending_action
qp.reject!(admin)
@ -124,6 +129,8 @@ describe QueuedPost do
topic = post.topic
expect(topic).to be_present
expect(topic.category).to eq(category)
expect(UserHistory.where(action: UserHistory.actions[:post_approved]).count).to eq(1)
end
it "rejecting doesn't create the post and topic" do

View File

@ -470,4 +470,22 @@ describe StaffActionLogger do
expect { log_check_personal_message }.to change { UserHistory.count }.by(1)
end
end
describe 'log_post_approved' do
let(:approved_post) { Fabricate(:post) }
subject(:log_post_approved) { described_class.new(admin).log_post_approved(approved_post) }
it 'raises an error when post is nil' do
expect { logger.log_post_approved(nil) }.to raise_error(Discourse::InvalidParameters)
end
it 'raises an error when post is not a Post' do
expect { logger.log_post_approved(1) }.to raise_error(Discourse::InvalidParameters)
end
it 'creates a new UserHistory record' do
expect { log_post_approved }.to change { UserHistory.count }.by(1)
end
end
end