Module: LoginSystem::ClassMethods

Defined in:
lib/login_system.rb

Instance Method Summary collapse

Instance Method Details

#controller_permissionsObject



114
115
116
# File 'lib/login_system.rb', line 114

def controller_permissions
  @controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new }
end

#login_requiredObject



98
99
100
101
102
# File 'lib/login_system.rb', line 98

def 
  unless 
    prepend_before_action :authenticate, :authorize
  end
end

#login_required?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/login_system.rb', line 94

def 
  filter_chain.any? {|f| f.method == :authenticate || f.method == :authorize }
end

#no_login_requiredObject



88
89
90
91
92
# File 'lib/login_system.rb', line 88

def 
  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)
  options = {}
  options = args.pop.dup if args.last.kind_of?(Hash)
  options.symbolize_keys!
  actions = args.map { |a| a.to_s.intern }
  actions.each do |action|
    controller_permissions[action] = options
  end
end

#user_has_access_to_action?(user, action, instance = new) ⇒ Boolean

Returns:

  • (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)
  permissions = controller_permissions[action.to_s.intern]
  case
  when allowed_roles = permissions[:when]
    allowed_roles = [allowed_roles].flatten
    user.present? ? allowed_roles.any? { |role| user.has_role?(role) } : false
  when condition_method = permissions[:if]
    instance.send(condition_method)
  else
    true
  end
end