FIX: Suspended users should not be allowed to post
This commit is contained in:
parent
e907cca62e
commit
138d013e56
|
@ -92,6 +92,7 @@ en:
|
|||
one: "Sorry, new users can only put one link in a post."
|
||||
other: "Sorry, new users can only put %{count} links in a post."
|
||||
spamming_host: "Sorry you cannot post a link to that host."
|
||||
user_is_suspended: "Suspended users are not allowed to post."
|
||||
|
||||
just_posted_that: "is too similar to what you recently posted"
|
||||
has_already_been_used: "has already been used"
|
||||
|
|
|
@ -47,6 +47,10 @@ class PostCreator
|
|||
@spam
|
||||
end
|
||||
|
||||
def skip_validations?
|
||||
@opts[:skip_validations]
|
||||
end
|
||||
|
||||
def guardian
|
||||
@guardian ||= Guardian.new(@user)
|
||||
end
|
||||
|
@ -55,6 +59,12 @@ class PostCreator
|
|||
@topic = nil
|
||||
@post = nil
|
||||
|
||||
if @user.suspended? && !skip_validations?
|
||||
@errors = Post.new.errors
|
||||
@errors.add(:base, I18n.t(:user_is_suspended))
|
||||
return
|
||||
end
|
||||
|
||||
transaction do
|
||||
setup_topic
|
||||
setup_post
|
||||
|
@ -142,7 +152,7 @@ class PostCreator
|
|||
{ user: @user,
|
||||
limit_once_per: 24.hours,
|
||||
message_params: {domains: @post.linked_hosts.keys.join(', ')} } )
|
||||
elsif @post && !@post.errors.present? && !@opts[:skip_validations]
|
||||
elsif @post && !@post.errors.present? && !skip_validations?
|
||||
SpamRulesEnforcer.enforce!(@post)
|
||||
end
|
||||
end
|
||||
|
@ -213,7 +223,7 @@ class PostCreator
|
|||
end
|
||||
|
||||
def rollback_if_host_spam_detected
|
||||
return if @opts[:skip_validations]
|
||||
return if skip_validations?
|
||||
if @post.has_host_spam?
|
||||
@post.errors.add(:base, I18n.t(:spamming_host))
|
||||
@errors = @post.errors
|
||||
|
@ -223,7 +233,7 @@ class PostCreator
|
|||
end
|
||||
|
||||
def save_post
|
||||
unless @post.save(validate: !@opts[:skip_validations])
|
||||
unless @post.save(validate: !skip_validations?)
|
||||
@errors = @post.errors
|
||||
raise ActiveRecord::Rollback.new
|
||||
end
|
||||
|
|
|
@ -463,5 +463,16 @@ describe PostCreator do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe "suspended users" do
|
||||
it "does not allow suspended users to create topics" do
|
||||
user = Fabricate(:user, suspended_at: 1.month.ago, suspended_till: 1.month.from_now)
|
||||
|
||||
creator = PostCreator.new(user, {title: "my test title 123", raw: "I should not be allowed to post"} )
|
||||
creator.create
|
||||
creator.errors.count.should be > 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue