mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:12:45 +08:00
FIX: Don't enqueue posts if the user can't create them (ex: closed)
This commit is contained in:
parent
1f5325e3f0
commit
e78b7a243e
|
@ -20,6 +20,7 @@ module TopicGuardian
|
|||
|
||||
def can_create_post_on_topic?(topic)
|
||||
# No users can create posts on deleted topics
|
||||
return false if topic.blank?
|
||||
return false if topic.trashed?
|
||||
return true if is_admin?
|
||||
|
||||
|
|
|
@ -80,6 +80,17 @@ class NewPostManager
|
|||
def self.default_handler(manager)
|
||||
if user_needs_approval?(manager)
|
||||
|
||||
# Can the user create the post in the first place?
|
||||
if manager.args[:topic_id]
|
||||
topic = Topic.unscoped.where(id: manager.args[:topic_id]).first
|
||||
|
||||
unless manager.user.guardian.can_create_post_on_topic?(topic)
|
||||
result = NewPostResult.new(:created_post, false)
|
||||
result.errors[:base] << I18n.t(:topic_not_found)
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
result = manager.enqueue('default')
|
||||
|
||||
if is_fast_typer?(manager) || matches_auto_block_regex?(manager)
|
||||
|
|
|
@ -233,16 +233,16 @@ describe NewPostManager do
|
|||
default = NewPostManager.new(u,{})
|
||||
expect(NewPostManager.user_needs_approval?(default)).to eq(false)
|
||||
|
||||
with_check = NewPostManager.new(u,{first_post_checks: true})
|
||||
with_check = NewPostManager.new(u, first_post_checks: true)
|
||||
expect(NewPostManager.user_needs_approval?(with_check)).to eq(true)
|
||||
|
||||
u.user_stat.post_count = 1
|
||||
with_check_and_post = NewPostManager.new(u,{first_post_checks: true})
|
||||
with_check_and_post = NewPostManager.new(u, first_post_checks: true)
|
||||
expect(NewPostManager.user_needs_approval?(with_check_and_post)).to eq(false)
|
||||
|
||||
u.user_stat.post_count = 0
|
||||
u.trust_level = 1
|
||||
with_check_tl1 = NewPostManager.new(u,{first_post_checks: true})
|
||||
with_check_tl1 = NewPostManager.new(u, first_post_checks: true)
|
||||
expect(NewPostManager.user_needs_approval?(with_check_tl1)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -584,7 +584,6 @@ describe PostsController do
|
|||
end
|
||||
|
||||
it 'queues the post if min_first_post_typing_time is not met' do
|
||||
|
||||
SiteSetting.min_first_post_typing_time = 3000
|
||||
# our logged on user here is tl1
|
||||
SiteSetting.auto_block_fast_typers_max_trust_level = 1
|
||||
|
@ -606,7 +605,23 @@ describe PostsController do
|
|||
|
||||
user.reload
|
||||
expect(user.blocked).to eq(false)
|
||||
end
|
||||
|
||||
it "doesn't enqueue replies when the topic is closed" do
|
||||
SiteSetting.min_first_post_typing_time = 3000
|
||||
SiteSetting.auto_block_fast_typers_max_trust_level = 1
|
||||
|
||||
topic = Fabricate(:closed_topic)
|
||||
|
||||
xhr :post, :create, {
|
||||
raw: 'this is the test content',
|
||||
title: 'this is the test title for the topic',
|
||||
topic_id: topic.id
|
||||
}
|
||||
|
||||
expect(response).not_to be_success
|
||||
parsed = ::JSON.parse(response.body)
|
||||
expect(parsed["action"]).not_to eq("enqueued")
|
||||
end
|
||||
|
||||
it 'blocks correctly based on auto_block_first_post_regex' do
|
||||
|
|
|
@ -8,6 +8,10 @@ Fabricator(:deleted_topic, from: :topic) do
|
|||
deleted_at Time.now
|
||||
end
|
||||
|
||||
Fabricator(:closed_topic, from: :topic) do
|
||||
closed true
|
||||
end
|
||||
|
||||
Fabricator(:topic_allowed_user) do
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user