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
Add mysql query for endpoints urls. Fix rubocop warnings.
Sebastian Palmaa4578cd375d0
diff --git a/api/app/models/concerns/spree/webhooks/has_webhooks.rb b/api/app/models/concerns/spree/webhooks/has_webhooks.rbindex 867523d25e..e2c476ec8a 100644--- a/api/app/models/concerns/spree/webhooks/has_webhooks.rb+++ b/api/app/models/concerns/spree/webhooks/has_webhooks.rb@@ -5,15 +5,15 @@ module Spreeincluded doafter_create_commit proc { queue_webhooks_requests!(event_name(:create)) },- unless: proc { migrating? || webhooks_descendant? }+ unless: proc { webhooks_descendant? }after_destroy_commit proc { queue_webhooks_requests!(event_name(:destroy)) },- unless: proc { migrating? || webhooks_descendant? }+ unless: proc { webhooks_descendant? }after_update_commit proc { queue_webhooks_requests!(event_name(:update)) },- unless: proc { migrating? || webhooks_descendant? }+ unless: proc { webhooks_descendant? }def queue_webhooks_requests!(event)unless payload.blank?- Spree::Webhooks::Endpoints::QueueRequests.call(event: event, payload: payload)+ Spree::Webhooks::Endpoints::QueueRequests.call(event: event, payload: payload)endendend@@ -30,7 +30,7 @@ module Spreedef payloadresource_serializer.new(self).serializable_hash- rescue NameError, NoMethodError+ rescue NoMethodError{}end@@ -38,10 +38,6 @@ module Spreedemodulized_class_name = self.class.to_s.demodulize"Spree::Api::V2::Platform::#{demodulized_class_name}Serializer".constantizeend-- def migrating?- ARGV.include?('db:migrate')- endendendenddiff --git a/api/app/services/spree/webhooks/endpoints/make_request.rb b/api/app/services/spree/webhooks/endpoints/make_request.rbindex bdf1fcc291..dcab4e1e7e 100644--- a/api/app/services/spree/webhooks/endpoints/make_request.rb+++ b/api/app/services/spree/webhooks/endpoints/make_request.rb@@ -5,6 +5,7 @@ module Spreeprepend Spree::ServiceModule::Basedef call(url:)+ p urlrun :make_requestend@@ -15,11 +16,11 @@ module Spreedef make_request(url:)uri = URI(url)- if uri.path == "" && uri.host.nil? && uri.port.nil?+ if uri.path == '' && uri.host.nil? && uri.port.nil?failure(false)elserequest = Net::HTTP::Post.new(uri.path, HEADERS)- request.body = {foo: :bar}.to_json+ request.body = { foo: :bar }.to_jsonhttp = Net::HTTP.new(uri.host, uri.port)http.use_ssl = truesuccess(http.request(request))diff --git a/api/app/services/spree/webhooks/endpoints/queue_requests.rb b/api/app/services/spree/webhooks/endpoints/queue_requests.rbindex 271f85f3e8..e95715e26d 100644--- a/api/app/services/spree/webhooks/endpoints/queue_requests.rb+++ b/api/app/services/spree/webhooks/endpoints/queue_requests.rb@@ -3,6 +3,7 @@ module Spreeprepend Spree::ServiceModule::Basedef call(event:, payload:)+ p payloadurls_subscribed_to(event).each do |url|Spree::Webhooks::Endpoints::MakeRequestJob.perform_later(url)end@@ -11,10 +12,19 @@ module Spreeprivatedef urls_subscribed_to(event)- Spree::Webhooks::Endpoint- .where(enabled: true)- .where('subscriptions @> ? OR subscriptions @> ?', ['*'].to_json, [event].to_json)- .pluck(:url)+ Spree::Webhooks::Endpoint.+ where(enabled: true).+ where(subscriptions_where_statement(event)).+ pluck(:url)+ end++ def subscriptions_where_statement(event)+ case ActiveRecord::Base.connection.adapter_name+ when 'Mysql2'+ ["('*' MEMBER OF(subscriptions) OR ? MEMBER OF(subscriptions))", event]+ when 'PostgreSQL'+ ["subscriptions @> '[\"*\"]' OR subscriptions @> ?", [event].to_json]+ endendendend