diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-07-15 13:47:08 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-07-15 14:12:24 -0500 |
commit | 436f7984d9ea60ec0dc222fcbcaa795792942781 (patch) | |
tree | d21f26779ed8fe1a7efee820cce07338db9f317a | |
parent | 9a2f0131c6cddef3ef0e7faa73070945f0d4f452 (diff) |
move user variables to `users` relation
-rw-r--r-- | app/lib/bangtags.rb | 4 | ||||
-rw-r--r-- | app/models/account.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 5 | ||||
-rw-r--r-- | app/services/import_service.rb | 8 | ||||
-rw-r--r-- | db/migrate/20190531082330_add_vars_to_users.rb | 5 | ||||
-rw-r--r-- | db/migrate/20190531082452_move_account_vars_to_users.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 1 |
7 files changed, 27 insertions, 6 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index e106dc582..8ed8a0612 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -28,7 +28,7 @@ class Bangtags # list of post-processing commands @post_cmds = [] # hash of bangtag variables - @vars = account.vars + @vars = account.user.vars # keep track of what variables we're appending the value of between chunks @vore_stack = [] # keep track of what type of nested components are active so we can !end them in order @@ -516,7 +516,7 @@ class Bangtags postprocess_before_save - account.save + account.user.save status.text = @chunks.join status.save diff --git a/app/models/account.rb b/app/models/account.rb index 8187bc7d9..d30c2a9ec 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -313,6 +313,10 @@ class Account < ApplicationRecord self[:also_known_as] || [] end + def field + @field ||= fields.map { |f| [f.name, f.value] }.to_h + end + def fields (self[:fields] || []).map { |f| Field.new(self, f) } end @@ -352,6 +356,7 @@ class Account < ApplicationRecord self.fields = tmp end + # needs to be removed after migration def vars self[:vars] end diff --git a/app/models/user.rb b/app/models/user.rb index 5f1ffb595..6aafa124a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,6 +38,7 @@ # chosen_languages :string is an Array # created_by_application_id :bigint(8) # approved :boolean default(TRUE), not null +# vars :jsonb not null # class User < ApplicationRecord @@ -151,6 +152,10 @@ class User < ApplicationRecord attr_reader :invite_code attr_writer :external + def vars + self[:vars] + end + def confirmed? confirmed_at.present? end diff --git a/app/services/import_service.rb b/app/services/import_service.rb index 9b0a03081..248178e8c 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -100,8 +100,8 @@ class ImportService < BaseService end def import_json_statuses - @account.vars['_bangtags:disable'] = true - @account.save + @account.user.vars['_bangtags:disable'] = true + @account.user.save @data.each do |json| # skip if invalid status object @@ -172,8 +172,8 @@ class ImportService < BaseService nil end - @account.vars.delete('_bangtags:disable') - @account.save + @account.user.vars.delete('_bangtags:disable') + @account.user.save end def import_activitypub diff --git a/db/migrate/20190531082330_add_vars_to_users.rb b/db/migrate/20190531082330_add_vars_to_users.rb new file mode 100644 index 000000000..c3937a350 --- /dev/null +++ b/db/migrate/20190531082330_add_vars_to_users.rb @@ -0,0 +1,5 @@ +class AddVarsToUsers < ActiveRecord::Migration[5.2] + def change + safety_assured { add_column :users, :vars, :jsonb, null:false, default: {} } + end +end diff --git a/db/migrate/20190531082452_move_account_vars_to_users.rb b/db/migrate/20190531082452_move_account_vars_to_users.rb new file mode 100644 index 000000000..fea150b78 --- /dev/null +++ b/db/migrate/20190531082452_move_account_vars_to_users.rb @@ -0,0 +1,5 @@ +class MoveAccountVarsToUsers < ActiveRecord::Migration[5.2] + def up + Account.local.find_each { |a| a.user.vars = a.vars; a.user.save } + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c4360422..2ccbf9e9f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -762,6 +762,7 @@ ActiveRecord::Schema.define(version: 2019_05_21_003909) do t.string "chosen_languages", array: true t.bigint "created_by_application_id" t.boolean "approved", default: true, null: false + t.jsonb "vars", default: {}, null: false t.index ["account_id"], name: "index_users_on_account_id" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id" |