From d13b4093ee5b4a9a76e2b4b21c1a324af693b435 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] 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 ----- 9 files changed, 48 insertions(+), 87 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 7a828206105..b49d8194389 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 @@ -1732,7 +1730,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