Module: Gluttonberg::Authorizable::ClassMethods

Defined in:
lib/gluttonberg/authorizable.rb

Instance Method Summary collapse

Instance Method Details

#all_for_user(user, options = {}) ⇒ Object

Returns all matching records that are authorize to provided user. For Super admin users returns all records For other non-super-users checks th condition of user_id May be called with additional conditions.



23
24
25
26
27
28
29
30
# File 'lib/gluttonberg/authorizable.rb', line 23

def all_for_user(user , options = {})
  if user.is_super_admin
    all(options)
  else
    options[:user_id] = user.id
    all(options)
  end
end

#get_for_user(user, id) ⇒ Object

Returns first matching records that is authorize to provided user with given id. For Super admin users it checks only id but for non-super-users checks additionally it checks condition of user_id



35
36
37
38
39
40
41
42
43
# File 'lib/gluttonberg/authorizable.rb', line 35

def get_for_user(user , id)
  options = {:id => id }
  if user.is_super_admin            
    first(options)
  else
    options[:user_id] = user.id
    first(options)
  end
end