Class: Lipsiadmin::AccessControl::Mapper

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/access_control/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#recognize_path

Constructor Details

#initialize(account, *roles, &block) ⇒ Mapper

:nodoc:



78
79
80
81
82
83
84
85
86
# File 'lib/access_control/base.rb', line 78

def initialize(, *roles, &block)#:nodoc:
  @project_modules = []
  @allowed         = []
  @denied          = []
  @roles           = roles
  @account_id      = .is_a?(Account) ? .id : 
  # Mantain backward compatibility
  yield(self, Account.find(@account_id)) rescue yield(self)
end

Instance Attribute Details

#project_modulesObject (readonly)

Returns the value of attribute project_modules.



76
77
78
# File 'lib/access_control/base.rb', line 76

def project_modules
  @project_modules
end

#rolesObject (readonly)

Returns the value of attribute roles.



76
77
78
# File 'lib/access_control/base.rb', line 76

def roles
  @roles
end

Instance Method Details

#allow_action(path) ⇒ Object

Globally allow an action of a controller for the current role



94
95
96
# File 'lib/access_control/base.rb', line 94

def allow_action(path)
  @allowed << recognize_path(path)
end

#allow_all_actions(path) ⇒ Object

Globally allow all actions from a controller for the current role



104
105
106
# File 'lib/access_control/base.rb', line 104

def allow_all_actions(path)
  @allowed << { :controller => recognize_path(path)[:controller] }
end

#allowedObject

Return allowed actions/controllers



119
120
121
122
123
124
125
126
127
# File 'lib/access_control/base.rb', line 119

def allowed
  # I know is a double check but is better 2 times that no one.
  if allowed?
    @project_modules.each { |pm| @allowed.concat pm.allowed  }
    @allowed.uniq
  else 
    []
  end
end

#allowed?Boolean

Return true if current_account role is included in given roles

Returns:

  • (Boolean)


114
115
116
# File 'lib/access_control/base.rb', line 114

def allowed?
  @roles.any? { |r| r.to_s.downcase == Account.find(@account_id).role.downcase }
end

#deniedObject

Return denied actions/controllers



130
131
132
# File 'lib/access_control/base.rb', line 130

def denied
  @denied.uniq
end

#deny_action(path) ⇒ Object

Globally deny an action of a controllerfor the current role



99
100
101
# File 'lib/access_control/base.rb', line 99

def deny_action(path)
  @denied << recognize_path(path)
end

#deny_all_actions(path) ⇒ Object

Globally denty all actions from a controller for the current role



109
110
111
# File 'lib/access_control/base.rb', line 109

def deny_all_actions(path)
  @denied << { :controller => recognize_path(path)[:controller] }
end

#project_module(name, controller = nil, &block) ⇒ Object

Create a new project module



89
90
91
# File 'lib/access_control/base.rb', line 89

def project_module(name, controller=nil, &block)
  @project_modules << ProjectModule.new(name, controller, &block)
end