diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index 037bfecdb6..e95d73b5fc 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -192,7 +192,7 @@ module Spree OpenFoodNetwork::Permissions.new(user).managed_product_enterprises.include? product.supplier end - can [:admin, :index], :products_v3 + can [:admin, :index, :bulk_update], :products_v3 can [:create], Spree::Variant can [:admin, :index, :read, :edit, diff --git a/app/webpacker/controllers/application_controller.js b/app/webpacker/controllers/application_controller.js index 3065427cf4..50f5e57269 100644 --- a/app/webpacker/controllers/application_controller.js +++ b/app/webpacker/controllers/application_controller.js @@ -47,7 +47,7 @@ export default class extends Controller { console.error(reflex + ":\n " + error); // show error message - alert(I18n.t("errors.stimulus_reflex_error")); + alert(I18n.t("errors.general_error.message")); } reflexForbidden(element, reflex, noop, reflexId) { diff --git a/app/webpacker/js/turbo.js b/app/webpacker/js/turbo.js new file mode 100644 index 0000000000..4451810c93 --- /dev/null +++ b/app/webpacker/js/turbo.js @@ -0,0 +1,14 @@ +import "@hotwired/turbo"; + +document.addEventListener("turbo:frame-missing", (event) => { + // don't replace frame contents + event.preventDefault(); + + // show error message instead + status = event.detail.response.status; + if(status == 401) { + alert(I18n.t("errors.unauthorized.message")); + } else { + alert(I18n.t("errors.general_error.message")); + } +}); diff --git a/app/webpacker/packs/admin.js b/app/webpacker/packs/admin.js index 81735d3040..dbb68bafc2 100644 --- a/app/webpacker/packs/admin.js +++ b/app/webpacker/packs/admin.js @@ -1,6 +1,6 @@ import "controllers"; import "channels"; -import "@hotwired/turbo"; +import "../js/turbo"; import "../js/hotkeys"; import "../js/mrujs"; import "../js/matomo"; @@ -17,3 +17,4 @@ import Trix from "trix"; document.addEventListener("trix-file-accept", (event) => { event.preventDefault(); }); + diff --git a/app/webpacker/packs/application.js b/app/webpacker/packs/application.js index 5ee6a3b066..f8263d1830 100644 --- a/app/webpacker/packs/application.js +++ b/app/webpacker/packs/application.js @@ -1,5 +1,5 @@ import "controllers"; -import "@hotwired/turbo"; +import "../js/turbo"; import "../js/hotkeys"; import "../js/mrujs"; import "../js/matomo"; diff --git a/config/locales/en.yml b/config/locales/en.yml index e20236b1d9..1fe516fee8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -175,14 +175,15 @@ en: message_html: "

The change you wanted was rejected. Maybe you tried to change something you don't have access to.

Return home

" - stimulus_reflex_error: "We're sorry, but something went wrong. + general_error: + message: "We're sorry, but something went wrong. - This might be a temporary problem, so please try again or reload the page. + This might be a temporary problem, so please try again or reload the page. - We record all errors and may be working on a fix. + We record all errors and may be working on a fix. - If the problem persists or is urgent, please contact us." + If the problem persists or is urgent, please contact us." stripe: error_code: incorrect_number: "The card number is incorrect." diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 7384f1c0bd..5d69b524cc 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -2,13 +2,16 @@ require "system_helper" -describe 'As an admin, I can manage products', feature: :admin_style_v3 do +describe 'As an enterprise user, I can manage my products', feature: :admin_style_v3 do include WebHelper include AuthenticationHelper include FileHelper + let(:producer) { create(:supplier_enterprise) } + let(:user) { create(:user, enterprises: [producer]) } + before do - login_as_admin + login_as user end it "can see the new product page" do @@ -129,8 +132,10 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do before { create_products 1 } # create a product with a different supplier - let!(:producer) { create(:supplier_enterprise, name: "Producer 1") } - let!(:product_by_supplier) { create(:simple_product, name: "Apples", supplier: producer) } + let!(:producer1) { create(:supplier_enterprise, name: "Producer 1") } + let!(:product_by_supplier) { create(:simple_product, name: "Apples", supplier: producer1) } + + before { user.enterprise_roles.create(enterprise: producer1) } it "can search for and update a product" do visit admin_products_url @@ -173,7 +178,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do search_by_category "Category 1" # expect(page).to have_content "1 product found for your search criteria." - expect(page).to have_select "category_id", selected: "Category 1" + expect(page).to have_select "category_id", selected: "Category 1" # fails in dev but not CI expect_products_count_to_be 1 expect(page).to have_field "Name", with: product_by_category.name end @@ -974,7 +979,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do def create_products(amount) amount.times do |i| - create(:simple_product, name: "product #{i}") + create(:simple_product, name: "product #{i}", supplier: producer) end end