Model concerns organization into module namespaces (#28149)

This commit is contained in:
Matt Jankowski 2023-12-01 06:00:41 -05:00 committed by GitHub
parent b751078fcd
commit 440b80b2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 62 additions and 62 deletions

View File

@ -107,7 +107,7 @@ Rails/ApplicationController:
# Include: app/models/**/*.rb # Include: app/models/**/*.rb
Rails/HasAndBelongsToMany: Rails/HasAndBelongsToMany:
Exclude: Exclude:
- 'app/models/concerns/account_associations.rb' - 'app/models/concerns/account/associations.rb'
- 'app/models/preview_card.rb' - 'app/models/preview_card.rb'
- 'app/models/status.rb' - 'app/models/status.rb'
- 'app/models/tag.rb' - 'app/models/tag.rb'
@ -116,7 +116,7 @@ Rails/HasAndBelongsToMany:
# Include: app/models/**/*.rb # Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent: Rails/HasManyOrHasOneDependent:
Exclude: Exclude:
- 'app/models/concerns/account_counters.rb' - 'app/models/concerns/account/counters.rb'
- 'app/models/conversation.rb' - 'app/models/conversation.rb'
- 'app/models/custom_emoji.rb' - 'app/models/custom_emoji.rb'
- 'app/models/custom_emoji_category.rb' - 'app/models/custom_emoji_category.rb'
@ -172,7 +172,7 @@ Rails/SkipsModelValidations:
Exclude: Exclude:
- 'app/controllers/admin/invites_controller.rb' - 'app/controllers/admin/invites_controller.rb'
- 'app/controllers/concerns/session_tracking_concern.rb' - 'app/controllers/concerns/session_tracking_concern.rb'
- 'app/models/concerns/account_merging.rb' - 'app/models/concerns/account/merging.rb'
- 'app/models/concerns/expireable.rb' - 'app/models/concerns/expireable.rb'
- 'app/models/status.rb' - 'app/models/status.rb'
- 'app/models/trends/links.rb' - 'app/models/trends/links.rb'
@ -252,7 +252,7 @@ Rails/WhereExists:
- 'app/lib/feed_manager.rb' - 'app/lib/feed_manager.rb'
- 'app/lib/status_cache_hydrator.rb' - 'app/lib/status_cache_hydrator.rb'
- 'app/lib/suspicious_sign_in_detector.rb' - 'app/lib/suspicious_sign_in_detector.rb'
- 'app/models/concerns/account_interactions.rb' - 'app/models/concerns/account/interactions.rb'
- 'app/models/featured_tag.rb' - 'app/models/featured_tag.rb'
- 'app/models/poll.rb' - 'app/models/poll.rb'
- 'app/models/session_activation.rb' - 'app/models/session_activation.rb'
@ -342,8 +342,8 @@ Style/GuardClause:
- 'app/lib/request_pool.rb' - 'app/lib/request_pool.rb'
- 'app/lib/webfinger.rb' - 'app/lib/webfinger.rb'
- 'app/lib/webfinger_resource.rb' - 'app/lib/webfinger_resource.rb'
- 'app/models/concerns/account_counters.rb' - 'app/models/concerns/account/counters.rb'
- 'app/models/concerns/ldap_authenticable.rb' - 'app/models/concerns/user/ldap_authenticable.rb'
- 'app/models/tag.rb' - 'app/models/tag.rb'
- 'app/models/user.rb' - 'app/models/user.rb'
- 'app/services/fan_out_on_write_service.rb' - 'app/services/fan_out_on_write_service.rb'
@ -372,8 +372,8 @@ Style/HashAsLastArrayItem:
Exclude: Exclude:
- 'app/controllers/admin/statuses_controller.rb' - 'app/controllers/admin/statuses_controller.rb'
- 'app/controllers/api/v1/statuses_controller.rb' - 'app/controllers/api/v1/statuses_controller.rb'
- 'app/models/concerns/account_counters.rb' - 'app/models/concerns/account/counters.rb'
- 'app/models/concerns/status_threading_concern.rb' - 'app/models/concerns/status/threading_concern.rb'
- 'app/models/status.rb' - 'app/models/status.rb'
- 'app/services/batched_remove_status_service.rb' - 'app/services/batched_remove_status_service.rb'
- 'app/services/notify_service.rb' - 'app/services/notify_service.rb'
@ -486,7 +486,7 @@ Style/RedundantReturn:
# AllowedMethods: present?, blank?, presence, try, try! # AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation: Style/SafeNavigation:
Exclude: Exclude:
- 'app/models/concerns/account_finder_concern.rb' - 'app/models/concerns/account/finder_concern.rb'
# This cop supports safe autocorrection (--autocorrect). # This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.

View File

@ -70,19 +70,20 @@ class Account < ApplicationRecord
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+} URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
include Attachmentable include Attachmentable # Load prior to Avatar & Header concerns
include AccountAssociations
include AccountAvatar include Account::Associations
include AccountFinderConcern include Account::Avatar
include AccountHeader include Account::Counters
include AccountInteractions include Account::FinderConcern
include Paginable include Account::Header
include AccountCounters include Account::Interactions
include DomainNormalizable include Account::Merging
include Account::Search
include Account::StatusesSearch
include DomainMaterializable include DomainMaterializable
include AccountMerging include DomainNormalizable
include AccountSearch include Paginable
include AccountStatusesSearch
enum protocol: { ostatus: 0, activitypub: 1 } enum protocol: { ostatus: 0, activitypub: 1 }
enum suspension_origin: { local: 0, remote: 1 }, _prefix: true enum suspension_origin: { local: 0, remote: 1 }, _prefix: true

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountAssociations module Account::Associations
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountAvatar module Account::Avatar
extend ActiveSupport::Concern extend ActiveSupport::Concern
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountCounters module Account::Counters
extend ActiveSupport::Concern extend ActiveSupport::Concern
ALLOWED_COUNTER_KEYS = %i(statuses_count following_count followers_count).freeze ALLOWED_COUNTER_KEYS = %i(statuses_count following_count followers_count).freeze

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountFinderConcern module Account::FinderConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountHeader module Account::Header
extend ActiveSupport::Concern extend ActiveSupport::Concern
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountInteractions module Account::Interactions
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountMerging module Account::Merging
extend ActiveSupport::Concern extend ActiveSupport::Concern
def merge_with!(other_account) def merge_with!(other_account)

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountSearch module Account::Search
extend ActiveSupport::Concern extend ActiveSupport::Concern
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/ DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module AccountStatusesSearch module Account::StatusesSearch
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module StatusSafeReblogInsert module Status::SafeReblogInsert
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module StatusSearchConcern module Status::SearchConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module StatusSnapshotConcern module Status::SnapshotConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module StatusThreadingConcern module Status::ThreadingConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
def ancestors(limit, account = nil) def ancestors(limit, account = nil)

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module HasUserSettings module User::HasSettings
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module LdapAuthenticable module User::LdapAuthenticable
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Omniauthable module User::Omniauthable
extend ActiveSupport::Concern extend ActiveSupport::Concern
TEMP_EMAIL_PREFIX = 'change@me' TEMP_EMAIL_PREFIX = 'change@me'

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module PamAuthenticable module User::PamAuthenticable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do

View File

@ -30,14 +30,14 @@
# #
class Status < ApplicationRecord class Status < ApplicationRecord
include Cacheable
include Discard::Model include Discard::Model
include Paginable include Paginable
include Cacheable
include StatusThreadingConcern
include StatusSnapshotConcern
include RateLimitable include RateLimitable
include StatusSafeReblogInsert include Status::SafeReblogInsert
include StatusSearchConcern include Status::SearchConcern
include Status::SnapshotConcern
include Status::ThreadingConcern
rate_limit by: :account, family: :statuses rate_limit by: :account, family: :statuses

View File

@ -53,9 +53,12 @@ class User < ApplicationRecord
filtered_languages filtered_languages
) )
include Redisable
include LanguagesHelper include LanguagesHelper
include HasUserSettings include Redisable
include User::HasSettings
include User::LdapAuthenticable
include User::Omniauthable
include User::PamAuthenticable
# The home and list feeds will be stored in Redis for this amount # The home and list feeds will be stored in Redis for this amount
# of time, and status fan-out to followers will include only people # of time, and status fan-out to followers will include only people
@ -75,10 +78,6 @@ class User < ApplicationRecord
devise :registerable, :recoverable, :validatable, devise :registerable, :recoverable, :validatable,
:confirmable :confirmable
include Omniauthable
include PamAuthenticable
include LdapAuthenticable
belongs_to :account, inverse_of: :user belongs_to :account, inverse_of: :user
belongs_to :invite, counter_cache: :uses, optional: true belongs_to :invite, counter_cache: :uses, optional: true
belongs_to :created_by_application, class_name: 'Doorkeeper::Application', optional: true belongs_to :created_by_application, class_name: 'Doorkeeper::Application', optional: true

View File

@ -33,7 +33,7 @@
.fields-row .fields-row
.fields-row__column.fields-row__column-6 .fields-row__column.fields-row__column-6
.fields-group .fields-group
= f.input :avatar, wrapper: :with_block_label, input_html: { accept: AccountAvatar::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.avatar', dimensions: '400x400', size: number_to_human_size(AccountAvatar::LIMIT)) = f.input :avatar, wrapper: :with_block_label, input_html: { accept: Account::Avatar::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.avatar', dimensions: '400x400', size: number_to_human_size(Account::Avatar::LIMIT))
.fields-row__column.fields-row__column-6 .fields-row__column.fields-row__column-6
.fields-group .fields-group
@ -46,7 +46,7 @@
.fields-row .fields-row
.fields-row__column.fields-row__column-6 .fields-row__column.fields-row__column-6
.fields-group .fields-group
= f.input :header, wrapper: :with_block_label, input_html: { accept: AccountHeader::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.header', dimensions: '1500x500', size: number_to_human_size(AccountHeader::LIMIT)) = f.input :header, wrapper: :with_block_label, input_html: { accept: Account::Header::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.header', dimensions: '1500x500', size: number_to_human_size(Account::Header::LIMIT))
.fields-row__column.fields-row__column-6 .fields-row__column.fields-row__column-6
.fields-group .fields-group

View File

@ -67,8 +67,8 @@ module Mastodon::CLI
local? ? username : "#{username}@#{domain}" local? ? username : "#{username}@#{domain}"
end end
# This is a duplicate of the AccountMerging concern because we need it to # This is a duplicate of the Account::Merging concern because we need it
# be independent from code version. # to be independent from code version.
def merge_with!(other_account) def merge_with!(other_account)
# Since it's the same remote resource, the remote resource likely # Since it's the same remote resource, the remote resource likely
# already believes we are following/blocking, so it's safe to # already believes we are following/blocking, so it's safe to

View File

@ -451,7 +451,7 @@ RSpec.describe Account do
end end
it 'limits via constant by default' do it 'limits via constant by default' do
stub_const('AccountSearch::DEFAULT_LIMIT', 1) stub_const('Account::Search::DEFAULT_LIMIT', 1)
2.times.each { Fabricate(:account, display_name: 'Display Name') } 2.times.each { Fabricate(:account, display_name: 'Display Name') }
results = described_class.search_for('display') results = described_class.search_for('display')
expect(results.size).to eq 1 expect(results.size).to eq 1
@ -595,7 +595,7 @@ RSpec.describe Account do
end end
it 'limits by 10 by default' do it 'limits by 10 by default' do
stub_const('AccountSearch::DEFAULT_LIMIT', 1) stub_const('Account::Search::DEFAULT_LIMIT', 1)
2.times { Fabricate(:account, display_name: 'Display Name') } 2.times { Fabricate(:account, display_name: 'Display Name') }
results = described_class.advanced_search_for('display', account) results = described_class.advanced_search_for('display', account)
expect(results.size).to eq 1 expect(results.size).to eq 1

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountCounters do describe Account::Counters do
let!(:account) { Fabricate(:account) } let!(:account) { Fabricate(:account) }
describe '#increment_count!' do describe '#increment_count!' do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountFinderConcern do describe Account::FinderConcern do
describe 'local finders' do describe 'local finders' do
let!(:account) { Fabricate(:account, username: 'Alice') } let!(:account) { Fabricate(:account, username: 'Alice') }

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountInteractions do describe Account::Interactions do
let(:account) { Fabricate(:account, username: 'account') } let(:account) { Fabricate(:account, username: 'account') }
let(:account_id) { account.id } let(:account_id) { account.id }
let(:account_ids) { [account_id] } let(:account_ids) { [account_id] }

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountStatusesSearch do describe Account::StatusesSearch do
let(:account) { Fabricate(:account, indexable: indexable) } let(:account) { Fabricate(:account, indexable: indexable) }
before do before do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe StatusThreadingConcern do describe Status::ThreadingConcern do
describe '#ancestors' do describe '#ancestors' do
let!(:alice) { Fabricate(:account, username: 'alice') } let!(:alice) { Fabricate(:account, username: 'alice') }
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountSearch do describe Account::Search do
describe 'a non-discoverable account becoming discoverable' do describe 'a non-discoverable account becoming discoverable' do
let(:account) { Account.find_by(username: 'search_test_account_1') } let(:account) { Account.find_by(username: 'search_test_account_1') }

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
describe AccountStatusesSearch do describe Account::StatusesSearch do
describe 'a non-indexable account becoming indexable' do describe 'a non-indexable account becoming indexable' do
let(:account) { Account.find_by(username: 'search_test_account_1') } let(:account) { Account.find_by(username: 'search_test_account_1') }