Prevent questions being sent to users that lock their inbox

This commit is contained in:
Andreas Nedbal 2022-11-06 15:01:01 +01:00
parent f6c28eefbd
commit fa12b19b8a
3 changed files with 9 additions and 0 deletions

View File

@ -12,6 +12,7 @@ class QuestionWorker
question = Question.find(question_id)
user.followers.each do |f|
next if f.inbox_locked?
next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question }
Inbox.create(user_id: f.id, question_id: question_id, new: true)

View File

@ -35,6 +35,9 @@ module Errors
class SelfAction < Forbidden
end
class InboxLocked < Forbidden
end
class FollowingSelf < SelfAction
end

View File

@ -14,6 +14,7 @@ module UseCase
option :direct, type: Types::Params::Bool, default: proc { true }
def call
check_lock
check_anonymous_rules
check_blocks
@ -42,6 +43,10 @@ module UseCase
private
def check_lock
raise Errors::InboxLocked if target_user.inbox_locked?
end
def check_anonymous_rules
if !source_user_id && !anonymous
# We can not create a non-anonymous question without a source user