Skip to content

armgit / spree

Public Imported from GitHub
0

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.

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.rb
index 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 Spree
included do
after_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)
end
end
end
@@ -30,7 +30,7 @@ module Spree
def payload
resource_serializer.new(self).serializable_hash
- rescue NameError, NoMethodError
+ rescue NoMethodError
{}
end
@@ -38,10 +38,6 @@ module Spree
demodulized_class_name = self.class.to_s.demodulize
"Spree::Api::V2::Platform::#{demodulized_class_name}Serializer".constantize
end
-
- def migrating?
- ARGV.include?('db:migrate')
- end
end
end
end
diff --git a/api/app/services/spree/webhooks/endpoints/make_request.rb b/api/app/services/spree/webhooks/endpoints/make_request.rb
index 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 Spree
prepend Spree::ServiceModule::Base
def call(url:)
+ p url
run :make_request
end
@@ -15,11 +16,11 @@ module Spree
def 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)
else
request = Net::HTTP::Post.new(uri.path, HEADERS)
- request.body = {foo: :bar}.to_json
+ request.body = { foo: :bar }.to_json
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
success(http.request(request))
diff --git a/api/app/services/spree/webhooks/endpoints/queue_requests.rb b/api/app/services/spree/webhooks/endpoints/queue_requests.rb
index 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 Spree
prepend Spree::ServiceModule::Base
def call(event:, payload:)
+ p payload
urls_subscribed_to(event).each do |url|
Spree::Webhooks::Endpoints::MakeRequestJob.perform_later(url)
end
@@ -11,10 +12,19 @@ module Spree
private
def 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]
+ end
end
end
end