Class: Permission

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/permission.rb

Instance Method Summary collapse

Instance Method Details

#cache_condsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/permission.rb', line 18

def cache_conds
  cond_sql = "permission_name = ?"
  cond_objs = [permission]
  if person
    cond_sql += " and person_id = ?"
    cond_objs += [person.id]
  end
  if permissioned
    cond_sql += " and permissioned_type = ? and permissioned_id = ?"
    cond_objs += [permissioned.class.name, permissioned.id]
  end
  return [cond_sql] + cond_objs
end

#destroy_cachesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/permission.rb', line 42

def destroy_caches
  if AeUsers.cache_permissions?
    if person
      destroy_caches_for_person(person)
    elsif role
      role.members.each do |person|
        AeUsers.permission_cache.invalidate(person, permissioned, permission)
      end
    elsif permissioned and permission
      AeUsers.permission_cache.invalidate_all(:permissioned => permissioned, :permission => permission)
    else
      AeUsers.permission_cache.invalidate_all
    end
  end
end

#destroy_caches_for_person(p) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'app/models/permission.rb', line 32

def destroy_caches_for_person(p)
  if AeUsers.cache_permissions?
    if permissioned and permission
      AeUsers.permission_cache.invalidate(p, permissioned, permission)
    else
      AeUsers.permission_cache.invalidate_all(:person => p)
    end
  end
end

#granteeObject



10
11
12
13
14
15
16
# File 'app/models/permission.rb', line 10

def grantee
  if not role.nil?
    return role
  else
    return person
  end
end

#objectObject



6
7
8
# File 'app/models/permission.rb', line 6

def object
  return permissioned
end