mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Enable/disable affiliate sales data
This commit is contained in:
@@ -5,8 +5,12 @@ module Admin
|
||||
def create
|
||||
authorize! :admin, enterprise
|
||||
|
||||
app = ConnectedApp.create!(enterprise_id: enterprise.id)
|
||||
app.connect(api_key: spree_current_user.spree_api_key, channel: SessionChannel.for_request(request))
|
||||
attributes = {}
|
||||
attributes[:type] = connected_app_params[:type] if connected_app_params[:type]
|
||||
|
||||
app = ConnectedApp.create!(enterprise_id: enterprise.id, **attributes)
|
||||
app.connect(api_key: spree_current_user.spree_api_key,
|
||||
channel: SessionChannel.for_request(request))
|
||||
|
||||
render_panel
|
||||
end
|
||||
@@ -14,7 +18,7 @@ module Admin
|
||||
def destroy
|
||||
authorize! :admin, enterprise
|
||||
|
||||
app = enterprise.connected_apps.first
|
||||
app = enterprise.connected_apps.find(params.require(:id))
|
||||
app.destroy
|
||||
|
||||
render_panel
|
||||
@@ -29,5 +33,9 @@ module Admin
|
||||
def render_panel
|
||||
redirect_to "#{edit_admin_enterprise_path(enterprise)}#/connected_apps_panel"
|
||||
end
|
||||
|
||||
def connected_app_params
|
||||
params.permit(:type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#
|
||||
module ConnectedApps
|
||||
class AffiliateSalesData < ConnectedApp
|
||||
def connect; end
|
||||
def connect(_opts)
|
||||
update! data: true # not-nil value indicates it is ready
|
||||
end
|
||||
|
||||
def disconnect; end
|
||||
end
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
%p= t ".tagline"
|
||||
%div
|
||||
- if connected_app.nil?
|
||||
= button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id), method: :post, disabled: !managed_by_user?(enterprise)
|
||||
= button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id, type: "ConnectedApps::AffiliateSalesData"), method: :post, disabled: !managed_by_user?(enterprise)
|
||||
-# This is only seen by super-admins:
|
||||
%em= t(".need_to_be_manager") unless managed_by_user?(enterprise)
|
||||
- else
|
||||
= button_to t(".disable"), admin_enterprise_connected_app_path(0, enterprise_id: enterprise.id), method: :delete
|
||||
= button_to t(".disable"), admin_enterprise_connected_app_path(connected_app.id, enterprise_id: enterprise.id), method: :delete
|
||||
%hr
|
||||
.connected-app__description
|
||||
= t ".description_html"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
= t ".loading"
|
||||
- else
|
||||
= button_to t(".disable"), admin_enterprise_connected_app_path(0, enterprise_id: enterprise.id), method: :delete
|
||||
= button_to t(".disable"), admin_enterprise_connected_app_path(connected_app.id, enterprise_id: enterprise.id), method: :delete
|
||||
|
||||
.connected-app__connection
|
||||
- if connected_app&.ready?
|
||||
|
||||
@@ -29,25 +29,25 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
|
||||
end
|
||||
|
||||
describe "Discover Regenerative" do
|
||||
let(:section_heading) { self.class.description }
|
||||
|
||||
it "can be enabled and disabled" do
|
||||
visit edit_admin_enterprise_path(enterprise)
|
||||
|
||||
scroll_to :bottom
|
||||
click_link "Connected apps"
|
||||
|
||||
within section_containing_heading "Discover Regenerative" do
|
||||
within section_containing_heading do
|
||||
click_button "Allow data sharing"
|
||||
end
|
||||
|
||||
# (page is reloaded so we need to evaluate within block again)
|
||||
within section_containing_heading "Discover Regenerative" do
|
||||
within section_containing_heading do
|
||||
expect(page).not_to have_button "Allow data sharing"
|
||||
expect(page).to have_button "Loading", disabled: true
|
||||
|
||||
perform_enqueued_jobs(only: ConnectAppJob)
|
||||
end
|
||||
|
||||
within section_containing_heading "Discover Regenerative" do
|
||||
expect(page).not_to have_button "Loading", disabled: true
|
||||
expect(page).to have_content "account is connected"
|
||||
expect(page).to have_link "Manage listing"
|
||||
@@ -55,7 +55,7 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
|
||||
click_button "Stop sharing"
|
||||
end
|
||||
|
||||
within section_containing_heading "Discover Regenerative" do
|
||||
within section_containing_heading do
|
||||
expect(page).to have_button "Allow data sharing"
|
||||
expect(page).not_to have_button "Stop sharing"
|
||||
expect(page).not_to have_content "account is connected"
|
||||
@@ -68,15 +68,51 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
|
||||
|
||||
visit "#{edit_admin_enterprise_path(enterprise)}#/connected_apps_panel"
|
||||
|
||||
within section_containing_heading "Discover Regenerative" do
|
||||
within section_containing_heading do
|
||||
expect(page).to have_button("Allow data sharing", disabled: true)
|
||||
expect(page).to have_content "Only managers can connect apps."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def section_containing_heading(heading)
|
||||
describe "Affiliate Sales Data" do
|
||||
let(:section_heading) { "INRAE / UFC QUE CHOISIR Research" }
|
||||
|
||||
it "can be enabled and disabled" do
|
||||
visit edit_admin_enterprise_path(enterprise)
|
||||
|
||||
scroll_to :bottom
|
||||
click_link "Connected apps"
|
||||
|
||||
within section_containing_heading do
|
||||
click_button "Allow data sharing"
|
||||
end
|
||||
|
||||
# (page is reloaded so we need to evaluate within block again)
|
||||
within section_containing_heading do
|
||||
expect(page).not_to have_button "Allow data sharing"
|
||||
click_button "Stop sharing"
|
||||
end
|
||||
|
||||
within section_containing_heading do
|
||||
expect(page).to have_button "Allow data sharing"
|
||||
expect(page).not_to have_button "Stop sharing"
|
||||
end
|
||||
end
|
||||
|
||||
it "can't be enabled by non-manager" do
|
||||
login_as create(:admin_user)
|
||||
|
||||
visit "#{edit_admin_enterprise_path(enterprise)}#/connected_apps_panel"
|
||||
|
||||
within section_containing_heading do
|
||||
expect(page).to have_button("Allow data sharing", disabled: true)
|
||||
expect(page).to have_content "Only managers can connect apps."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def section_containing_heading(heading = section_heading)
|
||||
page.find("h3", text: heading).ancestor("section")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user