mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Disconnect Connected App as enterprise user
The app has to provide a webhook URL to be notified when the app is disconnected. Once we have better token management, we would have a unique token per app and could revoke it. But for now it's just a request to disconnect the app.
This commit is contained in:
@@ -3,10 +3,43 @@
|
||||
module Admin
|
||||
class ConnectedAppReflex < ApplicationReflex
|
||||
def create
|
||||
enterprise = Enterprise.find(element.dataset.enterprise_id)
|
||||
authorize! :admin, enterprise
|
||||
|
||||
app = ConnectedApp.create!(enterprise_id: enterprise.id)
|
||||
|
||||
# Avoid race condition by sending before enqueuing job:
|
||||
broadcast_partial
|
||||
|
||||
ConnectAppJob.perform_later(
|
||||
app, current_user.spree_api_key,
|
||||
channel: SessionChannel.for_request(request),
|
||||
)
|
||||
morph :nothing
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :admin, enterprise
|
||||
|
||||
app = enterprise.connected_apps.first
|
||||
app.destroy
|
||||
|
||||
broadcast_partial
|
||||
|
||||
WebhookDeliveryJob.perform_later(
|
||||
app.data["destroy"],
|
||||
"disconnect-app",
|
||||
nil
|
||||
)
|
||||
morph :nothing
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def enterprise
|
||||
@enterprise ||= Enterprise.find(element.dataset.enterprise_id)
|
||||
end
|
||||
|
||||
def broadcast_partial
|
||||
selector = "#edit_enterprise_#{enterprise.id} #connected-app-discover-regen"
|
||||
html = ApplicationController.render(
|
||||
partial: "admin/enterprises/form/connected_apps",
|
||||
@@ -15,12 +48,6 @@ module Admin
|
||||
|
||||
# Avoid race condition by sending before enqueuing job:
|
||||
cable_ready.morph(selector:, html:).broadcast
|
||||
|
||||
ConnectAppJob.perform_later(
|
||||
app, current_user.spree_api_key,
|
||||
channel: SessionChannel.for_request(request),
|
||||
)
|
||||
morph :nothing
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
%div
|
||||
- if enterprise.connected_apps.empty?
|
||||
%button{ data: {reflex: "click->Admin::ConnectedApp#create", enterprise_id: enterprise.id} }
|
||||
= t ".action"
|
||||
= t ".enable"
|
||||
- else
|
||||
%button{ data: {reflex: "click->Admin::ConnectedApp#destroy", enterprise_id: enterprise.id} }
|
||||
= t ".disable"
|
||||
|
||||
.connected-app__connection
|
||||
- if enterprise.connected_apps.present?
|
||||
.connected-app__note
|
||||
|
||||
@@ -1283,7 +1283,8 @@ en:
|
||||
legend: "Connected apps"
|
||||
title: "Discover Regenerative"
|
||||
tagline: "Allow website to publish your enterprise information."
|
||||
action: "Share data"
|
||||
enable: "Share data"
|
||||
disable: "Disconnect"
|
||||
saving_changes: "Saving changes"
|
||||
note: |
|
||||
In order for this enterprise to be published, you need to include
|
||||
|
||||
@@ -28,7 +28,7 @@ describe "Connected Apps", feature: :connected_apps, vcr: true do
|
||||
expect(page).to have_content "CONNECTED APPS"
|
||||
end
|
||||
|
||||
it "can be enabled" do
|
||||
it "can be enabled and disabled" do
|
||||
visit edit_admin_enterprise_path(enterprise)
|
||||
|
||||
scroll_to :bottom
|
||||
@@ -43,5 +43,11 @@ describe "Connected Apps", feature: :connected_apps, vcr: true do
|
||||
expect(page).to_not have_content "Saving changes"
|
||||
expect(page).to have_content "include regenerative details"
|
||||
expect(page).to have_link "Update details"
|
||||
|
||||
click_button "Disconnect"
|
||||
expect(page).to have_button "Share data"
|
||||
expect(page).to_not have_button "Disconnect"
|
||||
expect(page).to_not have_content "include regenerative details"
|
||||
expect(page).to_not have_link "Update details"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user