Merge pull request #4447 from pmusaraj/approve_new_topics_setting

FEATURE: add "Approve new topics unless user level" setting
This commit is contained in:
Sam 2016-10-11 10:14:28 +11:00 committed by GitHub
commit 0f0b657182
4 changed files with 31 additions and 0 deletions

View File

@ -1348,6 +1348,7 @@ en:
approve_post_count: "The amount of posts from a new or basic user that must be approved" approve_post_count: "The amount of posts from a new or basic user that must be approved"
approve_unless_trust_level: "Posts for users below this trust level must be approved" approve_unless_trust_level: "Posts for users below this trust level must be approved"
approve_new_topics_unless_trust_level: "New topics for users below this trust level must be approved"
notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, an email will be sent to the contact_email. Set to 0 to disable these emails." notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, an email will be sent to the contact_email. Set to 0 to disable these emails."
auto_close_messages_post_count: "Maximum number of posts allowed in a message before it is automatically closed (0 to disable)" auto_close_messages_post_count: "Maximum number of posts allowed in a message before it is automatically closed (0 to disable)"
auto_close_topics_post_count: "Maximum number of posts allowed in a topic before it is automatically closed (0 to disable)" auto_close_topics_post_count: "Maximum number of posts allowed in a topic before it is automatically closed (0 to disable)"

View File

@ -550,6 +550,9 @@ posting:
approve_unless_trust_level: approve_unless_trust_level:
default: 0 default: 0
enum: 'TrustLevelSetting' enum: 'TrustLevelSetting'
approve_new_topics_unless_trust_level:
default: 0
enum: 'TrustLevelSetting'
notify_about_queued_posts_after: notify_about_queued_posts_after:
default: 24 default: 24
min: 0 min: 0

View File

@ -73,6 +73,7 @@ class NewPostManager
(user.trust_level <= TrustLevel.levels[:basic] && user.post_count < SiteSetting.approve_post_count) || (user.trust_level <= TrustLevel.levels[:basic] && user.post_count < SiteSetting.approve_post_count) ||
(user.trust_level < SiteSetting.approve_unless_trust_level.to_i) || (user.trust_level < SiteSetting.approve_unless_trust_level.to_i) ||
(manager.args[:title].present? && user.trust_level < SiteSetting.approve_new_topics_unless_trust_level.to_i) ||
is_fast_typer?(manager) || is_fast_typer?(manager) ||
matches_auto_block_regex?(manager) matches_auto_block_regex?(manager)
end end
@ -114,6 +115,7 @@ class NewPostManager
def self.queue_enabled? def self.queue_enabled?
SiteSetting.approve_post_count > 0 || SiteSetting.approve_post_count > 0 ||
SiteSetting.approve_unless_trust_level.to_i > 0 || SiteSetting.approve_unless_trust_level.to_i > 0 ||
SiteSetting.approve_new_topics_unless_trust_level.to_i > 0 ||
handlers.size > 1 handlers.size > 1
end end

View File

@ -115,6 +115,31 @@ describe NewPostManager do
end end
end end
context 'with a high trust level setting for new topics but post responds to existing topic' do
before do
SiteSetting.approve_new_topics_unless_trust_level = 4
end
it "doesn't return a result action" do
result = NewPostManager.default_handler(manager)
expect(result).to eq(nil)
end
end
end
context "new topic handler" do
let(:manager) { NewPostManager.new(topic.user, raw: 'this is new topic content', title: 'new topic title') }
context 'with a high trust level setting for new topics' do
before do
SiteSetting.approve_new_topics_unless_trust_level = 4
end
it "will return an enqueue result" do
result = NewPostManager.default_handler(manager)
expect(NewPostManager.queue_enabled?).to eq(true)
expect(result.action).to eq(:enqueued)
end
end
end end
context "extensibility priority" do context "extensibility priority" do