FIX: Don't enqueue posts if the user can't create them (ex: closed)

This commit is contained in:
Robin Ward
2016-09-09 12:15:56 -04:00
parent 1f5325e3f0
commit e78b7a243e
5 changed files with 35 additions and 4 deletions
+1
View File
@@ -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?
+11
View File
@@ -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)