Add setting column and its serializer to Account
This commit is contained in:
parent
1877a1dff1
commit
324d402d70
7 changed files with 62 additions and 3 deletions
|
@ -26,6 +26,7 @@ module ContextHelper
|
||||||
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
|
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
|
||||||
quote_uri: { 'fedibird' => 'http://fedibird.com/ns#', 'quoteUri' => 'fedibird:quoteUri' },
|
quote_uri: { 'fedibird' => 'http://fedibird.com/ns#', 'quoteUri' => 'fedibird:quoteUri' },
|
||||||
expiry: { 'fedibird' => 'http://fedibird.com/ns#', 'expiry' => 'fedibird:expiry' },
|
expiry: { 'fedibird' => 'http://fedibird.com/ns#', 'expiry' => 'fedibird:expiry' },
|
||||||
|
other_setting: { 'fedibird' => 'http://fedibird.com/ns#', 'otherSetting' => 'fedibird:otherSetting' },
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def full_context
|
def full_context
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
# devices_url :string
|
# devices_url :string
|
||||||
# suspension_origin :integer
|
# suspension_origin :integer
|
||||||
# sensitized_at :datetime
|
# sensitized_at :datetime
|
||||||
|
# settings :jsonb default("{}"), not null
|
||||||
#
|
#
|
||||||
|
|
||||||
class Account < ApplicationRecord
|
class Account < ApplicationRecord
|
||||||
|
@ -396,6 +397,14 @@ class Account < ApplicationRecord
|
||||||
ActionController::Base.helpers.strip_tags(note)
|
ActionController::Base.helpers.strip_tags(note)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def settings
|
||||||
|
self[:settings].class == String ? {} : self[:settings]
|
||||||
|
end
|
||||||
|
|
||||||
|
def other_settings
|
||||||
|
settings
|
||||||
|
end
|
||||||
|
|
||||||
class Field < ActiveModelSerializers::Model
|
class Field < ActiveModelSerializers::Model
|
||||||
attributes :name, :value, :verified_at, :account
|
attributes :name, :value, :verified_at, :account
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||||
|
|
||||||
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
||||||
:moved_to, :property_value, :identity_proof,
|
:moved_to, :property_value, :identity_proof,
|
||||||
:discoverable, :olm, :suspended
|
:discoverable, :olm, :suspended, :other_setting
|
||||||
|
|
||||||
attributes :id, :type, :following, :followers,
|
attributes :id, :type, :following, :followers,
|
||||||
:inbox, :outbox, :featured, :featured_tags,
|
:inbox, :outbox, :featured, :featured_tags,
|
||||||
|
@ -25,6 +25,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||||
attribute :also_known_as, if: :also_known_as?
|
attribute :also_known_as, if: :also_known_as?
|
||||||
attribute :suspended, if: :suspended?
|
attribute :suspended, if: :suspended?
|
||||||
|
|
||||||
|
has_many :virtual_other_settings, key: :other_setting
|
||||||
|
|
||||||
class EndpointsSerializer < ActivityPub::Serializer
|
class EndpointsSerializer < ActivityPub::Serializer
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
|
@ -162,6 +164,16 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||||
object.created_at.midnight.iso8601
|
object.created_at.midnight.iso8601
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def virtual_other_settings
|
||||||
|
object.other_settings.map do |k, v|
|
||||||
|
{
|
||||||
|
type: 'PropertyValue',
|
||||||
|
name: k,
|
||||||
|
value: v,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
|
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :fields
|
has_many :fields
|
||||||
|
has_many :other_settings
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object.id.to_s
|
object.id.to_s
|
||||||
|
@ -91,6 +92,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||||
object.suspended? ? [] : object.fields
|
object.suspended? ? [] : object.fields
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def other_settings
|
||||||
|
object.suspended? ? [] : object.other_settings
|
||||||
|
end
|
||||||
|
|
||||||
def suspended
|
def suspended
|
||||||
object.suspended?
|
object.suspended?
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,6 +98,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
||||||
@account.note = @json['summary'] || ''
|
@account.note = @json['summary'] || ''
|
||||||
@account.locked = @json['manuallyApprovesFollowers'] || false
|
@account.locked = @json['manuallyApprovesFollowers'] || false
|
||||||
@account.fields = property_values || {}
|
@account.fields = property_values || {}
|
||||||
|
@account.settings = defer_settings.merge(other_settings || {})
|
||||||
@account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) }
|
@account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) }
|
||||||
@account.discoverable = @json['discoverable'] || false
|
@account.discoverable = @json['discoverable'] || false
|
||||||
end
|
end
|
||||||
|
@ -211,6 +212,18 @@ class ActivityPub::ProcessAccountService < BaseService
|
||||||
as_array(@json['attachment']).select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
|
as_array(@json['attachment']).select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DEFER_SETTINGS_KEYS = %w(
|
||||||
|
).freeze
|
||||||
|
|
||||||
|
def defer_settings
|
||||||
|
(@account.settings || {}).select { |key, _| DEFER_SETTINGS_KEYS.include?(key) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def other_settings
|
||||||
|
return unless @json['otherSetting'].is_a?(Array)
|
||||||
|
@json['otherSetting'].each_with_object({}) { |v, h| h.merge!({v['name'] => v['value']}) if v['type'] == 'PropertyValue' }
|
||||||
|
end
|
||||||
|
|
||||||
def mismatching_origin?(url)
|
def mismatching_origin?(url)
|
||||||
needle = Addressable::URI.parse(url).host
|
needle = Addressable::URI.parse(url).host
|
||||||
haystack = Addressable::URI.parse(@uri).host
|
haystack = Addressable::URI.parse(@uri).host
|
||||||
|
|
17
db/migrate/20220202115057_add_settings_to_accounts.rb
Normal file
17
db/migrate/20220202115057_add_settings_to_accounts.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||||
|
|
||||||
|
class AddSettingsToAccounts < ActiveRecord::Migration[6.1]
|
||||||
|
include Mastodon::MigrationHelpers
|
||||||
|
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def up
|
||||||
|
safety_assured { add_column_with_default :accounts, :settings, :jsonb, default: '{}', allow_null: false }
|
||||||
|
safety_assured { add_index :accounts, :settings, using: 'gin', algorithm: :concurrently, name: :index_accounts_on_settings }
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :accounts, name: :index_accounts_on_settings
|
||||||
|
remove_column :accounts, :settings
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_12_13_083734) do
|
ActiveRecord::Schema.define(version: 2022_02_02_115057) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -207,9 +207,11 @@ ActiveRecord::Schema.define(version: 2021_12_13_083734) do
|
||||||
t.string "devices_url"
|
t.string "devices_url"
|
||||||
t.integer "suspension_origin"
|
t.integer "suspension_origin"
|
||||||
t.datetime "sensitized_at"
|
t.datetime "sensitized_at"
|
||||||
|
t.jsonb "settings", default: "{}", null: false
|
||||||
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
||||||
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
||||||
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
|
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
|
||||||
|
t.index ["settings"], name: "index_accounts_on_settings", using: :gin
|
||||||
t.index ["uri"], name: "index_accounts_on_uri"
|
t.index ["uri"], name: "index_accounts_on_uri"
|
||||||
t.index ["url"], name: "index_accounts_on_url"
|
t.index ["url"], name: "index_accounts_on_url"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue