mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: min_first_post_typing_time
If a user spends less than 3 seconds typing first post they will automatically enter the approval queue
This commit is contained in:
parent
a2533e2a02
commit
01ad88f1ed
5 changed files with 33 additions and 4 deletions
|
@ -89,6 +89,8 @@ class PostsController < ApplicationController
|
|||
|
||||
def create
|
||||
@manager_params = create_params
|
||||
@manager_params[:first_post_checks] = !is_api?
|
||||
|
||||
manager = NewPostManager.new(current_user, @manager_params)
|
||||
|
||||
if is_api?
|
||||
|
@ -353,7 +355,7 @@ class PostsController < ApplicationController
|
|||
# If a param is present it uses that result structure.
|
||||
def backwards_compatible_json(json_obj, success)
|
||||
json_obj.symbolize_keys!
|
||||
if params[:nested_post].blank? && json_obj[:errors].blank?
|
||||
if params[:nested_post].blank? && json_obj[:errors].blank? && json_obj[:action] != :enqueued
|
||||
json_obj = json_obj[:post]
|
||||
end
|
||||
|
||||
|
|
|
@ -1077,6 +1077,7 @@ en:
|
|||
num_flags_to_close_topic: "Minimum number of active flags that is required to automatically pause a topic for intervention"
|
||||
|
||||
auto_respond_to_flag_actions: "Enable automatic reply when disposing a flag."
|
||||
min_first_post_typing_time: "Minimum amount of time in milliseconds a user must type during first post, if threshold is not met post will automatically enter the needs approval queue. Set to 0 to disable (not recommended)"
|
||||
|
||||
reply_by_email_enabled: "Enable replying to topics via email."
|
||||
reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com"
|
||||
|
|
|
@ -680,6 +680,7 @@ spam:
|
|||
num_flaggers_to_close_topic: 5
|
||||
num_flags_to_close_topic: 12
|
||||
auto_respond_to_flag_actions: true
|
||||
min_first_post_typing_time: 3000
|
||||
|
||||
rate_limits:
|
||||
unique_posts_mins:
|
||||
|
|
|
@ -28,15 +28,23 @@ class NewPostManager
|
|||
@sorted_handlers.sort_by! {|h| -h[:priority]}
|
||||
end
|
||||
|
||||
def self.user_needs_approval?(user)
|
||||
def self.user_needs_approval?(manager)
|
||||
user = manager.user
|
||||
args = manager.args
|
||||
|
||||
return false if user.staff?
|
||||
|
||||
(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) ||
|
||||
(
|
||||
args[:first_post_checks] &&
|
||||
user.post_count == 0 &&
|
||||
args[:typing_duration_msecs].to_i < SiteSetting.min_first_post_typing_time
|
||||
)
|
||||
end
|
||||
|
||||
def self.default_handler(manager)
|
||||
manager.enqueue('default') if user_needs_approval?(manager.user)
|
||||
manager.enqueue('default') if user_needs_approval?(manager)
|
||||
end
|
||||
|
||||
def self.queue_enabled?
|
||||
|
|
|
@ -446,6 +446,10 @@ describe PostsController do
|
|||
|
||||
describe 'creating a post' do
|
||||
|
||||
before do
|
||||
SiteSetting.min_first_post_typing_time = 0
|
||||
end
|
||||
|
||||
include_examples 'action requires login', :post, :create
|
||||
|
||||
context 'api' do
|
||||
|
@ -477,6 +481,19 @@ describe PostsController do
|
|||
expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'queues the post if min_first_post_typing_time is not met' do
|
||||
|
||||
SiteSetting.min_first_post_typing_time = 3000
|
||||
|
||||
xhr :post, :create, {raw: 'this is the test content', title: 'this is the test title for the topic'}
|
||||
|
||||
expect(response).to be_success
|
||||
parsed = ::JSON.parse(response.body)
|
||||
|
||||
expect(parsed["action"]).to eq("enqueued")
|
||||
|
||||
end
|
||||
|
||||
it 'creates the post' do
|
||||
xhr :post, :create, {raw: 'this is the test content', title: 'this is the test title for the topic'}
|
||||
|
||||
|
|
Loading…
Reference in a new issue