2018-12-03 00:32:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccountAssociations
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
# Local users
|
|
|
|
has_one :user, inverse_of: :account, dependent: :destroy
|
|
|
|
|
2019-03-18 20:00:55 +00:00
|
|
|
# Identity proofs
|
|
|
|
has_many :identity_proofs, class_name: 'AccountIdentityProof', dependent: :destroy, inverse_of: :account
|
2020-06-02 17:24:53 +00:00
|
|
|
has_many :devices, dependent: :destroy, inverse_of: :account
|
2019-03-18 20:00:55 +00:00
|
|
|
|
2018-12-03 00:32:08 +00:00
|
|
|
# Timelines
|
|
|
|
has_many :statuses, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :favourites, inverse_of: :account, dependent: :destroy
|
2019-11-13 22:02:10 +00:00
|
|
|
has_many :bookmarks, inverse_of: :account, dependent: :destroy
|
2018-12-03 00:32:08 +00:00
|
|
|
has_many :mentions, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :notifications, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
2019-01-05 11:43:28 +00:00
|
|
|
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
|
2018-12-03 00:32:08 +00:00
|
|
|
|
|
|
|
# Pinned statuses
|
|
|
|
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status
|
|
|
|
|
|
|
|
# Endorsements
|
|
|
|
has_many :account_pins, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :endorsed_accounts, through: :account_pins, class_name: 'Account', source: :target_account
|
|
|
|
|
|
|
|
# Media
|
|
|
|
has_many :media_attachments, dependent: :destroy
|
2019-03-03 21:18:23 +00:00
|
|
|
has_many :polls, dependent: :destroy
|
2018-12-03 00:32:08 +00:00
|
|
|
|
|
|
|
# Report relationships
|
|
|
|
has_many :reports, dependent: :destroy, inverse_of: :account
|
|
|
|
has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
|
|
|
|
|
|
|
|
has_many :report_notes, dependent: :destroy
|
|
|
|
has_many :custom_filters, inverse_of: :account, dependent: :destroy
|
|
|
|
|
|
|
|
# Moderation notes
|
|
|
|
has_many :account_moderation_notes, dependent: :destroy, inverse_of: :account
|
|
|
|
has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 19:02:09 +00:00
|
|
|
has_many :account_warnings, dependent: :destroy, inverse_of: :account
|
|
|
|
has_many :targeted_account_warnings, class_name: 'AccountWarning', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
|
2018-12-03 00:32:08 +00:00
|
|
|
|
|
|
|
# Lists (that the account is on, not owned by the account)
|
|
|
|
has_many :list_accounts, inverse_of: :account, dependent: :destroy
|
|
|
|
has_many :lists, through: :list_accounts
|
|
|
|
|
|
|
|
# Lists (owned by the account)
|
|
|
|
has_many :owned_lists, class_name: 'List', dependent: :destroy, inverse_of: :account
|
|
|
|
|
|
|
|
# Account migrations
|
|
|
|
belongs_to :moved_to_account, class_name: 'Account', optional: true
|
2019-09-19 18:58:19 +00:00
|
|
|
has_many :migrations, class_name: 'AccountMigration', dependent: :destroy, inverse_of: :account
|
|
|
|
has_many :aliases, class_name: 'AccountAlias', dependent: :destroy, inverse_of: :account
|
2018-12-06 16:36:11 +00:00
|
|
|
|
2020-07-05 09:42:44 +00:00
|
|
|
# Domains
|
|
|
|
has_many :favourite_domains, inverse_of: :account, dependent: :destroy
|
|
|
|
|
2018-12-06 16:36:11 +00:00
|
|
|
# Hashtags
|
|
|
|
has_and_belongs_to_many :tags
|
2019-08-22 02:47:11 +00:00
|
|
|
has_many :favourite_tags, -> { includes(:tag) }, dependent: :destroy, inverse_of: :account
|
2019-02-04 03:25:59 +00:00
|
|
|
has_many :featured_tags, -> { includes(:tag) }, dependent: :destroy, inverse_of: :account
|
2019-08-30 08:02:41 +00:00
|
|
|
has_many :follow_tags, -> { includes(:tag) }, dependent: :destroy, inverse_of: :account
|
|
|
|
|
|
|
|
# KeywordSubscribes
|
|
|
|
has_many :keyword_subscribes, inverse_of: :account, dependent: :destroy
|
|
|
|
|
|
|
|
# DomainSubscribes
|
|
|
|
has_many :domain_subscribes, inverse_of: :account, dependent: :destroy
|
2020-09-15 12:37:58 +00:00
|
|
|
|
|
|
|
# Account deletion requests
|
|
|
|
has_one :deletion_request, class_name: 'AccountDeletionRequest', inverse_of: :account, dependent: :destroy
|
2021-04-12 10:37:14 +00:00
|
|
|
|
|
|
|
# Follow recommendations
|
|
|
|
has_one :follow_recommendation_suppression, inverse_of: :account, dependent: :destroy
|
2021-08-09 21:11:50 +00:00
|
|
|
|
|
|
|
# Account statuses cleanup policy
|
|
|
|
has_one :statuses_cleanup_policy, class_name: 'AccountStatusesCleanupPolicy', inverse_of: :account, dependent: :destroy
|
2018-12-03 00:32:08 +00:00
|
|
|
end
|
2020-07-12 13:00:23 +00:00
|
|
|
|
|
|
|
def permitted_group_statuses(account)
|
|
|
|
return Status.none if !group? || !account.nil? && (blocking?(account) || (account.domain.present? && domain_blocking?(account.domain)))
|
|
|
|
|
|
|
|
visibility = [:public, :unlisted]
|
|
|
|
visibility.push(:private) if account&.following?(self)
|
|
|
|
|
2020-08-30 13:49:09 +00:00
|
|
|
scope = Status.unscoped
|
|
|
|
.where(id:
|
|
|
|
Status.reorder(nil)
|
|
|
|
.where(account_id: id)
|
2020-07-12 13:00:23 +00:00
|
|
|
.where(visibility: visibility)
|
2020-08-30 13:49:09 +00:00
|
|
|
.select('CASE reblog_of_id WHEN NULL THEN id ELSE reblog_of_id END')
|
|
|
|
)
|
2020-07-12 13:00:23 +00:00
|
|
|
scope = scope.where.not(account_id: account.excluded_from_timeline_account_ids) unless account.nil?
|
|
|
|
scope
|
|
|
|
end
|
2018-12-03 00:32:08 +00:00
|
|
|
end
|