mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-04 03:25:14 +00:00
Prevent creation of Private Mentions quoting someone who is not mentioned (#36689)
This commit is contained in:
parent
16a54f7158
commit
05964f571b
3 changed files with 56 additions and 2 deletions
|
|
@ -80,6 +80,7 @@ class PostStatusService < BaseService
|
|||
@status = @account.statuses.new(status_attributes)
|
||||
process_mentions_service.call(@status, save_records: false)
|
||||
safeguard_mentions!(@status)
|
||||
safeguard_private_mention_quote!(@status)
|
||||
attach_quote!(@status)
|
||||
|
||||
antispam = Antispam.new(@status)
|
||||
|
|
@ -92,6 +93,16 @@ class PostStatusService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def safeguard_private_mention_quote!(status)
|
||||
return if @quoted_status.nil? || @visibility.to_sym != :direct
|
||||
|
||||
# The mentions array test here is awkward because the relationship is not persisted at this time
|
||||
return if @quoted_status.account_id == @account.id || status.mentions.to_a.any? { |mention| mention.account_id == @quoted_status.account_id && !mention.silent }
|
||||
|
||||
status.errors.add(:base, I18n.t('statuses.errors.quoted_user_not_mentioned'))
|
||||
raise ActiveRecord::RecordInvalid, status
|
||||
end
|
||||
|
||||
def attach_quote!(status)
|
||||
return if @quoted_status.nil?
|
||||
|
||||
|
|
@ -114,6 +125,7 @@ class PostStatusService < BaseService
|
|||
|
||||
def schedule_status!
|
||||
status_for_validation = @account.statuses.build(status_attributes)
|
||||
safeguard_private_mention_quote!(status_for_validation)
|
||||
|
||||
antispam = Antispam.new(status_for_validation)
|
||||
antispam.local_preflight_check!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue