Merge branch 'master' into glitch-soc/master

Conflicts:
	app/models/account.rb
	app/views/accounts/_header.html.haml
This commit is contained in:
Thibaut Girka
2018-05-09 17:43:30 +02:00
145 changed files with 3052 additions and 803 deletions

View File

@ -45,6 +45,7 @@
# moved_to_account_id :bigint(8)
# featured_collection_url :string
# fields :jsonb
# actor_type :string
#
class Account < ApplicationRecord
@ -76,6 +77,7 @@ class Account < ApplicationRecord
validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? }
validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
# Timelines
has_many :stream_entries, inverse_of: :account, dependent: :destroy
@ -151,6 +153,16 @@ class Account < ApplicationRecord
moved_to_account_id.present?
end
def bot?
%w(Application Service).include? actor_type
end
alias bot bot?
def bot=(val)
self.actor_type = ActiveModel::Type::Boolean.new.cast(val) ? 'Service' : 'Person'
end
def acct
local? ? username : "#{username}@#{domain}"
end
@ -201,9 +213,11 @@ class Account < ApplicationRecord
def fields_attributes=(attributes)
fields = []
attributes.each_value do |attr|
next if attr[:name].blank?
fields << attr
if attributes.is_a?(Hash)
attributes.each_value do |attr|
next if attr[:name].blank?
fields << attr
end
end
self[:fields] = fields
@ -272,8 +286,8 @@ class Account < ApplicationRecord
def initialize(account, attr)
@account = account
@name = attr['name']
@value = attr['value']
@name = attr['name'].strip[0, 255]
@value = attr['value'].strip[0, 255]
@errors = {}
end
@ -398,7 +412,7 @@ class Account < ApplicationRecord
end
def emojis
@emojis ||= CustomEmoji.from_text(note, domain)
@emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
end
before_create :generate_keys
@ -441,4 +455,8 @@ class Account < ApplicationRecord
self.domain = TagManager.instance.normalize_domain(domain)
end
def emojifiable_text
[note, display_name, fields.map(&:value)].join(' ')
end
end

View File

@ -41,7 +41,7 @@ class User < ApplicationRecord
include Settings::Extend
include Omniauthable
ACTIVE_DURATION = 14.days
ACTIVE_DURATION = 7.days
devise :two_factor_authenticatable,
otp_secret_encryption_key: Rails.configuration.x.otp_secret