mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 15:58:50 +00:00
Move "everyone" role and "instance actor" account magic number IDs to constants (#29260)
This commit is contained in:
@@ -5,6 +5,8 @@ class AddInstanceActor < ActiveRecord::Migration[5.2]
|
||||
# Dummy class, to make migration possible across version changes
|
||||
validates :username, uniqueness: { scope: :domain, case_sensitive: false }
|
||||
|
||||
INSTANCE_ACTOR_ID = -99
|
||||
|
||||
before_create :generate_keys
|
||||
|
||||
def generate_keys
|
||||
@@ -15,10 +17,10 @@ class AddInstanceActor < ActiveRecord::Migration[5.2]
|
||||
end
|
||||
|
||||
def up
|
||||
Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
|
||||
Account.create!(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
|
||||
end
|
||||
|
||||
def down
|
||||
Account.find_by(id: -99, actor_type: 'Application').destroy!
|
||||
Account.find_by(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application').destroy!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class UserRole < ApplicationRecord; end
|
||||
class UserRole < ApplicationRecord
|
||||
EVERYONE_ROLE_ID = -99
|
||||
end
|
||||
|
||||
def up
|
||||
process_role_everyone
|
||||
@@ -17,7 +19,7 @@ class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
|
||||
private
|
||||
|
||||
def process_role_everyone
|
||||
everyone_role = UserRole.find_by(id: -99)
|
||||
everyone_role = UserRole.find_by(id: UserRole::EVERYONE_ROLE_ID)
|
||||
return unless everyone_role
|
||||
|
||||
everyone_role.permissions &= ~::UserRole::FLAGS[:invite_users] unless min_invite_role == 'user'
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Account.create_with(actor_type: 'Application', locked: true, username: 'mastodon.internal').find_or_create_by(id: -99)
|
||||
Account.create_with(actor_type: 'Application', locked: true, username: 'mastodon.internal').find_or_create_by(id: Account::INSTANCE_ACTOR_ID)
|
||||
|
||||
Reference in New Issue
Block a user