mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #12412 from dacook/buu/fix-non-admin-saving-12403
[BUU] Fix non-admin saving
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
14
app/webpacker/js/turbo.js
Normal file
14
app/webpacker/js/turbo.js
Normal file
@@ -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"));
|
||||
}
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "controllers";
|
||||
import "@hotwired/turbo";
|
||||
import "../js/turbo";
|
||||
import "../js/hotkeys";
|
||||
import "../js/mrujs";
|
||||
import "../js/matomo";
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user