0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/plugins/discourse-zendesk-plugin/app/jobs/regular/zendesk_job.rb
Régis Hanol 36f1487556
FIX: pushing replies to topics already in zendesk (#36424)
When a topic is already linked to a zendesk ticket but not in a category
with "autogenerate", we would not push the replies to zendesk.

This ensures we do and update the specs.

Internal ref - t/169124
2025-12-04 17:18:46 +01:00

48 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class ZendeskJob < ::Jobs::Base
sidekiq_options backtrace: true
include DiscourseZendeskPlugin::Helper
def execute(args)
return unless SiteSetting.zendesk_enabled?
return if SiteSetting.zendesk_jobs_email.blank? || SiteSetting.zendesk_jobs_api_token.blank?
if args[:post_id].present?
push_post!(args[:post_id])
elsif args[:topic_id].present?
push_topic!(args[:topic_id])
end
end
private
def push_topic!(topic_id)
topic = Topic.find_by(id: topic_id)
return if topic.blank?
has_zendesk_ticket = topic.custom_fields[DiscourseZendeskPlugin::ZENDESK_ID_FIELD].present?
in_autogeneration_category =
DiscourseZendeskPlugin::Helper.autogeneration_category?(topic.category_id)
return if !has_zendesk_ticket && !in_autogeneration_category
topic.post_ids.each { |post_id| push_post!(post_id) }
end
def push_post!(post_id)
post = Post.find_by(id: post_id)
return if !post || post.user_id < 1
return if post.custom_fields[DiscourseZendeskPlugin::ZENDESK_ID_FIELD].present?
return if !SiteSetting.zendesk_job_push_all_posts? && post.post_number > 1
ticket_id = post.topic.custom_fields[DiscourseZendeskPlugin::ZENDESK_ID_FIELD]
if ticket_id.present?
add_comment(post, ticket_id) if comment_eligible_for_sync?(post)
elsif DiscourseZendeskPlugin::Helper.autogeneration_category?(post.topic.category_id)
create_ticket(post)
end
end
end
end