From 89036db666d37cc40f876d5534470f9dbb08bea9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 29 Mar 2023 11:20:56 +0200 Subject: [PATCH] Do not use a preference, but create a new column for hide_ofn_navigation --- app/controllers/concerns/white_label.rb | 2 +- app/models/enterprise.rb | 1 - app/serializers/api/admin/enterprise_serializer.rb | 2 +- app/serializers/api/enterprise_shopfront_serializer.rb | 2 +- app/services/permitted_attributes/enterprise.rb | 2 +- app/views/admin/enterprises/form/_white_label.html.haml | 4 ++-- ...20230329080357_add_hide_ofn_navigation_to_enterprises.rb | 5 +++++ db/schema.rb | 3 ++- spec/controllers/spree/orders_controller_spec.rb | 2 +- spec/system/admin/enterprises_spec.rb | 4 ++-- spec/system/consumer/white_label_spec.rb | 6 +++--- 11 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 575fa68d25..180d138237 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -9,6 +9,6 @@ module WhiteLabel # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation - @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation + @hide_ofn_navigation = distributor.hide_ofn_navigation end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 9a692dcc4d..a5d4fe6ff6 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -30,7 +30,6 @@ class Enterprise < ApplicationRecord preference :shopfront_product_sorting_method, :string, default: "by_category" preference :invoice_order_by_supplier, :boolean, default: false preference :product_low_stock_display, :boolean, default: false - preference :hide_ofn_navigation, :boolean, default: false # Allow hubs to restrict visible variants to only those in their inventory preference :product_selection_from_inventory_only, :boolean, default: false diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 1e8a184910..9afed8e532 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -14,7 +14,7 @@ module Api :logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name, :terms_and_conditions_updated_at, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, - :visible, :preferred_hide_ofn_navigation + :visible, :hide_ofn_navigation has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index ab8b26bc67..12ca4d1b79 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -10,7 +10,7 @@ module Api :phone, :whatsapp_phone, :whatsapp_url, :visible, :email_address, :hash, :logo, :promo_image, :path, :category, :active, :producers, :orders_close_at, :hubs, :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display, - :preferred_hide_ofn_navigation + :hide_ofn_navigation has_one :address, serializer: Api::AddressSerializer has_many :supplied_properties, serializer: Api::PropertySerializer diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 9904e88b23..c72a24cfa7 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -35,7 +35,7 @@ module PermittedAttributes :show_customer_names_to_suppliers, :preferred_shopfront_product_sorting_method, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, - :preferred_hide_ofn_navigation + :hide_ofn_navigation ] end end diff --git a/app/views/admin/enterprises/form/_white_label.html.haml b/app/views/admin/enterprises/form/_white_label.html.haml index 892c91a34e..b083ec7700 100644 --- a/app/views/admin/enterprises/form/_white_label.html.haml +++ b/app/views/admin/enterprises/form/_white_label.html.haml @@ -1,6 +1,6 @@ .row .three.columns.alpha - = f.label :preferred_hide_ofn_navigation, t('.hide_ofn_navigation') + = f.label :hide_ofn_navigation, t('.hide_ofn_navigation') .three.columns - = f.check_box :preferred_hide_ofn_navigation + = f.check_box :hide_ofn_navigation diff --git a/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb b/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb new file mode 100644 index 0000000000..3fd3906634 --- /dev/null +++ b/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb @@ -0,0 +1,5 @@ +class AddHideOfnNavigationToEnterprises < ActiveRecord::Migration[7.0] + def change + add_column :enterprises, :hide_ofn_navigation, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e7f939670..04c2560ce1 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: 2023_03_15_031807) do +ActiveRecord::Schema[7.0].define(version: 2023_03_29_080357) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_15_031807) do t.boolean "show_customer_names_to_suppliers", default: false, null: false t.string "visible", limit: 255, default: "public", null: false t.string "whatsapp_phone", limit: 255 + t.boolean "hide_ofn_navigation", default: false, null: false 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 diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 41da37c00f..44b5873661 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -91,7 +91,7 @@ describe Spree::OrdersController, type: :controller do it "redirects to shop when order is empty" do allow(controller).to receive(:current_distributor).and_return(distributor) - allow(distributor).to receive(:preferred_hide_ofn_navigation).and_return false + allow(distributor).to receive(:hide_ofn_navigation).and_return false allow(controller).to receive(:current_order_cycle).and_return(order_cycle) allow(controller).to receive(:current_order).and_return order allow(order).to receive_message_chain(:line_items, :empty?).and_return true diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 1ba51c6a65..5613a6da02 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -600,7 +600,7 @@ describe ' check "Hide OFN navigation" click_button 'Update' expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be true + expect(distributor1.reload.hide_ofn_navigation).to be true visit edit_admin_enterprise_path(distributor1) within(".side_menu") do @@ -610,7 +610,7 @@ describe ' uncheck "Hide OFN navigation" click_button 'Update' expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be false + expect(distributor1.reload.hide_ofn_navigation).to be false end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 58aa0ff5af..24e930725d 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -46,7 +46,7 @@ describe 'White label setting' do context "manage the hide_ofn_navigation preference" do context "when the preference is set to true" do before do - distributor.update_attribute(:preferred_hide_ofn_navigation, true) + distributor.update_attribute(:hide_ofn_navigation, true) end shared_examples "hides the OFN navigation when needed only" do @@ -132,7 +132,7 @@ describe 'White label setting' do context "when the user has a current distributor that is not the distributor's order" do let!(:another_distributor) { create(:distributor_enterprise) } before do - another_distributor.update_attribute(:preferred_hide_ofn_navigation, false) + another_distributor.update_attribute(:hide_ofn_navigation, false) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(another_distributor) end @@ -153,7 +153,7 @@ describe 'White label setting' do context "when the preference is set to false" do before do - distributor.update_attribute(:preferred_hide_ofn_navigation, false) + distributor.update_attribute(:hide_ofn_navigation, false) set_order(order) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor)