Sha256: 0333083cccf0be230d15a4b7b18e8e2b5454b2c8b40dcc46b0932892225ef3cc
Contents?: true
Size: 1.65 KB
Versions: 8
Compression:
Stored size: 1.65 KB
Contents
module Ixtlan module ActionController #:nodoc: module Guard #:nodoc: def self.included(base) base.send(:include, InstanceMethods) unless base.respond_to?(:groups_for_current_user) base.send(:include, GroupsMethod) end end module GroupsMethod protected def groups_for_current_user if current_user current_user.groups.collect do |group| group.name end else [] end end end module InstanceMethods #:nodoc: protected def guard Rails.application.config.guard end def check(flavor = nil, &block) unless guard.allowed?(params[:controller], params[:action], groups_for_current_user, flavor, block) if flavor raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{resource}##{action}##{flavor}'") else raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{resource}##{action}'") end end true end def authorization check end end end end module Allowed #:nodoc: # Inclusion hook to make #allowed available as method def self.included(base) base.send(:include, InstanceMethods) end module InstanceMethods #:nodoc: def allowed?(resource, action) controller.send(:guard).allowed?(controller, resource, action) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems