Sha256: e17adf2c6490253c906f42771e9c7cc35b133330da28b1a2961a7d9017c6fbec

Contents?: true

Size: 794 Bytes

Versions: 1

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

module Authorizy
  module Extension
    extend ::ActiveSupport::Concern

    included do
      helper_method(:authorizy?)

      def authorizy
        return if Authorizy::Core.new(authorizy_user, params, session).access?

        info = I18n.t('authorizy.denied', action: params[:action], controller: params[:controller])

        return render(json: { message: info }, status: 422) if request.xhr?

        redirect_to Authorizy.config.redirect_url.call(self), info: info
      end

      def authorizy?(controller, action)
        Authorizy::Core.new(authorizy_user, params, session, action: action, controller: controller).access?
      end

      private

      def authorizy_user
        Authorizy.config.current_user.call(self)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authorizy-0.1.0 lib/authorizy/extension.rb