mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Tell data proxy the enterprise to update
This commit is contained in:
@@ -40,7 +40,9 @@ module DfcProvider
|
||||
)
|
||||
end
|
||||
|
||||
ProxyNotifier.new.refresh(key)
|
||||
urls = DfcProvider::Engine.routes.url_helpers
|
||||
enterprise_url = urls.enterprise_url(current_enterprise.id)
|
||||
ProxyNotifier.new.refresh(key, enterprise_url)
|
||||
|
||||
render json: platform(key)
|
||||
end
|
||||
|
||||
@@ -5,9 +5,9 @@ require "private_address_check/tcpsocket_ext"
|
||||
|
||||
# Call a webhook to notify a data proxy about changes in our data.
|
||||
class ProxyNotifier
|
||||
def refresh(platform)
|
||||
def refresh(platform, enterprise_url)
|
||||
PrivateAddressCheck.only_public_connections do
|
||||
notify_proxy(platform)
|
||||
notify_proxy(platform, enterprise_url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,11 +31,11 @@ class ProxyNotifier
|
||||
response.body["access_token"]
|
||||
end
|
||||
|
||||
def notify_proxy(platform)
|
||||
def notify_proxy(platform, enterprise_url)
|
||||
token = request_token(platform)
|
||||
data = {
|
||||
eventType: "refresh",
|
||||
enterpriseUrlid: DfcProvider::Engine.routes.url_helpers.enterprises_url,
|
||||
enterpriseUrlid: enterprise_url,
|
||||
scope: "ReadEnterprise",
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ require_relative "../spec_helper"
|
||||
# OPENID_APP_SECRET="..."
|
||||
RSpec.describe ProxyNotifier do
|
||||
let(:platform) { "cqcm-dev" }
|
||||
let(:enterprise_url) { "http://ofn.example.net/api/dfc/enterprises/10000" }
|
||||
|
||||
it "receives an access token", :vcr do
|
||||
token = subject.request_token(platform)
|
||||
@@ -21,7 +22,7 @@ RSpec.describe ProxyNotifier do
|
||||
# If you don't have valid credentials, you'll get an unauthorized error.
|
||||
# Correctly authenticated, the server fails to update its data.
|
||||
expect {
|
||||
subject.refresh(platform)
|
||||
subject.refresh(platform, enterprise_url)
|
||||
}.to raise_error Faraday::ServerError
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user