mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-21 00:29:47 +00:00
Use normalizes to prepare Account#username
value (#28646)
This commit is contained in:
parent
cd58e37b25
commit
9322396e58
|
@ -108,6 +108,8 @@ class Account < ApplicationRecord
|
||||||
validates :shared_inbox_url, absence: true, if: :local?, on: :create
|
validates :shared_inbox_url, absence: true, if: :local?, on: :create
|
||||||
validates :followers_url, absence: true, if: :local?, on: :create
|
validates :followers_url, absence: true, if: :local?, on: :create
|
||||||
|
|
||||||
|
normalizes :username, with: ->(username) { username.squish }
|
||||||
|
|
||||||
scope :remote, -> { where.not(domain: nil) }
|
scope :remote, -> { where.not(domain: nil) }
|
||||||
scope :local, -> { where(domain: nil) }
|
scope :local, -> { where(domain: nil) }
|
||||||
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
|
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
|
||||||
|
@ -475,7 +477,6 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
before_validation :prepare_contents, if: :local?
|
before_validation :prepare_contents, if: :local?
|
||||||
before_validation :prepare_username, on: :create
|
|
||||||
before_create :generate_keys
|
before_create :generate_keys
|
||||||
before_destroy :clean_feed_manager
|
before_destroy :clean_feed_manager
|
||||||
|
|
||||||
|
@ -493,10 +494,6 @@ class Account < ApplicationRecord
|
||||||
note&.strip!
|
note&.strip!
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_username
|
|
||||||
username&.squish!
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_keys
|
def generate_keys
|
||||||
return unless local? && private_key.blank? && public_key.blank?
|
return unless local? && private_key.blank? && public_key.blank?
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue