Module: LoginSystem::ClassMethods
- Defined in:
- lib/login_system.rb
Instance Method Summary collapse
- #controller_permissions ⇒ Object
- #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
55 56 57 |
# File 'lib/login_system.rb', line 55 def @controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new } end |
#no_login_required ⇒ Object
40 41 42 43 |
# File 'lib/login_system.rb', line 40 def no_login_required # skip_before_filter :authenticate_user # Not working in some systems end |
#only_allow_access_to(*args) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/login_system.rb', line 45 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/login_system.rb', line 59 def user_has_access_to_action?(user, action, instance=new) result = false = [action.to_s.intern] case when [:when].present? allowed_roles = [[:when]].flatten # We no longer have an admin role, if it's in there replace it with administrator allowed_roles.map! { |role| role == :admin ? :administrator : role } result = allowed_roles.include? user.class_name.downcase.to_sym when [:if].present? result = instance.send([:if]) else result = [:administrator,:designer,:user].include? user.class_name.downcase.to_sym end return result end |