mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00

Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled
64 lines
2.1 KiB
Ruby
64 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Status::InteractionPolicyConcern
|
|
extend ActiveSupport::Concern
|
|
|
|
QUOTE_APPROVAL_POLICY_FLAGS = {
|
|
unsupported_policy: (1 << 0),
|
|
public: (1 << 1),
|
|
followers: (1 << 2),
|
|
followed: (1 << 3),
|
|
}.freeze
|
|
|
|
included do
|
|
before_validation :downgrade_quote_policy, if: -> { local? && !distributable? }
|
|
end
|
|
|
|
def quote_policy_as_keys(kind)
|
|
case kind
|
|
when :automatic
|
|
policy = quote_approval_policy >> 16
|
|
when :manual
|
|
policy = quote_approval_policy & 0xFFFF
|
|
end
|
|
|
|
QUOTE_APPROVAL_POLICY_FLAGS.keys.select { |key| policy.anybits?(QUOTE_APPROVAL_POLICY_FLAGS[key]) }.map(&:to_s)
|
|
end
|
|
|
|
# Returns `:automatic`, `:manual`, `:unknown` or `:denied`
|
|
def quote_policy_for_account(other_account, preloaded_relations: {})
|
|
return :denied if other_account.nil? || direct_visibility?
|
|
|
|
following_author = nil
|
|
|
|
# Post author is always allowed to quote themselves
|
|
return :automatic if account_id == other_account.id
|
|
|
|
automatic_policy = quote_approval_policy >> 16
|
|
manual_policy = quote_approval_policy & 0xFFFF
|
|
|
|
return :automatic if automatic_policy.anybits?(QUOTE_APPROVAL_POLICY_FLAGS[:public])
|
|
|
|
if automatic_policy.anybits?(QUOTE_APPROVAL_POLICY_FLAGS[:followers])
|
|
following_author = preloaded_relations[:following] ? preloaded_relations[:following][account_id] : other_account.following?(account) if following_author.nil?
|
|
return :automatic if following_author
|
|
end
|
|
|
|
# We don't know we are allowed by the automatic policy, considering the manual one
|
|
return :manual if manual_policy.anybits?(QUOTE_APPROVAL_POLICY_FLAGS[:public])
|
|
|
|
if manual_policy.anybits?(QUOTE_APPROVAL_POLICY_FLAGS[:followers])
|
|
following_author = preloaded_relations[:following] ? preloaded_relations[:following][account_id] : other_account.following?(account) if following_author.nil?
|
|
return :manual if following_author
|
|
end
|
|
|
|
return :unknown if (automatic_policy | manual_policy).anybits?(QUOTE_APPROVAL_POLICY_FLAGS[:unsupported_policy])
|
|
|
|
:denied
|
|
end
|
|
|
|
def downgrade_quote_policy
|
|
self.quote_approval_policy = 0
|
|
end
|
|
end
|