Module: LoginSystem::ClassMethods
- Defined in:
- lib/login_system.rb
Instance Method Summary collapse
- #controller_permissions ⇒ Object
- #login_required ⇒ Object
- #login_required? ⇒ Boolean
- #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_action :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 |
#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.is_a?(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 |
# File 'lib/login_system.rb', line 115 def user_has_access_to_action?(user, action, instance = new) = [action.to_s.intern] if allowed_roles = [:when] allowed_roles = [allowed_roles].flatten user.present? ? allowed_roles.any? { |role| user.role?(role) } : false elsif condition_method = [:if] instance.send(condition_method) else true end end |