Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed: refresh admin records after bulk operation (#13496)

Damian Legawiec62c9f3dee92b
diff --git a/admin/app/controllers/concerns/spree/admin/bulk_operations_concern.rb b/admin/app/controllers/concerns/spree/admin/bulk_operations_concern.rb
index 3fb18035b1..bae8cd14af 100644
--- a/admin/app/controllers/concerns/spree/admin/bulk_operations_concern.rb
+++ b/admin/app/controllers/concerns/spree/admin/bulk_operations_concern.rb
@@ -25,16 +25,7 @@ module Spree
end
def handle_bulk_operation_response
- respond_to do |format|
- format.turbo_stream do
- flash.now[:success] = flash_message_for(bulk_collection, :successfully_updated)
- render partial: 'spree/admin/shared/close_bulk_modal'
- end
- format.html do
- flash[:success] = flash_message_for(bulk_collection, :successfully_updated)
- redirect_to request.referer
- end
- end
+ redirect_back fallback_location: request.referer, status: :see_other
end
def bulk_collection
diff --git a/admin/app/controllers/spree/admin/products_controller.rb b/admin/app/controllers/spree/admin/products_controller.rb
index 7f4d5dff86..871dbc6a3a 100644
--- a/admin/app/controllers/spree/admin/products_controller.rb
+++ b/admin/app/controllers/spree/admin/products_controller.rb
@@ -86,15 +86,10 @@ module Spree
end
def bulk_status_update
- if bulk_collection.update_all(status: params[:status], updated_at: Time.current)
- product_ids = bulk_collection.ids
+ bulk_collection.update_all(status: params[:status], updated_at: Time.current)
+ invoke_callbacks(:bulk_status_update, :after)
- invoke_callbacks(:bulk_status_update, :after)
-
- flash.now[:success] = Spree.t('admin.bulk_ops.products.status_updated', status: params[:status].titleize)
- else
- flash.now[:error] = Spree.t('something_went_wrong')
- end
+ handle_bulk_operation_response
end
def bulk_remove_from_taxons
diff --git a/admin/app/views/spree/admin/products/bulk_status_update.turbo_stream.erb b/admin/app/views/spree/admin/products/bulk_status_update.turbo_stream.erb
deleted file mode 100644
index d1eda1fb5a..0000000000
--- a/admin/app/views/spree/admin/products/bulk_status_update.turbo_stream.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= render 'spree/admin/shared/close_bulk_modal' %>
-
-<% @bulk_collection.each do |product| %>
- <%= turbo_stream.replace dom_id(product, :status) do %>
- <%= render 'spree/admin/products/product_status', product: product %>
- <% end %>
-<% end %>
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
index 89a0973aae..0f6ad4ce7c 100644
--- a/admin/config/locales/en.yml
+++ b/admin/config/locales/en.yml
@@ -27,7 +27,6 @@ en:
set_active: Setting products to active will make those products available on the storefront.
set_archived: Setting products to archived will hide them from storefront.
set_draft: Setting products to draft will hide them from storefront.
- status_updated: Status updated
title:
add_tags: Add tags
add_to_brand: Add to brand
diff --git a/admin/spec/controllers/spree/admin/products_controller_spec.rb b/admin/spec/controllers/spree/admin/products_controller_spec.rb
index 13c358cb1a..4988e1b560 100644
--- a/admin/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/products_controller_spec.rb
@@ -1267,7 +1267,9 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
describe 'POST #bulk_status_update' do
let(:product) { create(:product, stores: [store], status: status) }
let(:status) { :draft }
- let(:send_request) { put :bulk_status_update, params: { ids: [product.id], status: 'active' }, format: :turbo_stream }
+ let(:send_request) { put :bulk_status_update, params: { ids: [product.id], status: 'active' } }
+
+ before { request.env['HTTP_REFERER'] = '/admin/products' }
shared_examples 'updates status to active' do |status|
let(:status) { status }
@@ -1276,6 +1278,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
expect(product.status).to eq status.to_s
send_request
expect(product.reload.active?).to be(true)
+ expect(response).to redirect_to('/admin/products')
end
end
@@ -1290,13 +1293,16 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
let(:product) { create(:product, stores: [store], status: :active) }
let(:product2) { create(:product, stores: [store], status: :active) }
let(:send_request) do
- put :bulk_add_tags, params: { ids: [product.id, product2.id], tags: ['tag1', 'tag2', 'tag3'] }, format: :turbo_stream
+ put :bulk_add_tags, params: { ids: [product.id, product2.id], tags: ['tag1', 'tag2', 'tag3'] }
end
+ before { request.env['HTTP_REFERER'] = '/admin/products' }
+
it 'adds tags to products' do
send_request
expect(product.reload.tag_list).to eq(['tag1', 'tag2', 'tag3'])
expect(product2.reload.tag_list).to eq(['tag1', 'tag2', 'tag3'])
+ expect(response).to redirect_to('/admin/products')
end
end
@@ -1304,13 +1310,16 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
let(:product) { create(:product, stores: [store], status: :active, tag_list: ['tag1', 'tag2', 'tag3']) }
let(:product2) { create(:product, stores: [store], status: :active, tag_list: ['tag1', 'tag2', 'tag3']) }
let(:send_request) do
- put :bulk_remove_tags, params: { ids: [product.id, product2.id], tags: ['tag1', 'tag2', 'tag3'] }, format: :turbo_stream
+ put :bulk_remove_tags, params: { ids: [product.id, product2.id], tags: ['tag1', 'tag2', 'tag3'] }
end
+ before { request.env['HTTP_REFERER'] = '/admin/products' }
+
it 'removes tags from products' do
send_request
expect(product.reload.tag_list).to eq([])
expect(product2.reload.tag_list).to eq([])
+ expect(response).to redirect_to('/admin/products')
end
end
@@ -1328,9 +1337,11 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
let!(:category3) { create(:taxon) }
let(:send_request) do
- put :bulk_remove_from_taxons, params: { ids: product_ids, taxon_ids: taxon_ids }, format: :turbo_stream
+ put :bulk_remove_from_taxons, params: { ids: product_ids, taxon_ids: taxon_ids }
end
+ before { request.env['HTTP_REFERER'] = '/admin/products' }
+
it { expect { send_request }.to change { product.reload.taxons } }
it 'unassigns the category properly' do
@@ -1432,9 +1443,11 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
let(:category) { create(:taxon) }
let(:send_request) do
- put :bulk_add_to_taxons, params: { ids: product_ids, taxon_ids: taxon_ids }, format: :turbo_stream
+ put :bulk_add_to_taxons, params: { ids: product_ids, taxon_ids: taxon_ids }
end
+ before { request.env['HTTP_REFERER'] = '/admin/products' }
+
it { expect { send_request }.to change { product.reload.taxons } }
it 'assigns the category properly' do
diff --git a/admin/spec/controllers/spree/admin/users_controller_spec.rb b/admin/spec/controllers/spree/admin/users_controller_spec.rb
index a8dc679ea8..84f6d6d70e 100644
--- a/admin/spec/controllers/spree/admin/users_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/users_controller_spec.rb
@@ -211,12 +211,15 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
let(:users) { create_list(:user, 3) }
let(:tags) { ['tag1', 'tag2'] }
+ before { request.env['HTTP_REFERER'] = '/admin/users' }
+
it 'adds tags to users' do
- post :bulk_add_tags, params: { ids: users.pluck(:id), tags: tags }, format: :turbo_stream
+ post :bulk_add_tags, params: { ids: users.pluck(:id), tags: tags }
users.each do |user|
expect(user.reload.tag_list).to contain_exactly(*tags)
end
+ expect(response).to redirect_to('/admin/users')
end
end
@@ -224,13 +227,16 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
let(:users) { create_list(:user, 3, tag_list: ['tag1', 'tag2']) }
let(:tags) { ['tag1', 'tag2'] }
+ before { request.env['HTTP_REFERER'] = '/admin/users' }
+
it 'removes tags from users' do
users.each { |user| user.update(tag_list: tags) }
- post :bulk_remove_tags, params: { ids: users.map(&:id), tags: tags }, format: :turbo_stream
+ post :bulk_remove_tags, params: { ids: users.map(&:id), tags: tags }
users.each do |user|
expect(user.reload.tag_list).to eq([])
end
+ expect(response).to redirect_to('/admin/users')
end
end