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
114 115 116 |
# File 'lib/login_system.rb', line 114 def @controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new } end |
#login_required ⇒ Object
98 99 100 101 102 |
# File 'lib/login_system.rb', line 98 def login_required unless login_required? prepend_before_action :authenticate, :authorize end end |
#login_required? ⇒ Boolean
94 95 96 |
# File 'lib/login_system.rb', line 94 def login_required? filter_chain.any? {|f| f.method == :authenticate || f.method == :authorize } end |
#no_login_required ⇒ Object
88 89 90 91 92 |
# File 'lib/login_system.rb', line 88 def no_login_required skip_before_action :authenticate skip_before_action :authorize # puts _process_action_callbacks.map(&:filter) end |
#only_allow_access_to(*args) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/login_system.rb', line 104 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
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/login_system.rb', line 118 def user_has_access_to_action?(user, action, instance=new) = [action.to_s.intern] case when allowed_roles = [:when] allowed_roles = [allowed_roles].flatten user.present? ? allowed_roles.any? { |role| user.has_role?(role) } : false when condition_method = [:if] instance.send(condition_method) else true end end |