Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: Vagrantfile app/javascript/packs/public.js app/views/admin/settings/edit.html.haml app/views/settings/preferences/show.html.haml app/views/settings/profiles/show.html.haml config/locales/es.yml config/locales/simple_form.en.yml config/webpack/configuration.js config/webpack/loaders/babel.js package.json yarn.lock Split new additions to app/javascript/packs/public.js to app/javascript/core/settings.js
This commit is contained in:
@@ -226,11 +226,19 @@ class Account < ApplicationRecord
|
||||
end
|
||||
|
||||
def fields_attributes=(attributes)
|
||||
fields = []
|
||||
fields = []
|
||||
old_fields = self[:fields] || []
|
||||
|
||||
if attributes.is_a?(Hash)
|
||||
attributes.each_value do |attr|
|
||||
next if attr[:name].blank?
|
||||
|
||||
previous = old_fields.find { |item| item['value'] == attr[:value] }
|
||||
|
||||
if previous && previous['verified_at'].present?
|
||||
attr[:verified_at] = previous['verified_at']
|
||||
end
|
||||
|
||||
fields << attr
|
||||
end
|
||||
end
|
||||
@@ -238,13 +246,18 @@ class Account < ApplicationRecord
|
||||
self[:fields] = fields
|
||||
end
|
||||
|
||||
def build_fields
|
||||
return if fields.size >= 4
|
||||
DEFAULT_FIELDS_SIZE = 4
|
||||
|
||||
raw_fields = self[:fields] || []
|
||||
add_fields = 4 - raw_fields.size
|
||||
add_fields.times { raw_fields << { name: '', value: '' } }
|
||||
self.fields = raw_fields
|
||||
def build_fields
|
||||
return if fields.size >= DEFAULT_FIELDS_SIZE
|
||||
|
||||
tmp = self[:fields] || []
|
||||
|
||||
(DEFAULT_FIELDS_SIZE - tmp.size).times do
|
||||
tmp << { name: '', value: '' }
|
||||
end
|
||||
|
||||
self.fields = tmp
|
||||
end
|
||||
|
||||
def magic_key
|
||||
@@ -297,17 +310,32 @@ class Account < ApplicationRecord
|
||||
end
|
||||
|
||||
class Field < ActiveModelSerializers::Model
|
||||
attributes :name, :value, :account, :errors
|
||||
attributes :name, :value, :verified_at, :account, :errors
|
||||
|
||||
def initialize(account, attr)
|
||||
@account = account
|
||||
@name = attr['name'].strip[0, 255]
|
||||
@value = attr['value'].strip[0, 255]
|
||||
@errors = {}
|
||||
def initialize(account, attributes)
|
||||
@account = account
|
||||
@attributes = attributes
|
||||
@name = attributes['name'].strip[0, 255]
|
||||
@value = attributes['value'].strip[0, 255]
|
||||
@verified_at = attributes['verified_at']&.to_datetime
|
||||
@errors = {}
|
||||
end
|
||||
|
||||
def verified?
|
||||
verified_at.present?
|
||||
end
|
||||
|
||||
def verifiable?
|
||||
value.present? && value.start_with?('http://', 'https://')
|
||||
end
|
||||
|
||||
def mark_verified!
|
||||
@verified_at = Time.now.utc
|
||||
@attributes['verified_at'] = @verified_at
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ name: @name, value: @value }
|
||||
{ name: @name, value: @value, verified_at: @verified_at }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user