mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: user 'UserBlocker' when blocking a new user
This commit is contained in:
parent
be3a5a56cc
commit
f15d463eb8
|
@ -64,9 +64,7 @@ class QueuedPost < ActiveRecord::Base
|
|||
QueuedPost.transaction do
|
||||
change_to!(:approved, approved_by)
|
||||
|
||||
if user.blocked?
|
||||
user.update_columns(blocked: false)
|
||||
end
|
||||
UserBlocker.unblock(user, approved_by) if user.blocked?
|
||||
|
||||
creator = PostCreator.new(user, create_options.merge(skip_validations: true))
|
||||
created_post = creator.create
|
||||
|
|
|
@ -38,7 +38,7 @@ class SpamRule::AutoBlock
|
|||
|
||||
def block_user
|
||||
Post.transaction do
|
||||
if UserBlocker.block(@user, nil, {message: :too_many_spam_flags}) and SiteSetting.notify_mods_when_user_blocked
|
||||
if UserBlocker.block(@user, Discourse.system_user, message: :too_many_spam_flags) && SiteSetting.notify_mods_when_user_blocked
|
||||
GroupMessage.create(Group[:moderators].name, :user_automatically_blocked, {user: @user, limit_once_per: false})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,8 +27,8 @@ class UserBlocker
|
|||
|
||||
def hide_posts
|
||||
Post.where(user_id: @user.id).update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Post.hidden_reasons[:new_user_spam_threshold_reached]])
|
||||
topic_ids = Post.where('user_id = ? and post_number = ?', @user.id, 1).pluck(:topic_id)
|
||||
Topic.where(id: topic_ids).update_all({ visible: false }) unless topic_ids.empty?
|
||||
topic_ids = Post.where(user_id: @user.id, post_number: 1).pluck(:topic_id)
|
||||
Topic.where(id: topic_ids).update_all(visible: false) unless topic_ids.empty?
|
||||
end
|
||||
|
||||
def unblock
|
||||
|
|
|
@ -82,14 +82,11 @@ class NewPostManager
|
|||
|
||||
result = manager.enqueue('default')
|
||||
|
||||
block = is_fast_typer?(manager)
|
||||
|
||||
block ||= matches_auto_block_regex?(manager)
|
||||
|
||||
manager.user.update_columns(blocked: true) if block
|
||||
if is_fast_typer?(manager) || matches_auto_block_regex?(manager)
|
||||
UserBlocker.block(manager.user, Discourse.system_user, keep_posts: true)
|
||||
end
|
||||
|
||||
result
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ describe SpamRule::AutoBlock do
|
|||
|
||||
context 'user is not blocked' do
|
||||
before do
|
||||
UserBlocker.expects(:block).with(user, nil, has_entries(message: :too_many_spam_flags)).returns(true)
|
||||
UserBlocker.expects(:block).with(user, Discourse.system_user, message: :too_many_spam_flags).returns(true)
|
||||
end
|
||||
|
||||
it 'prevents the user from making new posts' do
|
||||
|
@ -126,7 +126,7 @@ describe SpamRule::AutoBlock do
|
|||
|
||||
context 'user is already blocked' do
|
||||
before do
|
||||
UserBlocker.expects(:block).with(user, nil, has_entries(message: :too_many_spam_flags)).returns(false)
|
||||
UserBlocker.expects(:block).with(user, Discourse.system_user, message: :too_many_spam_flags).returns(false)
|
||||
end
|
||||
|
||||
it "doesn't send a pm to moderators if the user is already blocked" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user