From d0f683d2792e5292cef65521f3d0e65faaf0de63 Mon Sep 17 00:00:00 2001
From: David Cook
Date: Tue, 23 Apr 2024 16:48:52 +1000
Subject: [PATCH 1/4] Spec for bug
---
spec/system/admin/products_v3/products_spec.rb | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb
index 7384f1c0bd1..a4f2a3b139b 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 @@
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
@@ -145,6 +150,7 @@
fill_in "Name", with: "Pommes"
end
+ pending "#12403"
expect {
click_button "Save changes"
@@ -180,7 +186,7 @@
end
end
- describe "updating" do
+ xdescribe "updating" do # pending #12403
let!(:variant_a1) {
product_a.variants.first.tap{ |v|
v.update! display_name: "Medium box", sku: "APL-01", price: 5.25, on_hand: 5,
@@ -974,7 +980,7 @@
def create_products(amount)
amount.times do |i|
- create(:simple_product, name: "product #{i}")
+ create(:simple_product, name: "product #{i}", supplier: producer)
end
end
From b5cdee3d65f725df76aaea1f993959b02ff5ef57 Mon Sep 17 00:00:00 2001
From: David Cook
Date: Tue, 23 Apr 2024 13:02:54 +1000
Subject: [PATCH 2/4] Rename translation key
So that it can be used for more general purposes.
---
app/webpacker/controllers/application_controller.js | 2 +-
config/locales/en.yml | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/app/webpacker/controllers/application_controller.js b/app/webpacker/controllers/application_controller.js
index 3065427cf43..50f5e57269e 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/config/locales/en.yml b/config/locales/en.yml
index e20236b1d9a..1fe516fee83 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.
"
- 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."
From 574e8f01356e51f5b9641d2fd8cf5d926930f6a2 Mon Sep 17 00:00:00 2001
From: David Cook
Date: Tue, 23 Apr 2024 13:04:48 +1000
Subject: [PATCH 3/4] Show error message when turbo:frame-missing
Instead of replacing frame contents with unhelpful text 'Content missing'.
---
app/webpacker/js/turbo.js | 14 ++++++++++++++
app/webpacker/packs/admin.js | 3 ++-
app/webpacker/packs/application.js | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 app/webpacker/js/turbo.js
diff --git a/app/webpacker/js/turbo.js b/app/webpacker/js/turbo.js
new file mode 100644
index 00000000000..4451810c939
--- /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 81735d3040d..dbb68bafc29 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 5ee6a3b0660..f8263d1830a 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";
From b846d0f517f1508ea98e144ddb71ab539cef608e Mon Sep 17 00:00:00 2001
From: David Cook
Date: Tue, 23 Apr 2024 13:11:39 +1000
Subject: [PATCH 4/4] Add ability to bulk update products for product managers
I forgot to do this in #12328 [BUU] Remove Stimulus Reflex from Products screen
---
app/models/spree/ability.rb | 2 +-
spec/system/admin/products_v3/products_spec.rb | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb
index 037bfecdb6b..e95d73b5fcc 100644
--- a/app/models/spree/ability.rb
+++ b/app/models/spree/ability.rb
@@ -192,7 +192,7 @@ def add_product_management_abilities(user)
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/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb
index a4f2a3b139b..5d69b524cca 100644
--- a/spec/system/admin/products_v3/products_spec.rb
+++ b/spec/system/admin/products_v3/products_spec.rb
@@ -150,7 +150,6 @@
fill_in "Name", with: "Pommes"
end
- pending "#12403"
expect {
click_button "Save changes"
@@ -179,14 +178,14 @@
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
end
end
- xdescribe "updating" do # pending #12403
+ describe "updating" do
let!(:variant_a1) {
product_a.variants.first.tap{ |v|
v.update! display_name: "Medium box", sku: "APL-01", price: 5.25, on_hand: 5,