Merge remote-tracking branch 'parent/main' into upstream-20240218

This commit is contained in:
KMY 2024-02-20 09:25:49 +09:00
commit 7684b5de6f
47 changed files with 412 additions and 115 deletions

View file

@ -69,6 +69,7 @@ class Account < ApplicationRecord
)
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
INSTANCE_ACTOR_ID = -99
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
@ -127,7 +128,7 @@ class Account < ApplicationRecord
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_instance_actor, -> { where.not(id: -99) }
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: %w(Application Service)) }
scope :groups, -> { where(actor_type: 'Group') }
@ -185,7 +186,7 @@ class Account < ApplicationRecord
end
def instance_actor?
id == -99
id == INSTANCE_ACTOR_ID
end
alias bot bot?

View file

@ -13,11 +13,11 @@ module Account::FinderConcern
end
def representative
actor = Account.find(-99).tap(&:ensure_keys!)
actor = Account.find(Account::INSTANCE_ACTOR_ID).tap(&:ensure_keys!)
actor.update!(username: 'mastodon.internal') if actor.username.include?(':')
actor
rescue ActiveRecord::RecordNotFound
Account.create!(id: -99, actor_type: 'Application', locked: true, username: 'mastodon.internal')
Account.create!(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: 'mastodon.internal')
end
def find_local(username)

View file

@ -40,6 +40,8 @@ class UserRole < ApplicationRecord
manage_ng_words: (1 << 30),
}.freeze
EVERYONE_ROLE_ID = -99
module Flags
NONE = 0
ALL = FLAGS.values.reduce(&:|)
@ -98,7 +100,7 @@ class UserRole < ApplicationRecord
before_validation :set_position
scope :assignable, -> { where.not(id: -99).order(position: :asc) }
scope :assignable, -> { where.not(id: EVERYONE_ROLE_ID).order(position: :asc) }
has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify
@ -107,9 +109,9 @@ class UserRole < ApplicationRecord
end
def self.everyone
UserRole.find(-99)
UserRole.find(EVERYONE_ROLE_ID)
rescue ActiveRecord::RecordNotFound
UserRole.create!(id: -99, permissions: Flags::DEFAULT)
UserRole.create!(id: EVERYONE_ROLE_ID, permissions: Flags::DEFAULT)
end
def self.that_can(*any_of_privileges)
@ -117,7 +119,7 @@ class UserRole < ApplicationRecord
end
def everyone?
id == -99
id == EVERYONE_ROLE_ID
end
def nobody?