Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed returns management settings with new permitted attributes (#12758)
Damian Legawiec0d1eed60a370
diff --git a/admin/app/controllers/spree/admin/refund_reasons_controller.rb b/admin/app/controllers/spree/admin/refund_reasons_controller.rbindex e08a6a69ce..696eed50ae 100644--- a/admin/app/controllers/spree/admin/refund_reasons_controller.rb+++ b/admin/app/controllers/spree/admin/refund_reasons_controller.rb@@ -1,6 +1,13 @@module Spreemodule Adminclass RefundReasonsController < ResourceController+ add_breadcrumb Spree.t(:refund_reasons), :admin_refund_reasons_path++ private++ def permitted_resource_params+ params.require(:refund_reason).permit(permitted_refund_reason_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/reimbursement_types_controller.rb b/admin/app/controllers/spree/admin/reimbursement_types_controller.rbindex 59f25080d8..36c5fe835f 100644--- a/admin/app/controllers/spree/admin/reimbursement_types_controller.rb+++ b/admin/app/controllers/spree/admin/reimbursement_types_controller.rb@@ -1,6 +1,13 @@module Spreemodule Adminclass ReimbursementTypesController < ResourceController+ add_breadcrumb Spree.t(:reimbursement_types), :admin_reimbursement_types_path++ private++ def permitted_resource_params+ params.require(:reimbursement_type).permit(permitted_reimbursement_type_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/reimbursements_controller.rb b/admin/app/controllers/spree/admin/reimbursements_controller.rbindex 7c0d4eda4b..7ab8f0efaa 100644--- a/admin/app/controllers/spree/admin/reimbursements_controller.rb+++ b/admin/app/controllers/spree/admin/reimbursements_controller.rb@@ -42,6 +42,10 @@ module Spreeflash[:error] = error.messageredirect_to spree.edit_admin_order_reimbursement_path(parent, @reimbursement)end++ def permitted_resource_params+ params.require(:reimbursement).permit(permitted_reimbursement_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb b/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rbindex 7f58f048de..8a7610afd0 100644--- a/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb+++ b/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb@@ -1,6 +1,8 @@module Spreemodule Adminclass ReturnAuthorizationReasonsController < ResourceController+ add_breadcrumb Spree.t(:return_authorization_reasons), :admin_return_authorization_reasons_path+privatedef permitted_resource_paramsdiff --git a/admin/spec/controllers/spree/admin/refund_reasons_controller_spec.rb b/admin/spec/controllers/spree/admin/refund_reasons_controller_spec.rbnew file mode 100644index 0000000000..eb00542062--- /dev/null+++ b/admin/spec/controllers/spree/admin/refund_reasons_controller_spec.rb@@ -0,0 +1,85 @@+require 'spec_helper'++RSpec.describe Spree::Admin::RefundReasonsController, type: :controller do+ stub_authorization!+ render_views++ let(:refund_reason) { create(:refund_reason) }+ let(:valid_attributes) { { name: 'Test Reason', active: true } }+ let(:invalid_attributes) { { name: '', active: nil } }++ describe 'GET #index' do+ it 'returns a successful response' do+ get :index+ expect(response).to be_successful+ end+ end++ describe 'GET #new' do+ it 'returns a successful response' do+ get :new+ expect(response).to be_successful+ end+ end++ describe 'POST #create' do+ context 'with valid params' do+ it 'creates a new refund reason' do+ expect {+ post :create, params: { refund_reason: valid_attributes }+ }.to change(Spree::RefundReason, :count).by(1)+ end++ it 'redirects to the refund reasons edit screen' do+ post :create, params: { refund_reason: valid_attributes }+ refund_reason = Spree::RefundReason.last+ expect(response).to redirect_to(edit_admin_refund_reason_path(refund_reason))+ end+ end++ context 'with invalid params' do+ it 'does not create a new refund reason' do+ expect {+ post :create, params: { refund_reason: invalid_attributes }+ }.not_to change(Spree::RefundReason, :count)+ end++ it 're-renders the new template' do+ post :create, params: { refund_reason: invalid_attributes }+ expect(response).to render_template(:new)+ end+ end+ end++ describe 'GET #edit' do+ it 'returns a successful response' do+ get :edit, params: { id: refund_reason.to_param }+ expect(response).to be_successful+ end+ end++ describe 'PUT #update' do+ context 'with valid params' do+ let(:new_attributes) { { name: 'Updated Reason', active: false } }++ it 'updates the requested refund reason' do+ put :update, params: { id: refund_reason.to_param, refund_reason: new_attributes }+ refund_reason.reload+ expect(refund_reason.name).to eq('Updated Reason')+ expect(refund_reason.active).to be false+ end++ it 'redirects to the refund reason edit screen' do+ put :update, params: { id: refund_reason.to_param, refund_reason: new_attributes }+ expect(response).to redirect_to(edit_admin_refund_reason_path(refund_reason))+ end+ end++ context 'with invalid params' do+ it 'does not update the refund reason' do+ put :update, params: { id: refund_reason.to_param, refund_reason: invalid_attributes }+ expect(response).to render_template(:edit)+ end+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb b/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rbnew file mode 100644index 0000000000..39b0b6e66a--- /dev/null+++ b/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb@@ -0,0 +1,85 @@+require 'spec_helper'++RSpec.describe Spree::Admin::ReimbursementTypesController, type: :controller do+ stub_authorization!+ render_views++ let(:reimbursement_type) { create(:reimbursement_type) }+ let(:valid_attributes) { { name: 'Test Type', active: true } }+ let(:invalid_attributes) { { name: '', active: nil } }++ describe 'GET #index' do+ it 'returns a successful response' do+ get :index+ expect(response).to be_successful+ end+ end++ describe 'GET #new' do+ it 'returns a successful response' do+ get :new+ expect(response).to be_successful+ end+ end++ describe 'POST #create' do+ context 'with valid params' do+ it 'creates a new reimbursement type' do+ expect {+ post :create, params: { reimbursement_type: valid_attributes }+ }.to change(Spree::ReimbursementType, :count).by(1)+ end++ it 'redirects to the reimbursement types edit screen' do+ post :create, params: { reimbursement_type: valid_attributes }+ reimbursement_type = Spree::ReimbursementType.last+ expect(response).to redirect_to(edit_admin_reimbursement_type_path(reimbursement_type))+ end+ end++ context 'with invalid params' do+ it 'does not create a new reimbursement type' do+ expect {+ post :create, params: { reimbursement_type: invalid_attributes }+ }.not_to change(Spree::ReimbursementType, :count)+ end++ it 're-renders the new template' do+ post :create, params: { reimbursement_type: invalid_attributes }+ expect(response).to render_template(:new)+ end+ end+ end++ describe 'GET #edit' do+ it 'returns a successful response' do+ get :edit, params: { id: reimbursement_type.to_param }+ expect(response).to be_successful+ end+ end++ describe 'PUT #update' do+ context 'with valid params' do+ let(:new_attributes) { { name: 'Updated Type', active: false } }++ it 'updates the requested reimbursement type' do+ put :update, params: { id: reimbursement_type.to_param, reimbursement_type: new_attributes }+ reimbursement_type.reload+ expect(reimbursement_type.name).to eq('Updated Type')+ expect(reimbursement_type.active).to be false+ end++ it 'redirects to the reimbursement type edit screen' do+ put :update, params: { id: reimbursement_type.to_param, reimbursement_type: new_attributes }+ expect(response).to redirect_to(edit_admin_reimbursement_type_path(reimbursement_type))+ end+ end++ context 'with invalid params' do+ it 'does not update the reimbursement type' do+ put :update, params: { id: reimbursement_type.to_param, reimbursement_type: invalid_attributes }+ expect(response).to render_template(:edit)+ end+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/return_authorization_reasons_controller_spec.rb b/admin/spec/controllers/spree/admin/return_authorization_reasons_controller_spec.rbnew file mode 100644index 0000000000..0ffa73f1a5--- /dev/null+++ b/admin/spec/controllers/spree/admin/return_authorization_reasons_controller_spec.rb@@ -0,0 +1,85 @@+require 'spec_helper'++RSpec.describe Spree::Admin::ReturnAuthorizationReasonsController, type: :controller do+ stub_authorization!+ render_views++ let(:return_authorization_reason) { create(:return_authorization_reason) }+ let(:valid_attributes) { { name: 'Test Reason', active: true } }+ let(:invalid_attributes) { { name: '', active: nil } }++ describe 'GET #index' do+ it 'returns a successful response' do+ get :index+ expect(response).to be_successful+ end+ end++ describe 'GET #new' do+ it 'returns a successful response' do+ get :new+ expect(response).to be_successful+ end+ end++ describe 'POST #create' do+ context 'with valid params' do+ it 'creates a new return authorization reason' do+ expect {+ post :create, params: { return_authorization_reason: valid_attributes }+ }.to change(Spree::ReturnAuthorizationReason, :count).by(1)+ end++ it 'redirects to the return authorization reasons edit screen' do+ post :create, params: { return_authorization_reason: valid_attributes }+ return_authorization_reason = Spree::ReturnAuthorizationReason.last+ expect(response).to redirect_to(edit_admin_return_authorization_reason_path(return_authorization_reason))+ end+ end++ context 'with invalid params' do+ it 'does not create a new return authorization reason' do+ expect {+ post :create, params: { return_authorization_reason: invalid_attributes }+ }.not_to change(Spree::ReturnAuthorizationReason, :count)+ end++ it 're-renders the new template' do+ post :create, params: { return_authorization_reason: invalid_attributes }+ expect(response).to render_template(:new)+ end+ end+ end++ describe 'GET #edit' do+ it 'returns a successful response' do+ get :edit, params: { id: return_authorization_reason.to_param }+ expect(response).to be_successful+ end+ end++ describe 'PUT #update' do+ context 'with valid params' do+ let(:new_attributes) { { name: 'Updated Reason', active: false } }++ it 'updates the requested return authorization reason' do+ put :update, params: { id: return_authorization_reason.to_param, return_authorization_reason: new_attributes }+ return_authorization_reason.reload+ expect(return_authorization_reason.name).to eq('Updated Reason')+ expect(return_authorization_reason.active).to be false+ end++ it 'redirects to the return authorization reason edit screen' do+ put :update, params: { id: return_authorization_reason.to_param, return_authorization_reason: new_attributes }+ expect(response).to redirect_to(edit_admin_return_authorization_reason_path(return_authorization_reason))+ end+ end++ context 'with invalid params' do+ it 'does not update the return authorization reason' do+ put :update, params: { id: return_authorization_reason.to_param, return_authorization_reason: invalid_attributes }+ expect(response).to render_template(:edit)+ end+ end+ end+enddiff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rbindex 9bb647b67d..73fa88114b 100644--- a/core/lib/spree/permitted_attributes.rb+++ b/core/lib/spree/permitted_attributes.rb@@ -33,6 +33,9 @@ module Spree:product_properties_attributes,:property_attributes,:refund_attributes,+ :refund_reason_attributes,+ :reimbursement_attributes,+ :reimbursement_type_attributes,:report_attributes,:return_authorization_attributes,:return_authorization_reason_attributes,@@ -160,8 +163,12 @@ module Spree@@refund_attributes = [:amount, :refund_reason_id]+ @@refund_reason_attributes = [:name, :active, :mutable]+@@reimbursement_attributes = [return_items_attributes: [:id, :override_reimbursement_type_id, :pre_tax_amount, :exchange_variant_id]]+ @@reimbursement_type_attributes = [:name, :active]+@@report_attributes = [:type, :date_from, :date_to, :currency]@@return_authorization_attributes = [:amount, :memo, :stock_location_id, :inventory_units_attributes,@@ -170,7 +177,7 @@ module Spree:acceptance_status, :exchange_variant_id, :resellable]}]- @@return_authorization_reason_attributes = [:name, :description]+ @@return_authorization_reason_attributes = [:name, :active]@@return_item_attributes = [:inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount, :acceptance_status, :exchange_variant_id, :resellable]