commit
9a64fe852e
3 changed files with 31 additions and 25 deletions
|
@ -13,18 +13,8 @@ class AddMasterSettingsToAccounts < ActiveRecord::Migration[7.1]
|
|||
safety_assured do
|
||||
add_column :accounts, :master_settings, :jsonb
|
||||
|
||||
if Rails.env.test?
|
||||
Account.transaction do
|
||||
Account.find_in_batches do |accounts|
|
||||
accounts.each do |account|
|
||||
account.update(master_settings: { 'subscription_policy' => account.dissubscribable ? 'block' : 'allow' })
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
Account.where(dissubscribable: true).update_all(master_settings: { 'subscription_policy' => 'block' }) # rubocop:disable Rails/SkipsModelValidations
|
||||
Account.where(dissubscribable: false).update_all(master_settings: { 'subscription_policy' => 'allow' }) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
ActiveRecord::Base.connection.execute("UPDATE accounts SET master_settings = json_build_object('subscription_policy', 'block') WHERE accounts.dissubscribable IS TRUE")
|
||||
ActiveRecord::Base.connection.execute("UPDATE accounts SET master_settings = json_build_object('subscription_policy', 'allow') WHERE accounts.dissubscribable IS FALSE")
|
||||
|
||||
remove_column :accounts, :dissubscribable
|
||||
end
|
||||
|
@ -34,18 +24,8 @@ class AddMasterSettingsToAccounts < ActiveRecord::Migration[7.1]
|
|||
safety_assured do
|
||||
add_column_with_default :accounts, :dissubscribable, :boolean, default: false, allow_null: false
|
||||
|
||||
if Rails.env.test?
|
||||
Account.transaction do
|
||||
Account.find_in_batches do |accounts|
|
||||
accounts.each do |account|
|
||||
account.update(dissubscribable: account.master_settings.present? && account.master_settings['subscription_policy'] != 'allow')
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
Account.where(master_settings: { subscription_policy: 'block' }).update_all(dissubscribable: true) # rubocop:disable Rails/SkipsModelValidations
|
||||
Account.where(master_settings: { subscription_policy: 'allow' }).update_all(dissubscribable: false) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
ActiveRecord::Base.connection.execute("UPDATE accounts SET dissubscribable = TRUE WHERE master_settings ->> 'subscription_policy' = 'block'")
|
||||
ActiveRecord::Base.connection.execute("UPDATE accounts SET dissubscribable = FALSE WHERE master_settings ->> 'subscription_policy' = 'allow'")
|
||||
|
||||
remove_column :accounts, :master_settings
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Mastodon
|
|||
end
|
||||
|
||||
def kmyblue_minor
|
||||
2
|
||||
3
|
||||
end
|
||||
|
||||
def kmyblue_flag
|
||||
|
|
|
@ -252,6 +252,32 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with other settings' do
|
||||
let(:payload) do
|
||||
{
|
||||
id: 'https://foo.test',
|
||||
type: 'Actor',
|
||||
inbox: 'https://foo.test/inbox',
|
||||
otherSetting: [
|
||||
{ type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
|
||||
{ type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
|
||||
],
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'parses out of attachment' do
|
||||
account = subject.call('alice', 'example.com', payload)
|
||||
expect(account.settings).to be_a Hash
|
||||
expect(account.settings.size).to eq 2
|
||||
expect(account.settings['Pronouns']).to eq 'They/them'
|
||||
expect(account.settings['Occupation']).to eq 'Unit test'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not suspended' do
|
||||
subject { described_class.new.call('alice', 'example.com', payload) }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue