Module: ACLSystem2::AccessControl::ClassMethods

Defined in:
lib/acl_system2/access_control/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#access_control(actions = {}) ⇒ Object

access_control [:create, :edit] => ‘admin & !blacklist’,

:update => '(admin | moderator) & !blacklist',
:list => '(admin | moderator | user) & !blacklist'


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acl_system2/access_control/class_methods.rb', line 7

def access_control(actions = {})
  # Add class-wide permission callback to before_filter
  defaults = {}

  if block_given?
    yield defaults
    default_block_given = true
  end

  before_filter do |c|
    c.default_access_context = defaults if default_block_given
    @access = AccessSentry.new(c, actions)

    if @access.allowed?(c.action_name)
       c.send(:permission_granted) if c.respond_to?:permission_granted
    else
      if c.respond_to?(:permission_denied)
        c.send(:permission_denied)
      else
        c.send(:render, :text => "You have insuffient permissions to access #{ c.controller_name }/#{ c.action_name }")
      end
    end
  end

end