From 772f1f8fdea2d2a4612e95fc582a757fba95a787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 13 Nov 2024 20:00:04 +0100 Subject: [PATCH 01/24] Add external_billing_id field on enterprises table --- .../20241113185651_add_external_billing_id_on_enterprises.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20241113185651_add_external_billing_id_on_enterprises.rb diff --git a/db/migrate/20241113185651_add_external_billing_id_on_enterprises.rb b/db/migrate/20241113185651_add_external_billing_id_on_enterprises.rb new file mode 100644 index 00000000000..bd0292bbe3d --- /dev/null +++ b/db/migrate/20241113185651_add_external_billing_id_on_enterprises.rb @@ -0,0 +1,5 @@ +class AddExternalBillingIdOnEnterprises < ActiveRecord::Migration[7.0] + def change + add_column :enterprises, :external_billing_id, :string, limit: 128 + end +end diff --git a/db/schema.rb b/db/schema.rb index be371a9499d..37bab4a1e64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_11_12_230401) do +ActiveRecord::Schema[7.0].define(version: 2024_11_13_185651) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -229,6 +229,7 @@ t.boolean "hide_ofn_navigation", default: false, null: false t.text "white_label_logo_link" t.boolean "hide_groups_tab", default: false + t.string "external_billing_id", limit: 128 t.index ["address_id"], name: "index_enterprises_on_address_id" t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells" t.index ["name"], name: "index_enterprises_on_name", unique: true From 14334b02bf57d373646d4e8ee6a2ed467120504b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 13 Nov 2024 22:23:44 +0100 Subject: [PATCH 02/24] Add new field on enterprise admin form --- app/helpers/admin/enterprises_helper.rb | 1 + .../permitted_attributes/enterprise.rb | 2 +- .../enterprises/form/_admin_only.html.haml | 21 +++++++++++++++++++ .../form/_primary_details.html.haml | 16 -------------- 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 app/views/admin/enterprises/form/_admin_only.html.haml diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 67ed726282f..61bab28edca 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -75,6 +75,7 @@ def build_enterprise_side_menu_items( { name: 'white_label', icon_class: "icon-leaf", show: true }, { name: 'users', icon_class: "icon-user", show: true }, { name: 'connected_apps', icon_class: "icon-puzzle-piece", show: show_connected_apps }, + { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, ] end end diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 234fadac77a..1dd5b5a8385 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -37,7 +37,7 @@ def self.basic_permitted_attributes :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, :hide_ofn_navigation, :white_label_logo, :white_label_logo_link, - :hide_groups_tab + :hide_groups_tab, :external_billing_id, ] end end diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml new file mode 100644 index 00000000000..0d8033bcf12 --- /dev/null +++ b/app/views/admin/enterprises/form/_admin_only.html.haml @@ -0,0 +1,21 @@ +.row + .three.columns.alpha + = f.label :sells, t('.sells') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} + .two.columns + = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.none'), value: "none" + .two.columns + = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.own'), value: "own" + .four.columns.omega + = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.any'), value: "any" + %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } + = render partial: "components/admin_spinner" +.row + .three.columns.alpha + = f.label :external_billing_id, t('.external_billing_id') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} + .four.columns + = f.text_field :external_billing_id, { placeholder: t(:external_billing_id_placeholder) } diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 04609e9b586..27965fb421f 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -18,22 +18,6 @@ .five.columns.omega = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } = f.label :is_primary_producer, t('.producer') -- if spree_current_user.admin? - .row - .three.columns.alpha - = f.label :sells, t('.sells') - = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} - .two.columns - = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.none'), value: "none" - .two.columns - = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.own'), value: "own" - .four.columns.omega - = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.any'), value: "any" - %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } - = render partial: "components/admin_spinner" .row .three.columns.alpha %label= t('.visible_in_search') From 30dfae7e1838f7b4d636256465874a4a49b66a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sat, 16 Nov 2024 17:18:25 +0100 Subject: [PATCH 03/24] Deal with translations --- config/locales/en.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c8fa2dbdcf..fe96d51f55e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1187,6 +1187,16 @@ en: desc_long_placeholder: Tell customers about yourself. This information appears on your public profile. address: legend: "Address" + admin_only: + legend: "Admin Only" + any: Any + none: None + own: Own + sells: Sells + sells_tip: "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" + external_billing_id: External Billing ID + external_billing_id_placeholder: eg. INV-2024-123456 + external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise." business_details: legend: "Business Details" upload: 'upload' @@ -1279,11 +1289,6 @@ en: primary_producer: Primary Producer? primary_producer_tip: Select 'Producer' if you are a primary producer of food. producer: Producer - any: Any - none: None - own: Own - sells: Sells - sells_tip: "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" visible_in_search: Visible in search? visible_in_search_tip: "Shops can be
1. publicly visible, appearing on the OFN map and listings.
2. Hidden on maps and listings but referenced by other shops and linked in their profile.
3. Completely hidden." visible: Public From 6030d7e05b529ea8353669de10cd9810bf58c77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Mon, 25 Nov 2024 23:10:50 +0100 Subject: [PATCH 04/24] Handle the async action for entreprises sells field changes --- app/views/admin/enterprises/_form.html.haml | 7 ++++- .../enterprises/form/_admin_only.html.haml | 11 ++++--- .../form/_primary_details.html.haml | 2 -- .../controllers/admin_only_controller.js | 30 +++++++++++++++++++ .../controllers/primary_details_controller.js | 12 ++------ 5 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 app/webpacker/controllers/admin_only_controller.js diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 71a9b2378b3..0284abb32b2 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -1,7 +1,12 @@ - enterprise_side_menu_items(@enterprise).each do |item| - case item[:name] - when 'primary_details' - %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "primary-details-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel default" }} + %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "tabs-and-panels-target": "panel default" }} + %legend= t(".#{ item[:name] }.legend") + = render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f + + - when 'admin_only' + %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "admin-only", "admin-only-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel admin-only" }} %legend= t(".#{ item[:name] }.legend") = render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml index 0d8033bcf12..646aac8951e 100644 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ b/app/views/admin/enterprises/form/_admin_only.html.haml @@ -3,16 +3,19 @@ = f.label :sells, t('.sells') = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} .two.columns - = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged"} = f.label :sells, t('.none'), value: "none" .two.columns - = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" } = f.label :sells, t('.own'), value: "own" .four.columns.omega - = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" } = f.label :sells, t('.any'), value: "any" - %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } + %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "admin-only-target": "spinner" } } = render partial: "components/admin_spinner" + += render partial: 'admin/enterprises/form/permalink' + .row .three.columns.alpha = f.label :external_billing_id, t('.external_billing_id') diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 27965fb421f..297263f2639 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -31,5 +31,3 @@ .four.columns.omega = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' - -= render partial: 'admin/enterprises/form/permalink' diff --git a/app/webpacker/controllers/admin_only_controller.js b/app/webpacker/controllers/admin_only_controller.js new file mode 100644 index 00000000000..beb5eae2e4a --- /dev/null +++ b/app/webpacker/controllers/admin_only_controller.js @@ -0,0 +1,30 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + static values = { enterpriseSells: String }; + static targets = ["spinner"]; + + enterpriseSellsChanged(event) { + console.log("enterpriseSellsChanged"); + if (event.currentTarget.checked) { + this.enterpriseSellsValue = event.currentTarget.value; + this.spinnerTarget.classList.remove("hidden"); + this.makeRequest(); + } + } + + makeRequest() { + fetch( + `?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}`, + { + method: "GET", + headers: { "Content-type": "application/json; charset=UTF-8" }, + } + ) + .then((data) => data.json()) + .then((operation) => { + CableReady.perform(operation); + this.spinnerTarget.classList.add("hidden"); + }); + } +} diff --git a/app/webpacker/controllers/primary_details_controller.js b/app/webpacker/controllers/primary_details_controller.js index b4e72be4cf6..59443d2669e 100644 --- a/app/webpacker/controllers/primary_details_controller.js +++ b/app/webpacker/controllers/primary_details_controller.js @@ -1,7 +1,7 @@ import { Controller } from "stimulus"; export default class extends Controller { - static values = { primaryProducer: String, enterpriseSells: String }; + static values = { primaryProducer: String }; static targets = ["spinner"]; primaryProducerChanged(event) { @@ -9,17 +9,9 @@ export default class extends Controller { this.makeRequest(); } - enterpriseSellsChanged(event) { - if (event.currentTarget.checked) { - this.enterpriseSellsValue = event.currentTarget.value; - this.spinnerTarget.classList.remove("hidden"); - this.makeRequest(); - } - } - makeRequest() { fetch( - `?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}&is_primary_producer=${this.primaryProducerValue}`, + `?stimulus=true&is_primary_producer=${this.primaryProducerValue}`, { method: "GET", headers: { "Content-type": "application/json; charset=UTF-8" }, From 57c237c72d613700ee595a000baffc68f774e05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Mon, 25 Nov 2024 23:59:00 +0100 Subject: [PATCH 05/24] Move admin_only tab upper --- app/helpers/admin/enterprises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 61bab28edca..db7d78d5d54 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -56,6 +56,7 @@ def build_enterprise_side_menu_items( ) [ { name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' }, + { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, { name: 'address', icon_class: "icon-map-marker", show: true }, { name: 'contact', icon_class: "icon-phone", show: true }, { name: 'social', icon_class: "icon-twitter", show: true }, @@ -75,7 +76,6 @@ def build_enterprise_side_menu_items( { name: 'white_label', icon_class: "icon-leaf", show: true }, { name: 'users', icon_class: "icon-user", show: true }, { name: 'connected_apps', icon_class: "icon-puzzle-piece", show: show_connected_apps }, - { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, ] end end From e37881837b2e2f731c4ab0ec4cbd7bd5650092e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Tue, 26 Nov 2024 00:15:45 +0100 Subject: [PATCH 06/24] Add unit tests for admin entreprises changes --- spec/controllers/admin/enterprises_controller_spec.rb | 10 ++++++++++ spec/helpers/admin/enterprises_helper_spec.rb | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 4caf3e38d79..415f75cc2a5 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -409,6 +409,16 @@ distributor.reload expect(distributor.users).to include user end + + it "allows 'external_billing_id' to be changed" do + allow(controller).to receive_messages spree_current_user: admin_user + enterprise_params = + { id: profile_enterprise, enterprise: { external_billing_id: 'INV123456' } } + + spree_put :update, enterprise_params + profile_enterprise.reload + expect(profile_enterprise.external_billing_id).to eq 'INV123456' + end end context "geocoding" do diff --git a/spec/helpers/admin/enterprises_helper_spec.rb b/spec/helpers/admin/enterprises_helper_spec.rb index aae01ab5ea0..36bd1b50852 100644 --- a/spec/helpers/admin/enterprises_helper_spec.rb +++ b/spec/helpers/admin/enterprises_helper_spec.rb @@ -33,5 +33,13 @@ user.enterprises << enterprise expect(visible_items.pluck(:name)).to include "connected_apps" end + + context 'when user is an admin' do + let(:user) { create(:admin_user) } + + it "includes admin-only item" do + expect(visible_items.pluck(:name)).to include "admin_only" + end + end end end From 6ae3c8b1027e9f61549535f460c4f4da0599d7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 28 Nov 2024 22:01:35 +0100 Subject: [PATCH 07/24] Add external_billing_id field on revenues_by_hub report --- .../api/admin/enterprise_serializer.rb | 2 +- config/locales/en.yml | 1 + lib/reporting/reports/revenues_by_hub/base.rb | 1 + .../api/v0/enterprises_controller_spec.rb | 25 +++++++++++++++++++ .../api/admin/enterprise_serializer_spec.rb | 9 +++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index f189e57fd01..7c29b41e708 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -15,7 +15,7 @@ class EnterpriseSerializer < ActiveModel::Serializer :terms_and_conditions_file_name, :terms_and_conditions_updated_at, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, :visible, :hide_ofn_navigation, :white_label_logo, - :white_label_logo_link + :white_label_logo_link, :external_billing_id has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer diff --git a/config/locales/en.yml b/config/locales/en.yml index fe96d51f55e..8234c520680 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3198,6 +3198,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_hub_code: Hub Code report_header_hub_id: Hub ID report_header_hub_business_number: "Hub Business Number" + report_header_hub_external_billing_id: "Hub External Billing Id" report_header_hub_legal_name: "Hub Legal Name" report_header_hub_contact_name: "Hub Contact Name" report_header_hub_email: "Hub Public Email" diff --git a/lib/reporting/reports/revenues_by_hub/base.rb b/lib/reporting/reports/revenues_by_hub/base.rb index e539c77fed2..8b10386a6f2 100644 --- a/lib/reporting/reports/revenues_by_hub/base.rb +++ b/lib/reporting/reports/revenues_by_hub/base.rb @@ -24,6 +24,7 @@ def columns # rubocop:disable Metrics/AbcSize hub: proc { |orders| distributor(orders).name }, hub_id: proc { |orders| distributor(orders).id }, hub_business_number: proc { |orders| distributor(orders).abn }, + hub_external_billing_id: proc { |orders| distributor(orders).external_billing_id }, hub_legal_name: proc { |orders| distributor(orders).business_address&.company }, hub_contact_name: proc { |orders| distributor(orders).contact_name }, hub_email: proc { |orders| distributor(orders).email_address }, diff --git a/spec/controllers/api/v0/enterprises_controller_spec.rb b/spec/controllers/api/v0/enterprises_controller_spec.rb index d0529f3eeba..8a74176ff07 100644 --- a/spec/controllers/api/v0/enterprises_controller_spec.rb +++ b/spec/controllers/api/v0/enterprises_controller_spec.rb @@ -7,6 +7,31 @@ let(:enterprise) { create(:distributor_enterprise) } + context "as an admin user" do + let(:admin) { create(:user) } + let!(:enterprise) { create(:distributor_enterprise) } + + before do + allow(controller).to receive(:spree_current_user) { admin } + end + + describe "updating an enterprise" do + let(:enterprise_params) do + { + enterprise_id: enterprise.id, + enterprise: { external_billing_id: 'INV123456' } + } + end + + it "creates a visible=hidden enterprise" do + api_post :create, enterprise_params + expect(response.status).to eq 200 + + expect(enterprise.reload.external_billing_id).to eq('INV123456') + end + end + end + context "as an enterprise owner" do let(:enterprise_owner) { create(:user) } let!(:enterprise) { create(:distributor_enterprise, owner: enterprise_owner) } diff --git a/spec/serializers/api/admin/enterprise_serializer_spec.rb b/spec/serializers/api/admin/enterprise_serializer_spec.rb index 3f20145771f..df2a86f8027 100644 --- a/spec/serializers/api/admin/enterprise_serializer_spec.rb +++ b/spec/serializers/api/admin/enterprise_serializer_spec.rb @@ -73,4 +73,13 @@ end end end + + context "when there is a external billing id" do + let(:enterprise) { create(:distributor_enterprise, external_billing_id: 'INV123456') } + + it "includes URLs of image versions" do + serializer = Api::Admin::EnterpriseSerializer.new(enterprise) + expect(serializer.as_json[:external_billing_id]).to eq('INV123456') + end + end end From 657df9eb8f35d1bbbac1a94ac5e19b93b08f1e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 28 Nov 2024 22:23:28 +0100 Subject: [PATCH 08/24] Repair field placeholder translation --- app/views/admin/enterprises/form/_admin_only.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml index 646aac8951e..275e106c09d 100644 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ b/app/views/admin/enterprises/form/_admin_only.html.haml @@ -21,4 +21,4 @@ = f.label :external_billing_id, t('.external_billing_id') = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} .four.columns - = f.text_field :external_billing_id, { placeholder: t(:external_billing_id_placeholder) } + = f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') } From 3c7c02da2f59cdfbd069ac4ff7b90edd59752eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 28 Nov 2024 23:18:10 +0100 Subject: [PATCH 09/24] Repair specs --- app/views/admin/enterprises/_new_form.html.haml | 10 +++++----- config/locales/en.yml | 1 + spec/controllers/api/v0/enterprises_controller_spec.rb | 9 ++++----- spec/system/admin/enterprises_spec.rb | 4 ++++ spec/system/admin/reports/revenues_by_hub_spec.rb | 4 ++++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index 6964c190323..a1d12ac4924 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -28,21 +28,21 @@ .row .alpha.eleven.columns .three.columns.alpha - = f.label :sells, t('primary_details.sells', scope: scope) - %div{'ofn-with-tip' => t('primary_details.sells_tip', scope: scope)} + = f.label :sells, t('admin_only.sells', scope: scope) + %div{'ofn-with-tip' => t('admin_only.sells_tip', scope: scope)} %a What's this? .two.columns = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('primary_details.none', scope: scope), value: "none" + = f.label :sells, t('admin_only.none', scope: scope), value: "none" .two.columns = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('primary_details.own', scope: scope), value: "own" + = f.label :sells, t('admin_only.own', scope: scope), value: "own" .four.columns.omega = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('primary_details.any', scope: scope), value: "any" + = f.label :sells, t('admin_only.any', scope: scope), value: "any" .row .alpha.three.columns diff --git a/config/locales/en.yml b/config/locales/en.yml index 8234c520680..6db44cbe9e1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1712,6 +1712,7 @@ en: enterprise: primary_details: "Primary Details" address: "Address" + admin_only: "Admin Only" contact: "Contact" social: "Social" about: "About" diff --git a/spec/controllers/api/v0/enterprises_controller_spec.rb b/spec/controllers/api/v0/enterprises_controller_spec.rb index 8a74176ff07..55fd6a2a158 100644 --- a/spec/controllers/api/v0/enterprises_controller_spec.rb +++ b/spec/controllers/api/v0/enterprises_controller_spec.rb @@ -8,7 +8,7 @@ let(:enterprise) { create(:distributor_enterprise) } context "as an admin user" do - let(:admin) { create(:user) } + let(:admin) { create(:admin_user) } let!(:enterprise) { create(:distributor_enterprise) } before do @@ -18,13 +18,12 @@ describe "updating an enterprise" do let(:enterprise_params) do { - enterprise_id: enterprise.id, - enterprise: { external_billing_id: 'INV123456' } + external_billing_id: 'INV123456' } end - it "creates a visible=hidden enterprise" do - api_post :create, enterprise_params + it "changes the external_billing_id field" do + api_put :update, id: enterprise.id, enterprise: enterprise_params expect(response.status).to eq 200 expect(enterprise.reload.external_billing_id).to eq('INV123456') diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 86d007a46b5..2cd8b23e883 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -86,6 +86,10 @@ end fill_in 'enterprise_name', with: 'Eaterprises' + + accept_alert do + click_link "Admin Only" + end fill_in 'enterprise_permalink', with: 'eaterprises-permalink' expect(page).to have_selector '.available' choose 'Own' diff --git a/spec/system/admin/reports/revenues_by_hub_spec.rb b/spec/system/admin/reports/revenues_by_hub_spec.rb index 079a94d2fa2..5e85340aa32 100644 --- a/spec/system/admin/reports/revenues_by_hub_spec.rb +++ b/spec/system/admin/reports/revenues_by_hub_spec.rb @@ -64,6 +64,7 @@ "Hub", "Hub ID", "Hub Business Number", + "Hub External Billing Id", "Hub Legal Name", "Hub Contact Name", "Hub Public Email", @@ -89,6 +90,7 @@ "none", "none", "none", + "none", "email@email.com", "none", "10 Lovely Street", @@ -110,6 +112,7 @@ "none", "none", "none", + "none", "email@email.com", "none", "10 Lovely Street", @@ -131,6 +134,7 @@ "none", "none", "none", + "none", "email@email.com", "none", "10 Lovely Street", From 9dc364979a45805ad24c5d927e6033d3956c9388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 22 Dec 2024 12:37:58 +0100 Subject: [PATCH 10/24] Put back permalink fields on primary details panel --- app/views/admin/enterprises/form/_admin_only.html.haml | 2 -- app/views/admin/enterprises/form/_primary_details.html.haml | 2 ++ app/webpacker/controllers/admin_only_controller.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml index 275e106c09d..e95e4615224 100644 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ b/app/views/admin/enterprises/form/_admin_only.html.haml @@ -14,8 +14,6 @@ %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "admin-only-target": "spinner" } } = render partial: "components/admin_spinner" -= render partial: 'admin/enterprises/form/permalink' - .row .three.columns.alpha = f.label :external_billing_id, t('.external_billing_id') diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 297263f2639..830cd108b4d 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -31,3 +31,5 @@ .four.columns.omega = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' + += render partial: 'admin/enterprises/form/permalink' \ No newline at end of file diff --git a/app/webpacker/controllers/admin_only_controller.js b/app/webpacker/controllers/admin_only_controller.js index beb5eae2e4a..3b1a8e86c02 100644 --- a/app/webpacker/controllers/admin_only_controller.js +++ b/app/webpacker/controllers/admin_only_controller.js @@ -5,7 +5,6 @@ export default class extends Controller { static targets = ["spinner"]; enterpriseSellsChanged(event) { - console.log("enterpriseSellsChanged"); if (event.currentTarget.checked) { this.enterpriseSellsValue = event.currentTarget.value; this.spinnerTarget.classList.remove("hidden"); From d6faa23fc25a32575fe2b77a0041c9d3f9771f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 22 Dec 2024 12:58:12 +0100 Subject: [PATCH 11/24] Fix spec --- .../enterprises/form/_permalink.html.haml | 2 -- .../form/_primary_details.html.haml | 2 +- spec/system/admin/enterprises_spec.rb | 20 ++++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/admin/enterprises/form/_permalink.html.haml b/app/views/admin/enterprises/form/_permalink.html.haml index 5c2a43a7b03..87c138286a5 100644 --- a/app/views/admin/enterprises/form/_permalink.html.haml +++ b/app/views/admin/enterprises/form/_permalink.html.haml @@ -15,8 +15,6 @@ %span.unavailable.hidden{data: { "permalink-target": "unavailable" }} = t('js.unavailable') %i.icon-remove-sign - - - unless @enterprise.sells == 'none' .row .three.columns.alpha %label= t('.link_to_front') diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 830cd108b4d..27965fb421f 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -32,4 +32,4 @@ = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' -= render partial: 'admin/enterprises/form/permalink' \ No newline at end of file += render partial: 'admin/enterprises/form/permalink' diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 2cd8b23e883..995b15ae0c1 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -87,12 +87,12 @@ fill_in 'enterprise_name', with: 'Eaterprises' - accept_alert do - click_link "Admin Only" - end + accept_alert { click_link "Admin Only" } + choose 'Own' + + accept_alert { click_link "Primary Details" } fill_in 'enterprise_permalink', with: 'eaterprises-permalink' expect(page).to have_selector '.available' - choose 'Own' # Require login to view shopfront or for checkout accept_alert do @@ -119,34 +119,36 @@ fill_in_trix_editor 'enterprise_long_description', with: 'This is an interesting long description' - # Check StimulusJs switching of sidebar elements - accept_alert do - click_link "Primary Details" - end - # Unchecking hides the Properties tab + accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' + accept_alert { click_link "Admin Only" } choose 'None' expect(page).not_to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).not_to have_selector "[data-test=link_for_properties]" # Checking displays the Properties tab + accept_alert { click_link "Primary Details" } check 'enterprise_is_primary_producer' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).to have_selector "[data-test=link_for_properties]" + accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' + accept_alert { click_link "Admin Only" } choose 'Own' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" + accept_alert { click_link "Admin Only" } choose 'Any' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" + accept_alert { click_link "Primary Details" } page.find("#enterprise_group_ids-ts-control").set(eg1.name) page.find("#enterprise_group_ids-ts-dropdown .option.active").click From cd38e02cacf4571079b1ef7456e782e2ca9bc5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Mon, 23 Dec 2024 08:02:58 +0100 Subject: [PATCH 12/24] Add spinner --- app/helpers/admin/enterprises_helper.rb | 7 +++++-- .../admin/enterprises/form/_primary_details.html.haml | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index db7d78d5d54..327dd5abcc6 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -28,6 +28,7 @@ def enterprise_side_menu_items(enterprise) show_connected_apps = can?(:manage_connected_apps, enterprise) && feature?(:connected_apps, spree_current_user, enterprise) && Spree::Config.connected_apps_enabled.present? + show_admin_only = spree_current_user.admin? build_enterprise_side_menu_items( is_shop:, @@ -36,6 +37,7 @@ def enterprise_side_menu_items(enterprise) show_payment_methods:, show_enterprise_fees:, show_connected_apps:, + show_admin_only:, ) end @@ -52,11 +54,12 @@ def build_enterprise_side_menu_items( show_shipping_methods:, show_payment_methods:, show_enterprise_fees:, - show_connected_apps: + show_connected_apps:, + show_admin_only: ) [ { name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' }, - { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, + { name: 'admin_only', icon_class: "icon-gear", show: show_admin_only }, { name: 'address', icon_class: "icon-map-marker", show: true }, { name: 'contact', icon_class: "icon-phone", show: true }, { name: 'social', icon_class: "icon-twitter", show: true }, diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 27965fb421f..7ba7a48eabb 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -18,6 +18,8 @@ .five.columns.omega = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } = f.label :is_primary_producer, t('.producer') + %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } + = render partial: "components/admin_spinner" .row .three.columns.alpha %label= t('.visible_in_search') From 0f77d1bad50e1f6504401ade9a509fbce0345095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 26 Dec 2024 17:06:32 +0100 Subject: [PATCH 13/24] Use params value only if present --- app/controllers/admin/enterprises_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index e5b35473acd..141c02272a6 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -49,8 +49,11 @@ def edit @object.build_custom_tab if @object.custom_tab.nil? return unless params[:stimulus] - @enterprise.is_primary_producer = params[:is_primary_producer] - @enterprise.sells = params[:enterprise_sells] + if params[:is_primary_producer].present? + @enterprise.is_primary_producer = params[:is_primary_producer] + end + @enterprise.sells = params[:enterprise_sells] if params[:enterprise_sells].present? + render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu")) .morph("#permalink", partial("admin/enterprises/form/permalink")) end From 0b0b6a04e153e4c0ae95fe48adb1adf07e465564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 26 Dec 2024 18:28:35 +0100 Subject: [PATCH 14/24] Do explicit save in specs when switching tabs --- spec/system/admin/enterprises_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 995b15ae0c1..1530378cf95 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -122,38 +122,38 @@ # Unchecking hides the Properties tab accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - accept_alert { click_link "Admin Only" } + click_button 'Update' + click_link "Admin Only" choose 'None' expect(page).not_to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).not_to have_selector "[data-test=link_for_properties]" + click_button 'Update' # Checking displays the Properties tab - accept_alert { click_link "Primary Details" } check 'enterprise_is_primary_producer' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).to have_selector "[data-test=link_for_properties]" - accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - accept_alert { click_link "Admin Only" } + click_button 'Update' + click_link "Admin Only" choose 'Own' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" - accept_alert { click_link "Admin Only" } choose 'Any' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" + click_button 'Update' - accept_alert { click_link "Primary Details" } page.find("#enterprise_group_ids-ts-control").set(eg1.name) page.find("#enterprise_group_ids-ts-dropdown .option.active").click within(".permalink") do - link_path = "#{main_app.root_url}#{@enterprise.permalink}/shop" + link_path = "#{main_app.root_url}#{@enterprise.reload.permalink}/shop" link = find_link(link_path) expect(link[:href]).to eq link_path expect(link[:target]).to eq '_blank' From f9f5d0eb5193ad755ecadf189e51deb93d6d9c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:08:07 +0100 Subject: [PATCH 15/24] Revert "Do explicit save in specs when switching tabs" This reverts commit 3230159dceeb1485b0c6ec2422ea282b39431e0c. --- spec/system/admin/enterprises_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 1530378cf95..995b15ae0c1 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -122,38 +122,38 @@ # Unchecking hides the Properties tab accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - click_button 'Update' - click_link "Admin Only" + accept_alert { click_link "Admin Only" } choose 'None' expect(page).not_to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).not_to have_selector "[data-test=link_for_properties]" - click_button 'Update' # Checking displays the Properties tab + accept_alert { click_link "Primary Details" } check 'enterprise_is_primary_producer' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).to have_selector "[data-test=link_for_properties]" + accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - click_button 'Update' - click_link "Admin Only" + accept_alert { click_link "Admin Only" } choose 'Own' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" + accept_alert { click_link "Admin Only" } choose 'Any' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" - click_button 'Update' + accept_alert { click_link "Primary Details" } page.find("#enterprise_group_ids-ts-control").set(eg1.name) page.find("#enterprise_group_ids-ts-dropdown .option.active").click within(".permalink") do - link_path = "#{main_app.root_url}#{@enterprise.reload.permalink}/shop" + link_path = "#{main_app.root_url}#{@enterprise.permalink}/shop" link = find_link(link_path) expect(link[:href]).to eq link_path expect(link[:target]).to eq '_blank' From 9cd3bbf46f03714318ba1acdbe997e21674cb729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:08:10 +0100 Subject: [PATCH 16/24] Revert "Use params value only if present" This reverts commit 5cd50b1c1ff66398f470d51fdafacf26663a2730. --- app/controllers/admin/enterprises_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 141c02272a6..e5b35473acd 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -49,11 +49,8 @@ def edit @object.build_custom_tab if @object.custom_tab.nil? return unless params[:stimulus] - if params[:is_primary_producer].present? - @enterprise.is_primary_producer = params[:is_primary_producer] - end - @enterprise.sells = params[:enterprise_sells] if params[:enterprise_sells].present? - + @enterprise.is_primary_producer = params[:is_primary_producer] + @enterprise.sells = params[:enterprise_sells] render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu")) .morph("#permalink", partial("admin/enterprises/form/permalink")) end From 1e3f86625f02a7d67fcd37acee269d56ad080783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:08:12 +0100 Subject: [PATCH 17/24] Revert "Add spinner" This reverts commit 16506c44fa8aee0a588c01a253b78b023a8f3a39. --- app/helpers/admin/enterprises_helper.rb | 7 ++----- .../admin/enterprises/form/_primary_details.html.haml | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 327dd5abcc6..db7d78d5d54 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -28,7 +28,6 @@ def enterprise_side_menu_items(enterprise) show_connected_apps = can?(:manage_connected_apps, enterprise) && feature?(:connected_apps, spree_current_user, enterprise) && Spree::Config.connected_apps_enabled.present? - show_admin_only = spree_current_user.admin? build_enterprise_side_menu_items( is_shop:, @@ -37,7 +36,6 @@ def enterprise_side_menu_items(enterprise) show_payment_methods:, show_enterprise_fees:, show_connected_apps:, - show_admin_only:, ) end @@ -54,12 +52,11 @@ def build_enterprise_side_menu_items( show_shipping_methods:, show_payment_methods:, show_enterprise_fees:, - show_connected_apps:, - show_admin_only: + show_connected_apps: ) [ { name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' }, - { name: 'admin_only', icon_class: "icon-gear", show: show_admin_only }, + { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, { name: 'address', icon_class: "icon-map-marker", show: true }, { name: 'contact', icon_class: "icon-phone", show: true }, { name: 'social', icon_class: "icon-twitter", show: true }, diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 7ba7a48eabb..27965fb421f 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -18,8 +18,6 @@ .five.columns.omega = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } = f.label :is_primary_producer, t('.producer') - %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } - = render partial: "components/admin_spinner" .row .three.columns.alpha %label= t('.visible_in_search') From 983e3e717b26415dcc5d9a1dd4c3bc49e566715d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:08:14 +0100 Subject: [PATCH 18/24] Revert "Fix spec" This reverts commit b40e8a1ff9072721c468a7c012e1e4a9d47e3957. --- .../enterprises/form/_permalink.html.haml | 2 ++ .../form/_primary_details.html.haml | 2 +- spec/system/admin/enterprises_spec.rb | 20 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/admin/enterprises/form/_permalink.html.haml b/app/views/admin/enterprises/form/_permalink.html.haml index 87c138286a5..5c2a43a7b03 100644 --- a/app/views/admin/enterprises/form/_permalink.html.haml +++ b/app/views/admin/enterprises/form/_permalink.html.haml @@ -15,6 +15,8 @@ %span.unavailable.hidden{data: { "permalink-target": "unavailable" }} = t('js.unavailable') %i.icon-remove-sign + + - unless @enterprise.sells == 'none' .row .three.columns.alpha %label= t('.link_to_front') diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 27965fb421f..830cd108b4d 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -32,4 +32,4 @@ = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' -= render partial: 'admin/enterprises/form/permalink' += render partial: 'admin/enterprises/form/permalink' \ No newline at end of file diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 995b15ae0c1..2cd8b23e883 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -87,12 +87,12 @@ fill_in 'enterprise_name', with: 'Eaterprises' - accept_alert { click_link "Admin Only" } - choose 'Own' - - accept_alert { click_link "Primary Details" } + accept_alert do + click_link "Admin Only" + end fill_in 'enterprise_permalink', with: 'eaterprises-permalink' expect(page).to have_selector '.available' + choose 'Own' # Require login to view shopfront or for checkout accept_alert do @@ -119,36 +119,34 @@ fill_in_trix_editor 'enterprise_long_description', with: 'This is an interesting long description' + # Check StimulusJs switching of sidebar elements + accept_alert do + click_link "Primary Details" + end + # Unchecking hides the Properties tab - accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - accept_alert { click_link "Admin Only" } choose 'None' expect(page).not_to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).not_to have_selector "[data-test=link_for_properties]" # Checking displays the Properties tab - accept_alert { click_link "Primary Details" } check 'enterprise_is_primary_producer' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).not_to have_selector "[data-test=link_for_payment_methods]" expect(page).not_to have_selector "[data-test=link_for_shipping_methods]" expect(page).to have_selector "[data-test=link_for_properties]" - accept_alert { click_link "Primary Details" } uncheck 'enterprise_is_primary_producer' - accept_alert { click_link "Admin Only" } choose 'Own' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" - accept_alert { click_link "Admin Only" } choose 'Any' expect(page).to have_selector "[data-test=link_for_enterprise_fees]" expect(page).to have_selector "[data-test=link_for_payment_methods]" expect(page).to have_selector "[data-test=link_for_shipping_methods]" - accept_alert { click_link "Primary Details" } page.find("#enterprise_group_ids-ts-control").set(eg1.name) page.find("#enterprise_group_ids-ts-dropdown .option.active").click From a007fdaab815ff4cad6b99026feac679446b808f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:08:16 +0100 Subject: [PATCH 19/24] Revert "Put back permalink fields on primary details panel" This reverts commit d90ca538fb5b02e942842f1f9c1f44232f44027d. --- app/views/admin/enterprises/form/_admin_only.html.haml | 2 ++ app/views/admin/enterprises/form/_primary_details.html.haml | 2 -- app/webpacker/controllers/admin_only_controller.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml index e95e4615224..275e106c09d 100644 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ b/app/views/admin/enterprises/form/_admin_only.html.haml @@ -14,6 +14,8 @@ %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "admin-only-target": "spinner" } } = render partial: "components/admin_spinner" += render partial: 'admin/enterprises/form/permalink' + .row .three.columns.alpha = f.label :external_billing_id, t('.external_billing_id') diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 830cd108b4d..297263f2639 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -31,5 +31,3 @@ .four.columns.omega = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' - -= render partial: 'admin/enterprises/form/permalink' \ No newline at end of file diff --git a/app/webpacker/controllers/admin_only_controller.js b/app/webpacker/controllers/admin_only_controller.js index 3b1a8e86c02..beb5eae2e4a 100644 --- a/app/webpacker/controllers/admin_only_controller.js +++ b/app/webpacker/controllers/admin_only_controller.js @@ -5,6 +5,7 @@ export default class extends Controller { static targets = ["spinner"]; enterpriseSellsChanged(event) { + console.log("enterpriseSellsChanged"); if (event.currentTarget.checked) { this.enterpriseSellsValue = event.currentTarget.value; this.spinnerTarget.classList.remove("hidden"); From 3ef5b412822bf19e36264af46314ea57252ed9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 5 Jan 2025 20:33:18 +0100 Subject: [PATCH 20/24] Remove Admin Only tab logic --- app/helpers/admin/enterprises_helper.rb | 1 - app/views/admin/enterprises/_form.html.haml | 7 +---- .../admin/enterprises/_new_form.html.haml | 10 +++---- .../enterprises/form/_admin_only.html.haml | 24 --------------- .../form/_primary_details.html.haml | 24 +++++++++++++++ .../controllers/admin_only_controller.js | 30 ------------------- .../controllers/primary_details_controller.js | 12 ++++++-- config/locales/en.yml | 19 +++++------- spec/helpers/admin/enterprises_helper_spec.rb | 8 ----- spec/system/admin/enterprises_spec.rb | 4 --- 10 files changed, 48 insertions(+), 91 deletions(-) delete mode 100644 app/views/admin/enterprises/form/_admin_only.html.haml delete mode 100644 app/webpacker/controllers/admin_only_controller.js diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index db7d78d5d54..67ed726282f 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -56,7 +56,6 @@ def build_enterprise_side_menu_items( ) [ { name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' }, - { name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? }, { name: 'address', icon_class: "icon-map-marker", show: true }, { name: 'contact', icon_class: "icon-phone", show: true }, { name: 'social', icon_class: "icon-twitter", show: true }, diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 0284abb32b2..71a9b2378b3 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -1,12 +1,7 @@ - enterprise_side_menu_items(@enterprise).each do |item| - case item[:name] - when 'primary_details' - %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "tabs-and-panels-target": "panel default" }} - %legend= t(".#{ item[:name] }.legend") - = render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f - - - when 'admin_only' - %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "admin-only", "admin-only-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel admin-only" }} + %fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "primary-details-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel default" }} %legend= t(".#{ item[:name] }.legend") = render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index a1d12ac4924..6964c190323 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -28,21 +28,21 @@ .row .alpha.eleven.columns .three.columns.alpha - = f.label :sells, t('admin_only.sells', scope: scope) - %div{'ofn-with-tip' => t('admin_only.sells_tip', scope: scope)} + = f.label :sells, t('primary_details.sells', scope: scope) + %div{'ofn-with-tip' => t('primary_details.sells_tip', scope: scope)} %a What's this? .two.columns = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('admin_only.none', scope: scope), value: "none" + = f.label :sells, t('primary_details.none', scope: scope), value: "none" .two.columns = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('admin_only.own', scope: scope), value: "own" + = f.label :sells, t('primary_details.own', scope: scope), value: "own" .four.columns.omega = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells'   - = f.label :sells, t('admin_only.any', scope: scope), value: "any" + = f.label :sells, t('primary_details.any', scope: scope), value: "any" .row .alpha.three.columns diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml deleted file mode 100644 index 275e106c09d..00000000000 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -.row - .three.columns.alpha - = f.label :sells, t('.sells') - = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} - .two.columns - = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged"} - = f.label :sells, t('.none'), value: "none" - .two.columns - = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" } - = f.label :sells, t('.own'), value: "own" - .four.columns.omega - = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" } - = f.label :sells, t('.any'), value: "any" - %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "admin-only-target": "spinner" } } - = render partial: "components/admin_spinner" - -= render partial: 'admin/enterprises/form/permalink' - -.row - .three.columns.alpha - = f.label :external_billing_id, t('.external_billing_id') - = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} - .four.columns - = f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') } diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 297263f2639..8f1ebb93df0 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -18,6 +18,28 @@ .five.columns.omega = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } = f.label :is_primary_producer, t('.producer') +- if spree_current_user.admin? + .row + .three.columns.alpha + = f.label :sells, t('.sells') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} + .two.columns + = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.none'), value: "none" + .two.columns + = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.own'), value: "own" + .four.columns.omega + = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.any'), value: "any" + %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } + = render partial: "components/admin_spinner" + .row + .three.columns.alpha + = f.label :external_billing_id, t('.external_billing_id') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} + .four.columns + = f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') } .row .three.columns.alpha %label= t('.visible_in_search') @@ -31,3 +53,5 @@ .four.columns.omega = f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible' = f.label :visible, t('.hidden'), value: 'hidden' + += render partial: 'admin/enterprises/form/permalink' diff --git a/app/webpacker/controllers/admin_only_controller.js b/app/webpacker/controllers/admin_only_controller.js deleted file mode 100644 index beb5eae2e4a..00000000000 --- a/app/webpacker/controllers/admin_only_controller.js +++ /dev/null @@ -1,30 +0,0 @@ -import { Controller } from "stimulus"; - -export default class extends Controller { - static values = { enterpriseSells: String }; - static targets = ["spinner"]; - - enterpriseSellsChanged(event) { - console.log("enterpriseSellsChanged"); - if (event.currentTarget.checked) { - this.enterpriseSellsValue = event.currentTarget.value; - this.spinnerTarget.classList.remove("hidden"); - this.makeRequest(); - } - } - - makeRequest() { - fetch( - `?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}`, - { - method: "GET", - headers: { "Content-type": "application/json; charset=UTF-8" }, - } - ) - .then((data) => data.json()) - .then((operation) => { - CableReady.perform(operation); - this.spinnerTarget.classList.add("hidden"); - }); - } -} diff --git a/app/webpacker/controllers/primary_details_controller.js b/app/webpacker/controllers/primary_details_controller.js index 59443d2669e..b4e72be4cf6 100644 --- a/app/webpacker/controllers/primary_details_controller.js +++ b/app/webpacker/controllers/primary_details_controller.js @@ -1,7 +1,7 @@ import { Controller } from "stimulus"; export default class extends Controller { - static values = { primaryProducer: String }; + static values = { primaryProducer: String, enterpriseSells: String }; static targets = ["spinner"]; primaryProducerChanged(event) { @@ -9,9 +9,17 @@ export default class extends Controller { this.makeRequest(); } + enterpriseSellsChanged(event) { + if (event.currentTarget.checked) { + this.enterpriseSellsValue = event.currentTarget.value; + this.spinnerTarget.classList.remove("hidden"); + this.makeRequest(); + } + } + makeRequest() { fetch( - `?stimulus=true&is_primary_producer=${this.primaryProducerValue}`, + `?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}&is_primary_producer=${this.primaryProducerValue}`, { method: "GET", headers: { "Content-type": "application/json; charset=UTF-8" }, diff --git a/config/locales/en.yml b/config/locales/en.yml index 6db44cbe9e1..b2ab4fd8078 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1187,16 +1187,6 @@ en: desc_long_placeholder: Tell customers about yourself. This information appears on your public profile. address: legend: "Address" - admin_only: - legend: "Admin Only" - any: Any - none: None - own: Own - sells: Sells - sells_tip: "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" - external_billing_id: External Billing ID - external_billing_id_placeholder: eg. INV-2024-123456 - external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise." business_details: legend: "Business Details" upload: 'upload' @@ -1289,6 +1279,14 @@ en: primary_producer: Primary Producer? primary_producer_tip: Select 'Producer' if you are a primary producer of food. producer: Producer + any: Any + none: None + own: Own + sells: Sells + sells_tip: "None - enterprise does not sell to customers directly.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" + external_billing_id: External Billing ID + external_billing_id_placeholder: eg. INV-2024-123456 + external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise." visible_in_search: Visible in search? visible_in_search_tip: "Shops can be
1. publicly visible, appearing on the OFN map and listings.
2. Hidden on maps and listings but referenced by other shops and linked in their profile.
3. Completely hidden." visible: Public @@ -1712,7 +1710,6 @@ en: enterprise: primary_details: "Primary Details" address: "Address" - admin_only: "Admin Only" contact: "Contact" social: "Social" about: "About" diff --git a/spec/helpers/admin/enterprises_helper_spec.rb b/spec/helpers/admin/enterprises_helper_spec.rb index 36bd1b50852..aae01ab5ea0 100644 --- a/spec/helpers/admin/enterprises_helper_spec.rb +++ b/spec/helpers/admin/enterprises_helper_spec.rb @@ -33,13 +33,5 @@ user.enterprises << enterprise expect(visible_items.pluck(:name)).to include "connected_apps" end - - context 'when user is an admin' do - let(:user) { create(:admin_user) } - - it "includes admin-only item" do - expect(visible_items.pluck(:name)).to include "admin_only" - end - end end end diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 2cd8b23e883..86d007a46b5 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -86,10 +86,6 @@ end fill_in 'enterprise_name', with: 'Eaterprises' - - accept_alert do - click_link "Admin Only" - end fill_in 'enterprise_permalink', with: 'eaterprises-permalink' expect(page).to have_selector '.available' choose 'Own' From e946b505152c25ffbe382941d04dc5a6c28426a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Mon, 6 Jan 2025 21:21:32 +0100 Subject: [PATCH 21/24] Isolate into an Admin Only section --- .../form/_primary_details.html.haml | 50 ++++++++++--------- config/locales/en.yml | 1 + 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 8f1ebb93df0..e5bbf4eed06 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -16,30 +16,8 @@ %label= t('.primary_producer') = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.primary_producer_tip')} .five.columns.omega - = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } + = f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" } = f.label :is_primary_producer, t('.producer') -- if spree_current_user.admin? - .row - .three.columns.alpha - = f.label :sells, t('.sells') - = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} - .two.columns - = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.none'), value: "none" - .two.columns - = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.own'), value: "own" - .four.columns.omega - = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} - = f.label :sells, t('.any'), value: "any" - %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } - = render partial: "components/admin_spinner" - .row - .three.columns.alpha - = f.label :external_billing_id, t('.external_billing_id') - = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} - .four.columns - = f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') } .row .three.columns.alpha %label= t('.visible_in_search') @@ -55,3 +33,29 @@ = f.label :visible, t('.hidden'), value: 'hidden' = render partial: 'admin/enterprises/form/permalink' + +- if spree_current_user.admin? + .row + %fieldset.alpha.no-border-bottom + %legend= t('.admin_only_legend') + .row + .three.columns.alpha + = f.label :sells, t('.sells') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')} + .two.columns + = f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.none'), value: "none" + .two.columns + = f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.own'), value: "own" + .four.columns.omega + = f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"} + = f.label :sells, t('.any'), value: "any" + %span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } } + = render partial: "components/admin_spinner" + .row + .three.columns.alpha + = f.label :external_billing_id, t('.external_billing_id') + = render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')} + .four.columns + = f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') } diff --git a/config/locales/en.yml b/config/locales/en.yml index b2ab4fd8078..a1a5bb33c73 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1292,6 +1292,7 @@ en: visible: Public not_visible: Hidden hidden: Hide all references + admin_only_legend: Admin only properties: legend: "Properties" permalink: From 9c153c6083d505b21ec39ca7b96d5bf617ebf66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 8 Jan 2025 22:39:52 +0100 Subject: [PATCH 22/24] Improve specs --- spec/serializers/api/admin/enterprise_serializer_spec.rb | 9 --------- spec/system/admin/reports/revenues_by_hub_spec.rb | 8 ++++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/spec/serializers/api/admin/enterprise_serializer_spec.rb b/spec/serializers/api/admin/enterprise_serializer_spec.rb index df2a86f8027..3f20145771f 100644 --- a/spec/serializers/api/admin/enterprise_serializer_spec.rb +++ b/spec/serializers/api/admin/enterprise_serializer_spec.rb @@ -73,13 +73,4 @@ end end end - - context "when there is a external billing id" do - let(:enterprise) { create(:distributor_enterprise, external_billing_id: 'INV123456') } - - it "includes URLs of image versions" do - serializer = Api::Admin::EnterpriseSerializer.new(enterprise) - expect(serializer.as_json[:external_billing_id]).to eq('INV123456') - end - end end diff --git a/spec/system/admin/reports/revenues_by_hub_spec.rb b/spec/system/admin/reports/revenues_by_hub_spec.rb index 5e85340aa32..cc0c25ce113 100644 --- a/spec/system/admin/reports/revenues_by_hub_spec.rb +++ b/spec/system/admin/reports/revenues_by_hub_spec.rb @@ -37,9 +37,9 @@ tax_rate_name: "Tax 1" ) end - let(:distributor1) { create(:enterprise, name: "Hub 1", owner:) } + let(:distributor1) { create(:enterprise, name: "Hub 1", owner:, external_billing_id: 'INV1234') } let(:distributor2) { create(:enterprise, name: "Hub 2", owner:) } - let(:distributor3) { create(:enterprise, name: "Hub 3", owner:) } + let(:distributor3) { create(:enterprise, name: "Hub 3", owner:, external_billing_id: 'INV4321') } let(:owner) { create(:user, email: 'email@email.com') } let(:order_cycle) { create(:simple_order_cycle) } let(:product) { create(:product) } @@ -90,7 +90,7 @@ "none", "none", "none", - "none", + "INV1234", "email@email.com", "none", "10 Lovely Street", @@ -134,7 +134,7 @@ "none", "none", "none", - "none", + "INV4321", "email@email.com", "none", "10 Lovely Street", From 96c7c828c1a239472fe3e8f8051ed828ad19ab65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 8 Jan 2025 22:52:17 +0100 Subject: [PATCH 23/24] Fix specs --- spec/system/admin/reports/revenues_by_hub_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/reports/revenues_by_hub_spec.rb b/spec/system/admin/reports/revenues_by_hub_spec.rb index cc0c25ce113..9834fc55ba0 100644 --- a/spec/system/admin/reports/revenues_by_hub_spec.rb +++ b/spec/system/admin/reports/revenues_by_hub_spec.rb @@ -87,10 +87,10 @@ "Hub 1", order.distributor.id, "none", + "INV1234", "none", "none", "none", - "INV1234", "email@email.com", "none", "10 Lovely Street", @@ -131,10 +131,10 @@ "Hub 3", order_with_voucher_tax_excluded.distributor.id, "none", + "INV4321", "none", "none", "none", - "INV4321", "email@email.com", "none", "10 Lovely Street", From 244e0524c7522db869b551ee873400b1550999d9 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 10 Jan 2025 10:31:52 +1100 Subject: [PATCH 24/24] Re-instate check for external_billing_id --- spec/serializers/api/admin/enterprise_serializer_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/serializers/api/admin/enterprise_serializer_spec.rb b/spec/serializers/api/admin/enterprise_serializer_spec.rb index 3f20145771f..8483c2e27c9 100644 --- a/spec/serializers/api/admin/enterprise_serializer_spec.rb +++ b/spec/serializers/api/admin/enterprise_serializer_spec.rb @@ -5,10 +5,11 @@ RSpec.describe Api::Admin::EnterpriseSerializer do include FileHelper - let(:enterprise) { create(:distributor_enterprise) } + let(:enterprise) { create(:distributor_enterprise, external_billing_id: 'INV123456') } it "serializes an enterprise" do serializer = Api::Admin::EnterpriseSerializer.new enterprise expect(serializer.to_json).to match enterprise.name + expect(serializer.as_json[:external_billing_id]).to eq('INV123456') end context "for logo" do