FIX: Change UserCommScreener to use user_ids (#17489)

It makes more sense to use user_ids for the UserCommScreener
introduced in fa5f3e228c since
in most cases the ID will be available, not the username. This
was discovered while starting work on a plugin that will
use this. In the cases where only usernames are available
the extra query is negligble.
This commit is contained in:
Martin Brennan
2022-07-14 15:23:09 +10:00
committed by GitHub
parent b20dcec7d9
commit 6b2ea1b47b
5 changed files with 71 additions and 66 deletions

View File

@@ -1040,8 +1040,8 @@ class Topic < ActiveRecord::Base
raise UserExists.new(I18n.t("topic_invite.user_exists"))
end
comm_screener = UserCommScreener.new(acting_user: invited_by, target_usernames: target_user.username)
if comm_screener.ignoring_or_muting_actor?(target_user.username)
comm_screener = UserCommScreener.new(acting_user: invited_by, target_user_ids: target_user.id)
if comm_screener.ignoring_or_muting_actor?(target_user.id)
raise NotAllowed.new(I18n.t("not_accepting_pms", username: target_user.username))
end
@@ -1053,11 +1053,11 @@ class Topic < ActiveRecord::Base
raise NotAllowed.new(I18n.t("topic_invite.muted_topic"))
end
if comm_screener.disallowing_pms_from_actor?(target_user.username)
if comm_screener.disallowing_pms_from_actor?(target_user.id)
raise NotAllowed.new(I18n.t("topic_invite.receiver_does_not_allow_pm"))
end
if UserCommScreener.new(acting_user: target_user, target_usernames: invited_by.username).disallowing_pms_from_actor?(invited_by.username)
if UserCommScreener.new(acting_user: target_user, target_user_ids: invited_by.id).disallowing_pms_from_actor?(invited_by.id)
raise NotAllowed.new(I18n.t("topic_invite.sender_does_not_allow_pm"))
end
@@ -1759,7 +1759,7 @@ class Topic < ActiveRecord::Base
end
def create_invite_notification!(target_user, notification_type, invited_by, post_number: 1)
if UserCommScreener.new(acting_user: invited_by, target_usernames: target_user.username).ignoring_or_muting_actor?(target_user.username)
if UserCommScreener.new(acting_user: invited_by, target_user_ids: target_user.id).ignoring_or_muting_actor?(target_user.id)
raise NotAllowed.new(I18n.t("not_accepting_pms", username: target_user.username))
end