Methods

Files

UbiquoAccessControl::AccessControl::ClassMethods

Public Instance Methods

access_control(actions={}) {|defaults| ...} click to toggle source

Function to regulate the required permissions for actions in a controller

Examples:

  for the key in "actions":
    access_control {
     :DEFAULT => ... # control all actions
     :index => .... #control index action
     [:new, :create] => .... #control new and create actions
    }

  for the value:
    - one permission
      access_control :DEFAULT => 'permission_key'
      access_control :DEFAULT => :permission_key

    - more permissions
      access_control :DEFAULT => ['permission_key_1', 'permission_key_2']
      access_control :DEFAULT => [:permission_key_1, :permission_key_2]
      access_control :DEFAULT => %w{permission_key_1 permission_key_2}

    - only admins
      access_control :DEFAULT => nil
    # File vendor/plugins/ubiquo_access_control/lib/ubiquo_access_control/access_control.rb, line 73
73:       def access_control(actions={})
74:         # Add class-wide permission callback to before_filter
75:         defaults = {}
76:         if block_given?
77:           yield defaults
78:           default_block_given = true
79:         end
80:         before_filter do |c|
81:           c.default_access_context = defaults if default_block_given
82:           @access = AccessSentry.new(c, actions)
83:           if @access.allowed?(c.action_name)
84:             c.send(:permission_granted)  if c.respond_to?:permission_granted
85:           else
86:             if c.respond_to?:permission_denied
87:               c.send(:permission_denied)
88:             else
89:               if File.exists?(Rails.root.join('public', '403.html'))
90:                 c.send(:render, {:file => Rails.root.join('public','403.html'),:status => 403})
91:               else
92:                 c.send(:render, { :text => "Access denied", :status => 403})
93:               end
94:             end
95:           end
96:         end
97:       end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.