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

Display error if editing non-current order #3391

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ en:
cannot_create_payment_without_payment_methods_html: You cannot create a payment
for an order without any payment methods defined. %{link}
cannot_create_returns: Cannot create returns as this order has no shipped units.
cannot_edit_orders: You may only edit your current shopping cart.
cannot_perform_operation: Cannot perform requested operation
cannot_rebuild_shipments_order_completed: Cannot rebuild shipments for a completed
order.
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/controllers/spree/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def edit
@order = current_order || Spree::Order.incomplete.find_or_initialize_by(guest_token: cookies.signed[:guest_token])
authorize! :read, @order, cookies.signed[:guest_token]
associate_user
if params[:id] && @order.number != params[:id]
flash[:error] = t('spree.cannot_edit_orders')
redirect_to cart_path
end
end

# Adds a new item to the order (creating a new order if none already exists)
Expand Down
25 changes: 25 additions & 0 deletions frontend/spec/controllers/spree/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@
end
end

context '#edit' do
before do
allow(controller).to receive :authorize!
allow(controller).to receive_messages current_order: order
end

it 'should render cart' do
get :edit, params: { id: order.number }

expect(flash[:error]).to be_nil
expect(response).to be_ok
end

context 'with another order number than the current_order' do
let(:other_order) { create(:completed_order_with_totals) }

it 'should display error message' do
get :edit, params: { id: other_order.number }

expect(flash[:error]).to eq "You may only edit your current shopping cart."
expect(response).to redirect_to cart_path
end
end
end

context "#update" do
context "with authorization" do
before do
Expand Down