fix: Disable enqueueing Avatar jobs if the URL is invalid (#12035)

- Add a new queue purgable
- Disable enqueuing the job if URL is invalid
This commit is contained in:
Pranav
2025-07-24 12:56:39 +04:00
committed by GitHub
parent 2a5ecf84a1
commit 9acb0d86b5
7 changed files with 21 additions and 6 deletions

View File

@@ -6,6 +6,7 @@
# We don't want to update the name of the identified original contact.
class ContactIdentifyAction
include UrlHelper
pattr_initialize [:contact!, :params!, { retain_original_contact_name: false, discard_invalid_attrs: false }]
def perform
@@ -104,7 +105,14 @@ class ContactIdentifyAction
# TODO: replace reject { |_k, v| v.blank? } with compact_blank when rails is upgraded
@contact.discard_invalid_attrs if discard_invalid_attrs
@contact.save!
Avatar::AvatarFromUrlJob.perform_later(@contact, params[:avatar_url]) if params[:avatar_url].present? && !@contact.avatar.attached?
enqueue_avatar_job
end
def enqueue_avatar_job
return unless params[:avatar_url].present? && !@contact.avatar.attached?
return unless url_valid?(params[:avatar_url])
Avatar::AvatarFromUrlJob.perform_later(@contact, params[:avatar_url])
end
def merge_contact(base_contact, merge_contact)

View File

@@ -1,5 +1,5 @@
class Avatar::AvatarFromGravatarJob < ApplicationJob
queue_as :low
queue_as :purgable
def perform(avatarable, email)
return if GlobalConfigService.load('DISABLE_GRAVATAR', '').present?

View File

@@ -1,5 +1,5 @@
class Avatar::AvatarFromUrlJob < ApplicationJob
queue_as :low
queue_as :purgable
def perform(avatarable, avatar_url)
return unless avatarable.respond_to?(:avatar)