FEATURE: Pull hotlinked images in user bios (#14726)

This commit is contained in:
Bianca Nenciu
2021-10-29 17:58:05 +03:00
committed by GitHub
parent 19ef6995a8
commit 1c3c0f04d9
5 changed files with 89 additions and 1 deletions
+13
View File
@@ -12,6 +12,7 @@ class UserProfile < ActiveRecord::Base
validates :user, presence: true
before_save :cook
after_save :trigger_badges
after_save :pull_hotlinked_image
validate :website_domain_validator, if: Proc.new { |c| c.new_record? || c.website_changed? }
@@ -19,6 +20,8 @@ class UserProfile < ActiveRecord::Base
BAKED_VERSION = 1
attr_accessor :skip_pull_hotlinked_image
def bio_excerpt(length = 350, opts = {})
return nil if bio_cooked.blank?
excerpt = PrettyText.excerpt(bio_cooked, length, opts).sub(/<br>$/, '')
@@ -113,6 +116,16 @@ class UserProfile < ActiveRecord::Base
BadgeGranter.queue_badge_grant(Badge::Trigger::UserChange, user: self)
end
def pull_hotlinked_image
if !skip_pull_hotlinked_image && saved_change_to_bio_raw?
Jobs.enqueue_in(
SiteSetting.editing_grace_period,
:pull_user_profile_hotlinked_images,
user_id: self.user_id
)
end
end
private
def cooked