Sha256: 7d3aefbc806f6e047fd238cc3fffb3d5ba7e8c2789c497e3a75dc76f5a7421ee
Contents?: true
Size: 1.13 KB
Versions: 17
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true module Plutonium module Core module Controllers module Authorizable extend ActiveSupport::Concern include ActionPolicy::Controller included do authorize :user, through: :current_user authorize :entity_scope, through: :entity_scope_for_authorize helper_method :policy_for, :authorized_resource_scope end private def authorized_resource_scope(resource, **options) raise ArgumentError("Expected resource to be a class inheriting ActiveRecord::Base") unless resource.instance_of?(Class) && resource < ActiveRecord::Base options[:with] ||= ActionPolicy.lookup(resource, namespace: authorization_namespace) resource = resource.all authorized_scope(resource, **options) end def entity_scope_for_authorize current_scoped_entity if scoped_to_entity? end def verify_authorized # we don't use action policy's inbuilt checks, so ensure they are neutered, # also ensures pundit checks are disabled. end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems