Module: LoginSystem::ClassMethods
- Defined in:
- lib/login_system.rb
Instance Method Summary collapse
- #controller_permissions ⇒ Object
- #login_required ⇒ Object
- #login_required? ⇒ Boolean
- #no_login_required ⇒ Object
- #only_allow_access_to(*args) ⇒ Object
- #user_has_access_to_action?(user, action, instance = new) ⇒ Boolean
Instance Method Details
#controller_permissions ⇒ Object
111 112 113 |
# File 'lib/login_system.rb', line 111 def @controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new } end |
#login_required ⇒ Object
95 96 97 98 99 |
# File 'lib/login_system.rb', line 95 def login_required unless login_required? prepend_before_filter :authenticate, :authorize end end |
#login_required? ⇒ Boolean
91 92 93 |
# File 'lib/login_system.rb', line 91 def login_required? filter_chain.any? {|f| f.method == :authenticate || f.method == :authorize } end |
#no_login_required ⇒ Object
86 87 88 89 |
# File 'lib/login_system.rb', line 86 def no_login_required skip_before_filter :authenticate skip_before_filter :authorize end |
#only_allow_access_to(*args) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/login_system.rb', line 101 def only_allow_access_to(*args) = {} = args.pop.dup if args.last.kind_of?(Hash) .symbolize_keys! actions = args.map { |a| a.to_s.intern } actions.each do |action| [action] = end end |
#user_has_access_to_action?(user, action, instance = new) ⇒ Boolean
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/login_system.rb', line 115 def user_has_access_to_action?(user, action, instance=new) = [action.to_s.intern] case when allowed_roles = [:when] allowed_roles = [allowed_roles].flatten allowed_roles.any? { |role| user.has_role?(role) } when condition_method = [:if] instance.send(condition_method) else true end end |