mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
FEATURE: add staff action log for post approvals
This commit is contained in:
parent
c148500d51
commit
0a442977b3
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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."
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user