system_data.rb
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'User'
require 'Group'
require 'Site'
require 'MailAliasRole'
require 'MailAliasPerson'
require 'MailAccount'
class SystemDataBackend
def initialize(backend)
@backend = backend
@data = Hash.new
end
def users
load(:User)
end
def groups
load(:Group)
end
def sites
load(:Site)
end
def mailAliasRoles
load(:MailAliasRole)
end
def mailAliasPeople
load(:MailAliasPerson)
end
def mailAccounts
load(:MailAccount)
end
def userByName(name)
users.find{|user| user.name == name}
end
def groupByName(name)
groups.find{|group| group.name == name}
end
def siteByName(name)
sites.find{|site| site.name == name}
end
def usersInGroup(group)
case
when group.members.instance_of?(Array):
Hash[group.members.map{|uid| [uid, userByName(uid)] if userByName(uid)}]
when goup.members.nil?:
{}
else
{group.members => userByName(group.members)} if userByName(group.members)
end
end
def mailAliasRolesBySite(site)
mailAliasRoles.find_all{|mail| mail.site == site.name}
end
def mailAliasPeopleBySite(site)
mailAliasPeople.find_all{|mail| mail.site == site.name}
end
def mailAccountsBySite(site)
mailAccounts.find_all{|mail| mail.site == site.name}
end
private
def load(kind)
load!(kind) if ! @data[kind]
@data[kind]
end
def load!(kind)
@data[kind] = Array.new
@backend.load(kind) do |data|
data[:backend] = @backend
@data[kind].push(
eval(kind.to_s + '.new(data)')
)
end
end
end