Sha256: 5b2750708b65cf8d390afcedf72ad4aaf7c6bfe9e5f9e1fbf8b874598f783f27

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

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

      before_action :authorize_admin

      private

      # Overrides ControllerHelpers::Common
      # We want the admin's locale selection to be different than that on the frontend
      def set_user_language_locale_key
        :admin_locale
      end

      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

      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?
        t(event_sym, resource: resource_desc, scope: 'spree')
      end

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

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

      def lock_order
        Spree::OrderMutex.with_lock!(@order) { yield }
      rescue Spree::OrderMutex::LockFailed
        flash[:error] = t('spree.order_mutex_admin_error')
        redirect_to order_mutex_redirect_path
      end

      def order_mutex_redirect_path
        edit_admin_order_path(@order)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_backend_devise_token_auth-2.8.0.alpha.14 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.13 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.12 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.11 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.10 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.9 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.8 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.7 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.6 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.5 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.4 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.3 app/controllers/spree/admin/base_controller.rb
solidus_backend_devise_token_auth-2.8.0.alpha.2 app/controllers/spree/admin/base_controller.rb