Sha256: 17485c9508b294ede574da9f998bf6ae21190e0b0ec2f043283da49a63188c9c

Contents?: true

Size: 1.55 KB

Versions: 39

Compression:

Stored size: 1.55 KB

Contents

module Spree
  module Admin
    class BaseController < Spree::BaseController
      helper 'spree/admin/navigation'
      layout 'spree/layouts/admin'

      before_action :authorize_admin
      before_action :generate_admin_api_key

      protected

      def action
        params[:action].to_sym
      end

      def authorize_admin
        record = if respond_to?(:model_class, true) && model_class
                   model_class
                 else
                   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 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

      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
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
spree_backend-4.0.9 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.15 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.14 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.8 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.13.1 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.7.1 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.7 app/controllers/spree/admin/base_controller.rb
spree_backend-4.2.0.rc4 app/controllers/spree/admin/base_controller.rb
spree_backend-4.2.0.rc3 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.13 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.6 app/controllers/spree/admin/base_controller.rb
spree_backend-4.2.0.rc2 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.5 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.12 app/controllers/spree/admin/base_controller.rb
spree_backend-4.2.0.rc1 app/controllers/spree/admin/base_controller.rb
spree_backend-4.0.4 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.11 app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.10 app/controllers/spree/admin/base_controller.rb
spree_backend-4.2.0.beta app/controllers/spree/admin/base_controller.rb
spree_backend-4.1.9 app/controllers/spree/admin/base_controller.rb