From 9ead23ff6bc9e2ed017397968014f11956063355 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 20 Jun 2016 13:22:53 -0700 Subject: [PATCH] Remove clear cache button from admin Our existing "General Settings" page has a "Clear cache" button. On stores I've worked on I wouldn't want this exposed to admins. We should (and afaik we do) expire caches every time the underlying DB object is changed. This is motivated partly because I want to replace the GeneralSettingsController with a StoreController, and this is the only thing on that page that doesn't directly relate to a store. --- CHANGELOG.md | 2 + .../spree/backend/general_settings.js.coffee | 13 ------ .../javascripts/spree/backend/routes.js | 1 - .../admin/general_settings_controller.rb | 6 --- .../admin/general_settings/edit.html.erb | 16 -------- backend/config/routes.rb | 6 +-- .../admin/general_settings_controller_spec.rb | 41 ------------------- .../configuration/general_settings_spec.rb | 11 ----- 8 files changed, 3 insertions(+), 93 deletions(-) delete mode 100644 backend/app/assets/javascripts/spree/backend/general_settings.js.coffee delete mode 100644 backend/spec/controllers/spree/admin/general_settings_controller_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 30cfa238842..b408786e8c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ * Remove unused `user_id` column from PromotionRule. [#1259](https://github.com/solidusio/solidus/pull/1259) +* Removed "Clear cache" button from the admin [#1275](https://github.com/solidusio/solidus/pull/1275) + ## Solidus 1.3.0 (unreleased) * Order now requires a `store_id` in validations diff --git a/backend/app/assets/javascripts/spree/backend/general_settings.js.coffee b/backend/app/assets/javascripts/spree/backend/general_settings.js.coffee deleted file mode 100644 index fbbec7e49e9..00000000000 --- a/backend/app/assets/javascripts/spree/backend/general_settings.js.coffee +++ /dev/null @@ -1,13 +0,0 @@ -$(@).ready( -> - $('[data-hook=general_settings_clear_cache] #clear_cache').click -> - $.ajax - type: 'POST' - url: Spree.routes.clear_cache - success: -> - show_flash 'success', "Cache was flushed." - error: (msg) -> - if msg.responseJSON["error"] - show_flash 'error', msg.responseJSON["error"] - else - show_flash 'error', "There was a problem while flushing cache." -) diff --git a/backend/app/assets/javascripts/spree/backend/routes.js b/backend/app/assets/javascripts/spree/backend/routes.js index 7bf9d166015..758bfc04305 100644 --- a/backend/app/assets/javascripts/spree/backend/routes.js +++ b/backend/app/assets/javascripts/spree/backend/routes.js @@ -1,6 +1,5 @@ Spree.routes.checkouts_api = Spree.pathFor('api/checkouts') Spree.routes.classifications_api = Spree.pathFor('api/classifications') -Spree.routes.clear_cache = Spree.pathFor('admin/general_settings/clear_cache') Spree.routes.option_value_search = Spree.pathFor('api/option_values') Spree.routes.option_type_search = Spree.pathFor('api/option_types') Spree.routes.orders_api = Spree.pathFor('api/orders') diff --git a/backend/app/controllers/spree/admin/general_settings_controller.rb b/backend/app/controllers/spree/admin/general_settings_controller.rb index 960a5e4a023..66efd94617e 100644 --- a/backend/app/controllers/spree/admin/general_settings_controller.rb +++ b/backend/app/controllers/spree/admin/general_settings_controller.rb @@ -17,12 +17,6 @@ def update end end - def clear_cache - Rails.cache.clear - invoke_callbacks(:clear_cache, :after) - head :no_content - end - private def store_params diff --git a/backend/app/views/spree/admin/general_settings/edit.html.erb b/backend/app/views/spree/admin/general_settings/edit.html.erb index 28ccbbfaefc..4d3bca58c3b 100644 --- a/backend/app/views/spree/admin/general_settings/edit.html.erb +++ b/backend/app/views/spree/admin/general_settings/edit.html.erb @@ -59,22 +59,6 @@ <% end %> - <% if can? :clear_cache, :general_settings %> -
-
-
- <%= Spree.t(:clear_cache)%> -
- <%= Spree.t(:clear_cache_warning) %> -
-
- <%= button Spree.t(:clear_cache), '', 'button', id: "clear_cache" %> -
-
-
-
- <% end %> - <% if can? :update, :general_settings %>
<%= button Spree.t('actions.update'), 'refresh' %> diff --git a/backend/config/routes.rb b/backend/config/routes.rb index 2ed06aefce1..4c8f014edf8 100644 --- a/backend/config/routes.rb +++ b/backend/config/routes.rb @@ -130,11 +130,7 @@ end end - resource :general_settings, only: [:edit, :update] do - collection do - post :clear_cache - end - end + resource :general_settings, only: [:edit, :update] resources :return_items, only: [:update] diff --git a/backend/spec/controllers/spree/admin/general_settings_controller_spec.rb b/backend/spec/controllers/spree/admin/general_settings_controller_spec.rb deleted file mode 100644 index 56082b9641b..00000000000 --- a/backend/spec/controllers/spree/admin/general_settings_controller_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'spec_helper' - -describe Spree::Admin::GeneralSettingsController, type: :controller do - let(:user) { create(:user) } - - before do - allow(controller).to receive_messages spree_current_user: user - user.spree_roles << Spree::Role.find_or_create_by(name: 'admin') - end - - describe '#clear_cache' do - subject { spree_post :clear_cache } - - shared_examples 'a HTTP 204 response' do - it 'grant access to users with an admin role' do - subject - expect(response.status).to eq(204) - end - end - - context 'when no callback' do - it_behaves_like 'a HTTP 204 response' - end - - context 'when callback implemented' do - Spree::Admin::GeneralSettingsController.class_eval do - custom_callback(:clear_cache).after :foo - - def foo - # Make a call to Akamai, CloudFlare, etc invalidation.... - end - end - - before do - expect(controller).to receive(:foo).once - end - - it_behaves_like 'a HTTP 204 response' - end - end -end diff --git a/backend/spec/features/admin/configuration/general_settings_spec.rb b/backend/spec/features/admin/configuration/general_settings_spec.rb index 20f961a46ba..7bd11d84825 100644 --- a/backend/spec/features/admin/configuration/general_settings_spec.rb +++ b/backend/spec/features/admin/configuration/general_settings_spec.rb @@ -44,15 +44,4 @@ expect(page).to have_field("Site Name", with: "") end end - - context "clearing the cache" do - it "should clear the cache" do - expect(page).to_not have_content(Spree.t(:clear_cache_ok)) - expect(page).to have_content(Spree.t(:clear_cache_warning)) - - click_button "Clear Cache" - - expect(page).to have_content(Spree.t(:clear_cache_ok)) - end - end end