Merge pull request #11954 from mkllnk/delete-app

Enterprise user can remove Connected Apps
This commit is contained in:
Maikel
2024-01-03 11:17:26 +11:00
committed by GitHub
9 changed files with 87 additions and 43 deletions

View File

@@ -5,4 +5,7 @@
# Here we store keys and links to access the app.
class ConnectedApp < ApplicationRecord
belongs_to :enterprise
scope :connecting, -> { where(data: nil) }
scope :ready, -> { where.not(data: nil) }
end

View File

@@ -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

View File

@@ -7,21 +7,24 @@
%div
- if enterprise.connected_apps.empty?
%button{ data: {reflex: "click->Admin::ConnectedApp#create", enterprise_id: enterprise.id} }
= t ".action"
= t ".enable"
- elsif enterprise.connected_apps.connecting.present?
%button{ disabled: true }
%i.spinner.fa.fa-spin.fa-circle-o-notch
&nbsp;
= t ".loading"
- else
%button{ data: {reflex: "click->Admin::ConnectedApp#destroy", enterprise_id: enterprise.id} }
= t ".disable"
.connected-app__connection
- if enterprise.connected_apps.present?
- if enterprise.connected_apps.ready.present?
.connected-app__note
- link = enterprise.connected_apps[0].data&.fetch("link", false)
- if link
%p= t ".note"
%div
%a{ href: link, target: "_blank", class: "button" }
= t ".link_label"
- else
%p
%i.spinner.fa.fa-spin.fa-circle-o-notch
&nbsp;
= t ".saving_changes"
- link = enterprise.connected_apps[0].data["link"]
%p= t ".note"
%div
%a{ href: link, target: "_blank", class: "button secondary" }
= t ".link_label"
%hr
.connected-app__description

View File

@@ -1,3 +1,7 @@
#connected_apps_panel {
max-width: 615px;
}
.connected-app__head {
display: flex;
justify-content: space-between;

View File

@@ -12,7 +12,7 @@ $base-font-family: "Open Sans", "Helvetica Neue", "Helvetica", Helvetica, Arial,
// Body base colors
$color-body-bg: $white !default;
$color-body-text: $near-black !default;
$color-headers: $dark-blue !default;
$color-headers: $near-black !default;
$color-link: $teal !default;
$color-link-hover: $orient !default;
$color-link-active: $dark-blue !default;

View File

@@ -11,10 +11,6 @@
padding: 15px 0;
margin-top: 25px;
h1 {
color: $near-black;
}
.ofn-drop-down {
border: 0;
background-color: $spree-blue;

View File

@@ -1286,21 +1286,26 @@ en:
connected_apps:
legend: "Connected apps"
title: "Discover Regenerative"
tagline: "Allow website to publish your enterprise information."
action: "Share data"
saving_changes: "Saving changes"
tagline: "Allow Discover Regenerative to publish your enterprise information."
enable: "Allow data sharing"
disable: "Stop sharing"
loading: "Loading"
note: |
In order for this enterprise to be published, you need to include
regenerative details and accept the Terms and Conditions.
link_label: "Update details"
Your Open Food Network account is connected to Discover Regenerative.
Add or update information on your Discover Regenerative listing here.
link_label: "Manage listing"
description_html: |
<p>
Discover Regenerative makes it easier for buyers to discover
regenerative produce for their procurement, showcase producers that
are using regenerative farming practices, support connection
between buyers and producers within a trusted network.
Eligible producers can showcase their regenerative credentials,
farming practices and more through a profile listing.
Simplifying how buyers can find regenerative produce and connect
with producers of interest.
</p>
<p>
<a href="https://about.openfoodnetwork.org.au/regen-produce-portal/"
target="_blank"><b>Learn more about Discover Regenerative</b>
<i class="icon-external-link"></i></a>
</p>
<p><a href="" target="_blank"><b>Visit website</b> <i class="icon-external-link"></i></a></p>
actions:
edit_profile: Settings
properties: Properties

View File

@@ -28,20 +28,26 @@ 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
click_link "Connected apps"
expect(page).to have_content "Discover Regenerative"
click_button "Share data"
expect(page).to_not have_button "Share data"
expect(page).to have_content "Saving changes"
click_button "Allow data sharing"
expect(page).to_not have_button "Allow data sharing"
expect(page).to have_button "Loading", disabled: true
perform_enqueued_jobs(only: ConnectAppJob)
expect(page).to_not have_content "Saving changes"
expect(page).to have_content "include regenerative details"
expect(page).to have_link "Update details"
expect(page).to_not have_button "Loading", disabled: true
expect(page).to have_content "account is connected"
expect(page).to have_link "Manage listing"
click_button "Stop sharing"
expect(page).to have_button "Allow data sharing"
expect(page).to_not have_button "Stop sharing"
expect(page).to_not have_content "account is connected"
expect(page).to_not have_link "Manage listing"
end
end