From fcb540a89fc1b956e01e6eecada6c7ff2a83a6cc Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 18 Dec 2023 15:51:50 +1100 Subject: [PATCH 1/5] Improve readability by limiting text width --- app/webpacker/css/admin/connected_apps.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/webpacker/css/admin/connected_apps.scss b/app/webpacker/css/admin/connected_apps.scss index efcf8d16f3..c2cb2c9421 100644 --- a/app/webpacker/css/admin/connected_apps.scss +++ b/app/webpacker/css/admin/connected_apps.scss @@ -1,3 +1,7 @@ +#connected_apps_panel { + max-width: 615px; +} + .connected-app__head { display: flex; justify-content: space-between; From efee68007ded50e279e854aa8c7b02cc25813909 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 18 Dec 2023 16:02:11 +1100 Subject: [PATCH 2/5] Adjust header colour in new layout --- app/webpacker/css/admin_v3/globals/variables.scss | 2 +- app/webpacker/css/admin_v3/shared/layout.scss | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/webpacker/css/admin_v3/globals/variables.scss b/app/webpacker/css/admin_v3/globals/variables.scss index e41f2a9597..2a6dd0c35f 100644 --- a/app/webpacker/css/admin_v3/globals/variables.scss +++ b/app/webpacker/css/admin_v3/globals/variables.scss @@ -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; diff --git a/app/webpacker/css/admin_v3/shared/layout.scss b/app/webpacker/css/admin_v3/shared/layout.scss index addd363521..794e51f907 100644 --- a/app/webpacker/css/admin_v3/shared/layout.scss +++ b/app/webpacker/css/admin_v3/shared/layout.scss @@ -11,10 +11,6 @@ padding: 15px 0; margin-top: 25px; - h1 { - color: $near-black; - } - .ofn-drop-down { border: 0; background-color: $spree-blue; From b33910d5b4791d1f4ceb99977f7a4e019fa8131c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 20 Dec 2023 14:45:08 +1100 Subject: [PATCH 3/5] 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. --- app/reflexes/admin/connected_app_reflex.rb | 41 +++++++++++++++---- .../form/_connected_apps.html.haml | 6 ++- config/locales/en.yml | 3 +- ...ed.yml => can_be_enabled_and_disabled.yml} | 0 .../admin/enterprises/connected_apps_spec.rb | 8 +++- 5 files changed, 48 insertions(+), 10 deletions(-) rename spec/fixtures/vcr_cassettes/Connected_Apps/{can_be_enabled.yml => can_be_enabled_and_disabled.yml} (100%) diff --git a/app/reflexes/admin/connected_app_reflex.rb b/app/reflexes/admin/connected_app_reflex.rb index 8bfb83d562..ecfb974d96 100644 --- a/app/reflexes/admin/connected_app_reflex.rb +++ b/app/reflexes/admin/connected_app_reflex.rb @@ -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 diff --git a/app/views/admin/enterprises/form/_connected_apps.html.haml b/app/views/admin/enterprises/form/_connected_apps.html.haml index ae816b9999..9559d72bd9 100644 --- a/app/views/admin/enterprises/form/_connected_apps.html.haml +++ b/app/views/admin/enterprises/form/_connected_apps.html.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index b9df0ba1f9..3adaab685c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml b/spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled_and_disabled.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml rename to spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled_and_disabled.yml diff --git a/spec/system/admin/enterprises/connected_apps_spec.rb b/spec/system/admin/enterprises/connected_apps_spec.rb index b10ef466cb..1885d2959b 100644 --- a/spec/system/admin/enterprises/connected_apps_spec.rb +++ b/spec/system/admin/enterprises/connected_apps_spec.rb @@ -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 From 67ffb5526e0a10c25f1a262d277250517688570f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 20 Dec 2023 15:09:35 +1100 Subject: [PATCH 4/5] Display loading status in action button --- app/models/connected_app.rb | 3 +++ .../form/_connected_apps.html.haml | 23 +++++++++---------- config/locales/en.yml | 2 +- .../admin/enterprises/connected_apps_spec.rb | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/models/connected_app.rb b/app/models/connected_app.rb index 0553bbffa2..3edc7c4147 100644 --- a/app/models/connected_app.rb +++ b/app/models/connected_app.rb @@ -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 diff --git a/app/views/admin/enterprises/form/_connected_apps.html.haml b/app/views/admin/enterprises/form/_connected_apps.html.haml index 9559d72bd9..c60a7da1a1 100644 --- a/app/views/admin/enterprises/form/_connected_apps.html.haml +++ b/app/views/admin/enterprises/form/_connected_apps.html.haml @@ -8,24 +8,23 @@ - if enterprise.connected_apps.empty? %button{ data: {reflex: "click->Admin::ConnectedApp#create", enterprise_id: enterprise.id} } = t ".enable" + - elsif enterprise.connected_apps.connecting.present? + %button{ disabled: true } + %i.spinner.fa.fa-spin.fa-circle-o-notch +   + = 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 -   - = 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 3adaab685c..005dc5a09d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1285,7 +1285,7 @@ en: tagline: "Allow website to publish your enterprise information." enable: "Share data" disable: "Disconnect" - saving_changes: "Saving changes" + loading: "Loading" note: | In order for this enterprise to be published, you need to include regenerative details and accept the Terms and Conditions. diff --git a/spec/system/admin/enterprises/connected_apps_spec.rb b/spec/system/admin/enterprises/connected_apps_spec.rb index 1885d2959b..a659a70863 100644 --- a/spec/system/admin/enterprises/connected_apps_spec.rb +++ b/spec/system/admin/enterprises/connected_apps_spec.rb @@ -37,10 +37,10 @@ describe "Connected Apps", feature: :connected_apps, vcr: true do click_button "Share data" expect(page).to_not have_button "Share data" - expect(page).to have_content "Saving changes" + expect(page).to have_button "Loading", disabled: true perform_enqueued_jobs(only: ConnectAppJob) - expect(page).to_not have_content "Saving changes" + expect(page).to_not have_button "Loading", disabled: true expect(page).to have_content "include regenerative details" expect(page).to have_link "Update details" From a9b206f74e1e2b56533d0006a9bdf760de002b84 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 20 Dec 2023 15:18:02 +1100 Subject: [PATCH 5/5] Update Discover Regenerative description --- config/locales/en.yml | 26 +++++++++++-------- .../admin/enterprises/connected_apps_spec.rb | 18 ++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 005dc5a09d..4a1d3d292c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1282,22 +1282,26 @@ en: connected_apps: legend: "Connected apps" title: "Discover Regenerative" - tagline: "Allow website to publish your enterprise information." - enable: "Share data" - disable: "Disconnect" + 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: |

- 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. +

+

+ Learn more about Discover Regenerative +

-

Visit website

actions: edit_profile: Settings properties: Properties diff --git a/spec/system/admin/enterprises/connected_apps_spec.rb b/spec/system/admin/enterprises/connected_apps_spec.rb index a659a70863..2b61f6466f 100644 --- a/spec/system/admin/enterprises/connected_apps_spec.rb +++ b/spec/system/admin/enterprises/connected_apps_spec.rb @@ -35,19 +35,19 @@ describe "Connected Apps", feature: :connected_apps, vcr: true do click_link "Connected apps" expect(page).to have_content "Discover Regenerative" - click_button "Share data" - expect(page).to_not have_button "Share data" + 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_button "Loading", disabled: true - expect(page).to have_content "include regenerative details" - expect(page).to have_link "Update details" + expect(page).to have_content "account is connected" + expect(page).to have_link "Manage listing" - 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" + 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