Skip to content

Commit

Permalink
Remove Spree::Alert.
Browse files Browse the repository at this point in the history
The initial intent of Spree::Alert was to push notifications from Spree Commerce
to store owners when there were security alerts or new versions released.
This functionality hasn't been used much though in the past several years
with only a couple alerts issued for security updates.  The implementation
was simply sticking the alerts in admin cookies, and has now taken up too much
space causing CookieOverflow errors.  Since this feature isn't really being used,
and most developers rather follow the https://groups.google.com/forum/#!forum/spree-user
mailing list or the Spree Commerce blog & twitter accounts we're just going to
remove it and shut down the alerts.spreecommerce.com service.

Fixes #6465
Fixes #6516
  • Loading branch information
Jeff Dutil authored and Jeff Dutil committed Sep 10, 2015
1 parent ef635b9 commit d9bd194
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 253 deletions.
120 changes: 45 additions & 75 deletions backend/app/controllers/spree/admin/base_controller.rb
Expand Up @@ -7,92 +7,62 @@ class BaseController < Spree::BaseController
helper 'spree/admin/tables'
layout '/spree/layouts/admin'

before_action :check_alerts
before_action :authorize_admin

protected

def action
params[:action].to_sym
end

def authorize_admin
if respond_to?(:model_class, true) && model_class
record = model_class
else
record = controller_name.to_sym
end
authorize! :admin, record
authorize! action, record
end

# Need to generate an API key for a user due to some backend actions
# requiring authentication to the Spree API
def generate_admin_api_key
if (user = try_spree_current_user) && user.spree_api_key.blank?
user.generate_spree_api_key!
end
end

def check_alerts
return unless should_check_alerts?
unless session.has_key? :alerts
session[:alerts] = Spree::Alert.current(request.host)
filter_dismissed_alerts
Spree::Config.set :last_check_for_spree_alerts => DateTime.now.to_s
end
end

def should_check_alerts?
return false if !Rails.env.production? || !Spree::Config[:check_for_spree_alerts]
def action
params[:action].to_sym
end

last_check = Spree::Config[:last_check_for_spree_alerts]
return true if last_check.blank?

DateTime.parse(last_check) < 12.hours.ago
end

def flash_message_for(object, event_sym)
resource_desc = object.class.model_name.human
resource_desc += " \"#{object.name}\"" if object.respond_to?(:name) && object.name.present?
Spree.t(event_sym, :resource => resource_desc)
end

def render_js_for_destroy
render :partial => '/spree/admin/shared/destroy'
def authorize_admin
if respond_to?(:model_class, true) && model_class
record = model_class
else
record = controller_name.to_sym
end

# Index request for JSON needs to pass a CSRF token in order to prevent JSON Hijacking
def check_json_authenticity
return unless request.format.js? or request.format.json?
return unless protect_against_forgery?
auth_token = params[request_forgery_protection_token]
unless (auth_token and form_authenticity_token == URI.unescape(auth_token))
raise(ActionController::InvalidAuthenticityToken)
end
authorize! :admin, record
authorize! action, record
end

# Need to generate an API key for a user due to some backend actions
# requiring authentication to the Spree API
def generate_admin_api_key
if (user = try_spree_current_user) && user.spree_api_key.blank?
user.generate_spree_api_key!
end

def filter_dismissed_alerts
return unless session[:alerts]
dismissed = (Spree::Config[:dismissed_spree_alerts] || '').split(',')
# If it's a string, something has gone wrong with the alerts service. Ignore it.
if session[:alerts].is_a?(String)
session[:alerts] = nil
else
session[:alerts].reject! { |a| dismissed.include? a["id"].to_s }
end
end

def flash_message_for(object, event_sym)
resource_desc = object.class.model_name.human
resource_desc += " \"#{object.name}\"" if object.respond_to?(:name) && object.name.present?
Spree.t(event_sym, resource: resource_desc)
end

def render_js_for_destroy
render partial: '/spree/admin/shared/destroy'
end

# Index request for JSON needs to pass a CSRF token in order to prevent JSON Hijacking
def check_json_authenticity
return unless request.format.js? || request.format.json?
return unless protect_against_forgery?
auth_token = params[request_forgery_protection_token]
unless auth_token && form_authenticity_token == URI.unescape(auth_token)
raise(ActionController::InvalidAuthenticityToken)
end
end

def config_locale
Spree::Backend::Config[:locale]
end
def config_locale
Spree::Backend::Config[:locale]
end

def can_not_transition_without_customer_info
unless @order.billing_address.present?
flash[:notice] = Spree.t(:fill_in_customer_info)
redirect_to edit_admin_order_customer_url(@order)
end
def can_not_transition_without_customer_info
unless @order.billing_address.present?
flash[:notice] = Spree.t(:fill_in_customer_info)
redirect_to edit_admin_order_customer_url(@order)
end
end
end
end
end
Expand Up @@ -6,9 +6,7 @@ class GeneralSettingsController < Spree::Admin::BaseController
before_action :set_store

def edit
@preferences_security = [:allow_ssl_in_production,
:allow_ssl_in_staging, :allow_ssl_in_development_and_test,
:check_for_spree_alerts]
@preferences_security = [:allow_ssl_in_production, :allow_ssl_in_staging, :allow_ssl_in_development_and_test]
@preferences_currency = [:display_currency, :hide_cents]
end

Expand All @@ -24,15 +22,6 @@ def update
redirect_to edit_admin_general_settings_path
end

def dismiss_alert
if request.xhr? and params[:alert_id]
dismissed = Spree::Config[:dismissed_spree_alerts] || ''
Spree::Config.set dismissed_spree_alerts: dismissed.split(',').push(params[:alert_id]).join(',')
filter_dismissed_alerts
render nothing: true
end
end

def clear_cache
Rails.cache.clear
invoke_callbacks(:clear_cache, :after)
Expand Down
5 changes: 0 additions & 5 deletions backend/app/views/spree/admin/shared/_alert.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions backend/app/views/spree/layouts/admin.html.erb
Expand Up @@ -28,8 +28,6 @@
</div>
</div>

<%= render :partial => 'spree/admin/shared/alert', :collection => session[:alerts] %>
<%= render :partial => 'spree/admin/shared/header' %>
<%= render :partial => 'spree/admin/shared/menu' %>
<%= render :partial => 'spree/admin/shared/sub_menu' %>
Expand Down
1 change: 0 additions & 1 deletion backend/config/routes.rb
Expand Up @@ -112,7 +112,6 @@

resource :general_settings do
collection do
post :dismiss_alert
post :clear_cache
end
end
Expand Down
25 changes: 0 additions & 25 deletions backend/spec/controllers/spree/admin/alerts_spec.rb

This file was deleted.

42 changes: 2 additions & 40 deletions backend/spec/controllers/spree/admin/base_controller_spec.rb
Expand Up @@ -3,11 +3,11 @@
# we call process directly instead of get
require 'spec_helper'

describe Spree::Admin::BaseController, :type => :controller do
describe Spree::Admin::BaseController, type: :controller do
controller(Spree::Admin::BaseController) do
def index
authorize! :update, Spree::Order
render :text => 'test'
render text: 'test'
end
end

Expand All @@ -22,42 +22,4 @@ def index
expect(response).to redirect_to '/root'
end
end

describe "check alerts" do
stub_authorization!

it "checks alerts with before_filter" do
expect(controller).to receive :check_alerts
process :index
end

it "saves alerts into session" do
allow(controller).to receive_messages(:should_check_alerts? => true)
expect(Spree::Alert).to receive(:current).and_return([{"id" => "1", "message" => "test alert", "severity" => 'release'}])
process :index
expect(session[:alerts].first["message"]).to eq "test alert"
end

describe "should_check_alerts?" do
before do
allow(Rails.env).to receive_messages(:production? => true)
Spree::Config[:check_for_spree_alerts] = true
Spree::Config[:last_check_for_spree_alerts] = nil
end

it "only checks alerts if production and preference is true" do
expect(controller.send(:should_check_alerts?)).to be true
end

it "only checks for production" do
allow(Rails.env).to receive_messages(:production? => false)
expect(controller.send(:should_check_alerts?)).to be false
end

it "only checks if preference is true" do
Spree::Config[:check_for_spree_alerts] = false
expect(controller.send(:should_check_alerts?)).to be false
end
end
end
end
17 changes: 0 additions & 17 deletions core/app/models/spree/alert.rb

This file was deleted.

3 changes: 0 additions & 3 deletions core/app/models/spree/app_configuration.rb
Expand Up @@ -36,7 +36,6 @@ class AppConfiguration < Preferences::Configuration
preference :auto_capture, :boolean, default: false # automatically capture the credit card (as opposed to just authorize and capture later)
preference :auto_capture_on_dispatch, :boolean, default: false # Captures payment for each shipment in Shipment#after_ship callback, and makes Shipment.ready when payment authorized.
preference :binary_inventory_cache, :boolean, default: false # only invalidate product cache when a stock item changes whether it is in_stock
preference :check_for_spree_alerts, :boolean, default: false
preference :checkout_zone, :string, default: nil # replace with the name of a zone if you would like to limit the countries
preference :company, :boolean, default: false # Request company field for billing and shipping addr
preference :currency, :string, default: "USD"
Expand All @@ -46,11 +45,9 @@ class AppConfiguration < Preferences::Configuration
preference :currency_thousands_separator, :string, default: ","
preference :display_currency, :boolean, default: false
preference :default_country_id, :integer
preference :dismissed_spree_alerts, :string, default: ''
preference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.
preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being charged
preference :hide_cents, :boolean, default: false
preference :last_check_for_spree_alerts, :string, default: nil
preference :layout, :string, default: 'spree/layouts/spree_application'
preference :logo, :string, default: 'logo/spree_50.png'
preference :max_level_in_taxons_menu, :integer, default: 1 # maximum nesting level in taxons menu
Expand Down
1 change: 0 additions & 1 deletion core/config/locales/en.yml
Expand Up @@ -525,7 +525,6 @@ en:
categories: Categories
category: Category
charged: Charged
check_for_spree_alerts: Check for Spree alerts
checkout: Checkout
choose_a_customer: Choose a customer
choose_a_taxon_to_sort_products_for: "Choose a taxon to sort products for"
Expand Down
16 changes: 0 additions & 16 deletions core/spec/fixtures/alerts.json

This file was deleted.

33 changes: 0 additions & 33 deletions core/spec/models/spree/alert_spec.rb

This file was deleted.

1 change: 0 additions & 1 deletion core/spree_core.gemspec
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |s|
s.add_dependency 'font-awesome-rails', '~> 4.0'
s.add_dependency 'friendly_id', '~> 5.0.4'
s.add_dependency 'highline', '~> 1.6.18' # Necessary for the install generator
s.add_dependency 'httparty', '~> 0.11' # For checking alerts.
s.add_dependency 'json', '~> 1.7'
s.add_dependency 'kaminari', '~> 0.15', '>= 0.15.1'
s.add_dependency 'monetize', '~> 1.1'
Expand Down
8 changes: 0 additions & 8 deletions guides/content/developer/core/preferences.md
Expand Up @@ -412,14 +412,6 @@ Determines whether or not a currency is displayed with a price. Defaults to `fal

The default country's id. Defaults to 214, as this is the id for the United States within the seed data.

`dismissed_spree_alerts`

The list of alert IDs that you have dismissed.

`last_check_for_spree_alerts`

Stores the last time that alerts were checked for. Alerts are checked for every 12 hours.

`layout`

The path to the layout of your application, relative to the `app/views` directory. Defaults to `spree/layouts/spree_application`. To make Spree use your application's layout rather than Spree's default, use this:
Expand Down

0 comments on commit d9bd194

Please sign in to comment.