Class: Merb::Controller
- Defined in:
- lib/role-authz/authorization/controller_mixin.rb
Defined Under Namespace
Classes: Unauthorized
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.authorize(klass, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/role-authz/authorization/controller_mixin.rb', line 10 def self.(klass, &block) klass.class_inheritable_accessor :_authorization_proxy klass. = self self. = klass self. ||= Authorization::ControllerHelper.new self..instance_eval(&block) if block_given? before :ensure_authorized self. end |
.role(name, &block) ⇒ Object
6 7 8 |
# File 'lib/role-authz/authorization/controller_mixin.rb', line 6 def self.role(name, &block) Authorization.add_role(name, &block) end |
Instance Method Details
#authorization_target ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/role-authz/authorization/controller_mixin.rb', line 20 def if .respond_to?(:get) .get(params[:id]) else nil end end |
#ensure_authorized ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/role-authz/authorization/controller_mixin.rb', line 28 def operator = (session.user if session.authenticated?) roles = Authorization.roles_for(operator, ) roles.each do |role| actions = self.class..actions_for(role) return true if actions.include?(params[:action].to_sym) || actions.include?(:all) end if session.authenticated? raise else raise Unauthenticated end end |