Rescue Not Found Error for Enterprise for admin

Currently when an admin tries to edit an no-existing enterprise, a
NoMethodError is raised.

This commit adds a set_enterprise setter method to the
enterprises controller that sets the @enterprise instance variable to
have the same value as the enterprise object defined in the the edit
method; this method also rescues the NotFound error  in case
the enterprise is not found and redirects the user to the enterprises
index page with a error message.
This commit is contained in:
Tresor11
2025-03-22 00:35:27 +03:00
parent 37de45b60e
commit 5b3bae85ca
2 changed files with 19 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ module Admin
prepend_before_action :override_sells, only: :create
before_action :load_countries, except: [:index, :register, :check_permalink]
before_action :set_enterprise, only: [:edit, :update]
before_action :load_methods_and_fees, only: [:edit, :update]
before_action :load_groups, only: [:new, :edit, :update, :create]
before_action :load_taxons, only: [:new, :edit, :update, :create]
@@ -216,6 +217,14 @@ module Admin
[:index, :for_order_cycle, :visible, :bulk_update]
end
def set_enterprise
@enterprise = @object
return if @enterprise
flash[:error] = I18n.t(:enterprise_not_found_error)
redirect_to admin_enterprises_path
end
def load_methods_and_fees
enterprise_payment_methods = @enterprise.payment_methods.to_a
enterprise_shipping_methods = @enterprise.shipping_methods.to_a

View File

@@ -629,7 +629,7 @@ en:
price: Price
producer: Producer
category: Category
sku: SKU
sku: SKU
on_hand: "On Hand"
on_demand: "On Demand"
tax_category: "Tax Category"
@@ -641,7 +641,7 @@ en:
price: Price
producer: Producer
category: Category
sku: SKU
sku: SKU
on_hand: "On Hand"
on_demand: "On Demand"
tax_category: "Tax Category"
@@ -652,7 +652,7 @@ en:
clone: Clone
delete: Delete
remove: Remove
preview: Preview
preview: Preview
image:
edit: Edit
product_preview:
@@ -801,7 +801,7 @@ en:
connected_apps_enabled:
discover_regen: Discover Regenerative portal
affiliate_sales_data: DFC anonymised orders API for research purposes
vine: Voucher Integration Engine (VINE)
vine: Voucher Integration Engine (VINE)
update:
resource: Connected app settings
@@ -1429,7 +1429,7 @@ en:
use_limit: Use/Limit
customers: Customer
net_value: Net Value
active: Active?
active: Active?
add_new: Add New
no_voucher_yet: No Vouchers yet
white_label:
@@ -2139,7 +2139,7 @@ en:
voucher_not_found: Not found
add_voucher_error: There was an error while adding the voucher
create_voucher_error: "There was an error while creating the voucher: %{error}"
voucher_redeeming_error: There was an error while trying to redeem your voucher
voucher_redeeming_error: There was an error while trying to redeem your voucher
shops:
hubs:
show_closed_shops: "Show closed shops"
@@ -2218,7 +2218,7 @@ en:
invoice_column_price_per_unit_without_taxes: "Price Per unit (Excl. tax)"
invoice_column_tax_rate: "Tax rate"
invoice_tax_total: "GST Total:"
invoice_cancel_and_replace_invoice: "cancels and replaces invoice"
invoice_cancel_and_replace_invoice: "cancels and replaces invoice"
tax_invoice: "TAX INVOICE"
tax_total: "Total tax (%{rate}):"
invoice_shipping_category_delivery: "Delivery"
@@ -3440,6 +3440,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
enterprise_register_package_error: "Please select a package"
enterprise_register_error: "Could not complete registration for %{enterprise}"
enterprise_register_success_notice: "Congratulations! Registration for %{enterprise} is complete!"
enterprise_not_found_error: "Enterprise not found"
enterprise_bulk_update_success_notice: "Enterprises updated successfully"
enterprise_bulk_update_error: 'Update failed'
enterprise_shop_show_error: "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."
@@ -4733,7 +4734,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
title: "Edit Product Category"
destroy:
delete_taxon:
success: "Successfully deleted the product category"
success: "Successfully deleted the product category"
error: "Unable to delete the product category due to assigned products."
form:
name: Name
@@ -4741,7 +4742,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
meta_description: Meta Description
meta_keywords: Meta Keywords
description: Description
dfc_id: DFC URI
dfc_id: DFC URI
general_settings:
edit:
legal_settings: "Legal Settings"