mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
FEATURE: add staff action log for post approvals
This commit is contained in:
parent
c148500d51
commit
0a442977b3
6 changed files with 41 additions and 2 deletions
|
@ -77,6 +77,9 @@ class QueuedPost < ActiveRecord::Base
|
||||||
|
|
||||||
unless created_post && creator.errors.blank?
|
unless created_post && creator.errors.blank?
|
||||||
raise StandardError.new(creator.errors.full_messages.join(" "))
|
raise StandardError.new(creator.errors.full_messages.join(" "))
|
||||||
|
else
|
||||||
|
# Log post approval
|
||||||
|
StaffActionLogger.new(approved_by).log_post_approved(created_post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ class UserHistory < ActiveRecord::Base
|
||||||
disabled_second_factor: 52,
|
disabled_second_factor: 52,
|
||||||
post_edit: 53,
|
post_edit: 53,
|
||||||
topic_published: 54,
|
topic_published: 54,
|
||||||
recover_topic: 55
|
recover_topic: 55,
|
||||||
|
post_approved: 56
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,7 +122,8 @@ class UserHistory < ActiveRecord::Base
|
||||||
:disabled_second_factor,
|
:disabled_second_factor,
|
||||||
:post_edit,
|
:post_edit,
|
||||||
:topic_published,
|
:topic_published,
|
||||||
:recover_topic
|
:recover_topic,
|
||||||
|
:post_approved
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -410,6 +410,14 @@ class StaffActionLogger
|
||||||
context: topic.relative_url))
|
context: topic.relative_url))
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def params(opts = nil)
|
def params(opts = nil)
|
||||||
|
|
|
@ -3387,6 +3387,7 @@ en:
|
||||||
check_personal_message: "check personal message"
|
check_personal_message: "check personal message"
|
||||||
disabled_second_factor: "disable Two Factor Authentication"
|
disabled_second_factor: "disable Two Factor Authentication"
|
||||||
topic_published: "topic published"
|
topic_published: "topic published"
|
||||||
|
post_approved: "post approved"
|
||||||
screened_emails:
|
screened_emails:
|
||||||
title: "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."
|
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
|
expect(post).to be_present
|
||||||
end
|
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
|
it "follows the correct workflow for rejection" do
|
||||||
qp.create_pending_action
|
qp.create_pending_action
|
||||||
qp.reject!(admin)
|
qp.reject!(admin)
|
||||||
|
@ -124,6 +129,8 @@ describe QueuedPost do
|
||||||
topic = post.topic
|
topic = post.topic
|
||||||
expect(topic).to be_present
|
expect(topic).to be_present
|
||||||
expect(topic.category).to eq(category)
|
expect(topic.category).to eq(category)
|
||||||
|
|
||||||
|
expect(UserHistory.where(action: UserHistory.actions[:post_approved]).count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "rejecting doesn't create the post and topic" do
|
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)
|
expect { log_check_personal_message }.to change { UserHistory.count }.by(1)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue