mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Apply syntax_tree formatting to app/*
This commit is contained in:
@ -7,13 +7,19 @@ class UserProfile < ActiveRecord::Base
|
||||
belongs_to :card_background_upload, class_name: "Upload"
|
||||
belongs_to :profile_background_upload, class_name: "Upload"
|
||||
belongs_to :granted_title_badge, class_name: "Badge"
|
||||
belongs_to :featured_topic, class_name: 'Topic'
|
||||
belongs_to :featured_topic, class_name: "Topic"
|
||||
|
||||
has_many :upload_references, as: :target, dependent: :destroy
|
||||
has_many :user_profile_views, dependent: :destroy
|
||||
|
||||
validates :bio_raw, length: { maximum: 3000 }, watched_words: true
|
||||
validates :website, url: true, length: { maximum: 3000 }, allow_blank: true, if: :validate_website?
|
||||
validates :website,
|
||||
url: true,
|
||||
length: {
|
||||
maximum: 3000,
|
||||
},
|
||||
allow_blank: true,
|
||||
if: :validate_website?
|
||||
validates :location, length: { maximum: 3000 }, watched_words: true
|
||||
validates :user, presence: true
|
||||
|
||||
@ -26,8 +32,11 @@ class UserProfile < ActiveRecord::Base
|
||||
after_save :pull_hotlinked_image
|
||||
|
||||
after_save do
|
||||
if saved_change_to_profile_background_upload_id? || saved_change_to_card_background_upload_id? || saved_change_to_bio_raw?
|
||||
upload_ids = [self.profile_background_upload_id, self.card_background_upload_id] + Upload.extract_upload_ids(self.bio_raw)
|
||||
if saved_change_to_profile_background_upload_id? ||
|
||||
saved_change_to_card_background_upload_id? || saved_change_to_bio_raw?
|
||||
upload_ids =
|
||||
[self.profile_background_upload_id, self.card_background_upload_id] +
|
||||
Upload.extract_upload_ids(self.bio_raw)
|
||||
UploadReference.ensure_exist!(upload_ids: upload_ids, target: self)
|
||||
end
|
||||
end
|
||||
@ -36,13 +45,15 @@ class UserProfile < ActiveRecord::Base
|
||||
|
||||
def bio_excerpt(length = 350, opts = {})
|
||||
return nil if bio_cooked.blank?
|
||||
excerpt = PrettyText.excerpt(bio_cooked, length, opts).sub(/<br>$/, '')
|
||||
excerpt = PrettyText.excerpt(bio_cooked, length, opts).sub(/<br>$/, "")
|
||||
return excerpt if excerpt.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?)
|
||||
PrettyText.strip_links(excerpt)
|
||||
end
|
||||
|
||||
def bio_processed
|
||||
return bio_cooked if bio_cooked.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?)
|
||||
if bio_cooked.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?)
|
||||
return bio_cooked
|
||||
end
|
||||
PrettyText.strip_links(bio_cooked)
|
||||
end
|
||||
|
||||
@ -73,14 +84,16 @@ class UserProfile < ActiveRecord::Base
|
||||
|
||||
def self.rebake_old(limit)
|
||||
problems = []
|
||||
UserProfile.where('bio_cooked_version IS NULL OR bio_cooked_version < ?', BAKED_VERSION)
|
||||
.limit(limit).each do |p|
|
||||
begin
|
||||
p.rebake!
|
||||
rescue => e
|
||||
problems << { profile: p, ex: e }
|
||||
UserProfile
|
||||
.where("bio_cooked_version IS NULL OR bio_cooked_version < ?", BAKED_VERSION)
|
||||
.limit(limit)
|
||||
.each do |p|
|
||||
begin
|
||||
p.rebake!
|
||||
rescue => e
|
||||
problems << { profile: p, ex: e }
|
||||
end
|
||||
end
|
||||
end
|
||||
problems
|
||||
end
|
||||
|
||||
@ -90,15 +103,18 @@ class UserProfile < ActiveRecord::Base
|
||||
|
||||
def self.import_url_for_user(background_url, user, options = nil)
|
||||
if SiteSetting.verbose_upload_logging
|
||||
Rails.logger.warn("Verbose Upload Logging: Downloading profile background from #{background_url}")
|
||||
Rails.logger.warn(
|
||||
"Verbose Upload Logging: Downloading profile background from #{background_url}",
|
||||
)
|
||||
end
|
||||
|
||||
tempfile = FileHelper.download(
|
||||
background_url,
|
||||
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
||||
tmp_file_name: "sso-profile-background",
|
||||
follow_redirect: true
|
||||
)
|
||||
tempfile =
|
||||
FileHelper.download(
|
||||
background_url,
|
||||
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
||||
tmp_file_name: "sso-profile-background",
|
||||
follow_redirect: true,
|
||||
)
|
||||
|
||||
return unless tempfile
|
||||
|
||||
@ -108,14 +124,19 @@ class UserProfile < ActiveRecord::Base
|
||||
is_card_background = !options || options[:is_card_background]
|
||||
type = is_card_background ? "card_background" : "profile_background"
|
||||
|
||||
upload = UploadCreator.new(tempfile, "external-profile-background." + ext, origin: background_url, type: type).create_for(user.id)
|
||||
upload =
|
||||
UploadCreator.new(
|
||||
tempfile,
|
||||
"external-profile-background." + ext,
|
||||
origin: background_url,
|
||||
type: type,
|
||||
).create_for(user.id)
|
||||
|
||||
if (is_card_background)
|
||||
user.user_profile.upload_card_background(upload)
|
||||
else
|
||||
user.user_profile.upload_profile_background(upload)
|
||||
end
|
||||
|
||||
rescue Net::ReadTimeout, OpenURI::HTTPError
|
||||
# skip saving, we are not connected to the net
|
||||
ensure
|
||||
@ -133,7 +154,7 @@ class UserProfile < ActiveRecord::Base
|
||||
Jobs.enqueue_in(
|
||||
SiteSetting.editing_grace_period,
|
||||
:pull_user_profile_hotlinked_images,
|
||||
user_id: self.user_id
|
||||
user_id: self.user_id,
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -146,7 +167,10 @@ class UserProfile < ActiveRecord::Base
|
||||
|
||||
def cooked
|
||||
if self.bio_raw.present?
|
||||
PrettyText.cook(self.bio_raw, omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow)
|
||||
PrettyText.cook(
|
||||
self.bio_raw,
|
||||
omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow,
|
||||
)
|
||||
else
|
||||
nil
|
||||
end
|
||||
@ -171,11 +195,20 @@ class UserProfile < ActiveRecord::Base
|
||||
allowed_domains = SiteSetting.allowed_user_website_domains
|
||||
return if (allowed_domains.blank? || self.website.blank?)
|
||||
|
||||
domain = begin
|
||||
URI.parse(self.website).host
|
||||
rescue URI::Error
|
||||
domain =
|
||||
begin
|
||||
URI.parse(self.website).host
|
||||
rescue URI::Error
|
||||
end
|
||||
unless allowed_domains.split("|").include?(domain)
|
||||
self.errors.add :base,
|
||||
(
|
||||
I18n.t(
|
||||
"user.website.domain_not_allowed",
|
||||
domains: allowed_domains.split("|").join(", "),
|
||||
)
|
||||
)
|
||||
end
|
||||
self.errors.add :base, (I18n.t('user.website.domain_not_allowed', domains: allowed_domains.split('|').join(", "))) unless allowed_domains.split('|').include?(domain)
|
||||
end
|
||||
|
||||
def validate_website?
|
||||
|
Reference in New Issue
Block a user