Prevent other user's anon blocks from affecting each other

This commit is contained in:
Karina Kwiatek 2022-06-15 12:38:14 +02:00 committed by Karina Kwiatek
parent abd07373e3
commit 41e476a2f7
2 changed files with 20 additions and 2 deletions

View File

@ -83,8 +83,8 @@ class Ajax::QuestionController < AjaxController
return
end
unless MuteRule.where(user: target_user).any? { |rule| rule.applies_to? question } ||
(author_is_anonymous && AnonymousBlock.where(identifier: AnonymousBlock.get_identifier(request.ip)).any?)
unless target_user.mute_rules.any? { |rule| rule.applies_to? question } ||
(author_is_anonymous && target_user.anonymous_blocks.where(identifier: AnonymousBlock.get_identifier(request.ip)).any?)
Inbox.create!(user_id: target_user.id, question_id: question.id, new: true)
end
end

View File

@ -274,6 +274,24 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
end
end
context "when the sender is blocked by another user" do
let(:user_allows_anonymous_questions) { true }
let(:expected_question_user) { nil }
let(:expected_question_direct) { true }
before do
identifier = AnonymousBlock.get_identifier("0.0.0.0")
dummy_question = FactoryBot.create(:question, author_is_anonymous: true, author_identifier: identifier)
AnonymousBlock.create(
user: FactoryBot.create(:user),
identifier: identifier,
question: dummy_question
)
end
include_examples "creates the question"
end
context "when user does not allow anonymous questions" do
let(:user_allows_anonymous_questions) { false }
let(:expected_response) do