Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
SD-1544 Do not emit webhooks on touch events (#11539)
Aleksandar Petrushevcf09552d5933
diff --git a/api/app/models/concerns/spree/webhooks/has_webhooks.rb b/api/app/models/concerns/spree/webhooks/has_webhooks.rbindex 7c08f99c79..8beb55903b 100644--- a/api/app/models/concerns/spree/webhooks/has_webhooks.rb+++ b/api/app/models/concerns/spree/webhooks/has_webhooks.rb@@ -9,7 +9,8 @@ module Spreeafter_update_commit(proc { queue_webhooks_requests!(inferred_event_name(:update)) })def queue_webhooks_requests!(event_name)- return if disable_spree_webhooks? || updating_only_timestamps? || body.blank?+ return if disable_spree_webhooks? || body.blank?+ return if default_event?(event_name) && updating_only_timestamps?Spree::Webhooks::Subscribers::QueueRequests.call(body: body, event_name: event_name)end@@ -42,7 +43,11 @@ module Spreeenddef updating_only_timestamps?- saved_changes.present? && (saved_changes.keys - %w[created_at updated_at]).empty?+ (saved_changes.keys - %w[created_at updated_at deleted_at]).empty?+ end++ def default_event?(event_name)+ self.class.default_webhook_events.include?(event_name)enddef disable_spree_webhooks?diff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rbindex 584791ed50..26f5f77bb5 100644--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb@@ -107,11 +107,23 @@ describe Spree::Webhooks::HasWebhooks docontext 'when using touch with an argument other than created_at/updated_at' doit doexpect do- product.touch(:deleted_at)+ product.touch(:available_on)end.to emit_webhook_event(event_name)endendend++ context 'on touch events from callbacks' do+ let!(:store2) { create(:store) }+ let!(:cms_page) { create(:cms_homepage, store: store2, locale: 'en') }+ let(:body) { Spree::Api::V2::Platform::StoreSerializer.new(store2).serializable_hash }++ before { store2.changes_applied }++ it 'does not emit the touched model\'s update event' do+ expect { cms_page.update(title: 'Homepage #1') }.not_to emit_webhook_event('store.update')+ end+ endenddescribe '.default_webhook_events' do