0
0
Fork 0

Add bio fields (#6645)

* Add bio fields

- Fix #3211
- Fix #232
- Fix #121

* Display bio fields in web UI

* Fix output of links and missing fields

* Federate bio fields over ActivityPub as PropertyValue

* Improve how the fields are stored, add to Edit profile form

* Add rel=me to links in fields

Fix #121
This commit is contained in:
Eugen Rochko 2018-04-14 12:41:08 +02:00 committed by GitHub
parent 85ab30abf7
commit 78ed4ab75f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 274 additions and 7 deletions

View file

@ -44,6 +44,7 @@
# memorial :boolean default(FALSE), not null
# moved_to_account_id :integer
# featured_collection_url :string
# fields :jsonb
#
class Account < ApplicationRecord
@ -189,6 +190,30 @@ class Account < ApplicationRecord
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
end
def fields
(self[:fields] || []).map { |f| Field.new(self, f) }
end
def fields_attributes=(attributes)
fields = []
attributes.each_value do |attr|
next if attr[:name].blank?
fields << attr
end
self[:fields] = fields
end
def build_fields
return if fields.size >= 4
raw_fields = self[:fields] || []
add_fields = 4 - raw_fields.size
add_fields.times { raw_fields << { name: '', value: '' } }
self.fields = raw_fields
end
def magic_key
modulus, exponent = [keypair.public_key.n, keypair.public_key.e].map do |component|
result = []
@ -238,6 +263,17 @@ class Account < ApplicationRecord
shared_inbox_url.presence || inbox_url
end
class Field < ActiveModelSerializers::Model
attributes :name, :value, :account, :errors
def initialize(account, attr)
@account = account
@name = attr['name']
@value = attr['value']
@errors = {}
end
end
class << self
def readonly_attributes
super - %w(statuses_count following_count followers_count)