Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUU] Fix non-admin saving #12412

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/webpacker/controllers/application_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions app/webpacker/js/turbo.js
Original file line number Diff line number Diff line change
@@ -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"));
}
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, in Rails we arrange code like this in a folder called initializers. Maybe we could do the same with JS next time.

3 changes: 2 additions & 1 deletion app/webpacker/packs/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "controllers";
import "channels";
import "@hotwired/turbo";
import "../js/turbo";
import "../js/hotkeys";
import "../js/mrujs";
import "../js/matomo";
Expand All @@ -17,3 +17,4 @@ import Trix from "trix";
document.addEventListener("trix-file-accept", (event) => {
event.preventDefault();
});

2 changes: 1 addition & 1 deletion app/webpacker/packs/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "controllers";
import "@hotwired/turbo";
import "../js/turbo";
import "../js/hotkeys";
import "../js/mrujs";
import "../js/matomo";
Expand Down
9 changes: 5 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ en:
message_html: "<p>The change you wanted was rejected. Maybe you tried to change something you don't have access to.
<br><h3><a href='/' >Return home</a></h3>
</p>"
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."
Expand Down
18 changes: 12 additions & 6 deletions spec/system/admin/products_v3/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Copy link
Member Author

@dacook dacook Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In many places the codebase says "supplier". We now prefer the term "producer", which is used in general communication, so I've named the variables as such.
Maybe one day we'll update the codebase to avoid confusion..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't actually know this. "Supplier" is a bit more general. The enterprise may not be producing the product. 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall having a conversation in Slack I think, and that "producer" was the winner.
I agree that "supplier" makes more sense, although arguably the distributor also "supplies" the product, so it could be ambiguous...

I can't find that conversation though, so now I'm not sure! I will seek clarification in #product-circle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the conversation https://openfoodnetwork.slack.com/archives/C01T75H6G0Z/p1679368367236359
Seems we ended up with "supplier" back then 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sigmund, I forgot my own comments! 😅

I'm going to write it on a post-it note on my computer screen..

let(:user) { create(:user, enterprises: [producer]) }

before do
login_as_admin
login_as user
end

it "can see the new product page" do
Expand Down Expand Up @@ -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
Expand All @@ -145,6 +150,7 @@
fill_in "Name", with: "Pommes"
end

pending "#12403"
expect {
click_button "Save changes"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down