Sha256: 65f11c1d6d2daf7a3b2a54eee354f5f99bbdffa1739eef3202cd17cf64035041
Contents?: true
Size: 818 Bytes
Versions: 5
Compression:
Stored size: 818 Bytes
Contents
# frozen_string_literal: true module SolidusAdmin::ControllerHelpers::Authorization extend ActiveSupport::Concern included do before_action :authorize_solidus_admin_user! rescue_from CanCan::AccessDenied do render 'unauthorized', status: :forbidden end end private def current_ability @current_ability ||= Spree::Ability.new(current_solidus_admin_user) end def authorize_solidus_admin_user! subject = authorization_subject authorize! :admin, subject authorize! action_name.to_sym, subject end def authorization_subject "Spree::#{controller_name.classify}".constantize rescue NameError raise NotImplementedError, "Couldn't infer the model class from the controller name, " \ "please implement `#{self.class}#authorization_subject`." end end
Version data entries
5 entries across 5 versions & 1 rubygems