lib/trust/controller.rb
# Tests for current users permissions.
#
# If access control is not sufficient in controller, you may use this method.
# Also available as a helper in views.
#
# ==== Examples
#   +can? :edit+                          # does the current user have permission to edit the current resource?
#                                         # If there is a nested resource, the parent is automatically associated
#   +can? :edit, @customer+               # does the current user have permission to edit the given customer?
#                                         # Parent is also passed on here.
#   +can? :edit, @account, @client+       # is current user allowed to edit the account associated with the client?
#def can?(action_name, subject = resource.instance || resource.relation.new, parent = resource.parent)
Tests for current users permissions.
If access control is not sufficient in controller, you may use this method.
Also available as a helper in views.

Examples
+can. :edit+                          # does the current user have permission to edit the current resource.
If there is a nested resource, the parent is automatically associated
+can. :edit, @customer+               # does the current user have permission to edit the given customer.
Parent is also passed on here.
+can. :edit, @account, @client+       # is current user allowed to edit the account associated with the client.
Tests for current users permissions . If access control is not sufficient in controller you may use this method . Also available as a helper in views . Examples + can . : edit + # does the current user have permission to edit the current resource . If there is a nested resource the parent is automatically associated + can . : edit @customer + # does the current user have permission to edit the given customer . Parent is also passed on here . + can . : edit @account @client + # is current user allowed to edit the account associated with the client .
def can?(action_name, subject = nil, parent = nil)
        parent ||= resource.parent
        subject ||= case properties.action_type(action_name)
        when :collection
          resource.klass
        when :member
          resource.instance || resource.klass 
        when :new
          resource.relation
        end
        @trust_cache ||= {}
        @trust_cache[[action_name, subject, parent]] ||= !!Trust::Authorization.authorized?(action_name, subject, parent)
         = !!Trust::Authorization.authorized?(action_name, subject, parent)
      end
def can? ( action_name , subject = nil , parent = nil ) parent ||= resource . parent subject ||= case properties . action_type ( action_name ) when :collection resource . klass when :member resource . instance || resource . klass when :new resource . relation end @trust_cache ||= { } @trust_cache [ [ action_name , subject , parent ] ] ||= ! ! Trust :: Authorization . authorized? ( action_name , subject , parent ) end
Tests for current users permissions.
Tests for current users permissions .
# default back to class if no instance # if @trust_cache.has_key? [action_name, subject, parent] #   Rails.logger.debug "Authorisation from cache: #{action_name} #{subject.is_a?(Class) ? subject.to_s : subject.cache_key} #{parent && parent.cache_key}" #   @trust_cache[[action_name, subject, parent]] # else #   Rails.logger.debug "Authorisation load: #{action_name} #{subject.is_a?(Class) ? subject.to_s : subject.cache_key} #{parent && parent.cache_key}" #   @trust_cache[[action_name, subject, parent]] = !!Trust::Authorization.authorized?(action_name, subject, parent) # end
action_name
subject
parent