Site Settings for post approval

This commit is contained in:
Robin Ward 2015-04-15 12:12:20 -04:00
parent 0c233e4e25
commit af1571a58f
4 changed files with 53 additions and 0 deletions

View File

@ -1139,6 +1139,9 @@ en:
emoji_set: "How would you like your emoji?"
enforce_square_emoji: "Force a square aspect ratio to all emojis."
approve_post_count: "The amount of posts from a new user that must be approved"
approve_unless_trust_level: "Posts for users below this trust level must be approved"
errors:
invalid_email: "Invalid email address."
invalid_username: "There's no user with that username."

View File

@ -441,6 +441,11 @@ posting:
enum: 'EmojiSetSiteSetting'
enforce_square_emoji:
default: true
approve_post_count:
default: 0
approve_unless_trust_level:
default: 0
enum: 'TrustLevelSetting'
email:
email_time_window_mins:

View File

@ -19,6 +19,15 @@ class NewPostManager
handlers << block
end
def self.default_handler(manager)
if (manager.user.post_count < SiteSetting.approve_post_count) ||
(manager.user.trust_level < SiteSetting.approve_unless_trust_level)
return manager.enqueue('default')
end
end
add_handler {|manager| default_handler(manager) }
def initialize(user, args)
@user = user
@args = args.delete_if {|_, v| v.nil?}

View File

@ -17,6 +17,42 @@ describe NewPostManager do
end
end
context "default handler" do
let(:manager) { NewPostManager.new(topic.user, raw: 'this is new post content', topic_id: topic.id) }
context 'with the settings zeroed out' do
before do
SiteSetting.approve_post_count = 0
SiteSetting.approve_unless_trust_level = 0
end
it "doesn't return a result action" do
result = NewPostManager.default_handler(manager)
expect(result).to eq(nil)
end
end
context 'with a high approval post count' do
before do
SiteSetting.approve_post_count = 100
end
it "will return an enqueue result" do
result = NewPostManager.default_handler(manager)
expect(result.action).to eq(:enqueued)
end
end
context 'with a high trust level setting' do
before do
SiteSetting.approve_unless_trust_level = 4
end
it "will return an enqueue result" do
result = NewPostManager.default_handler(manager)
expect(result.action).to eq(:enqueued)
end
end
end
context "extensibility" do
before do