This repository has been archived by the owner on Mar 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
privilege_granter.rb
160 lines (128 loc) · 3.65 KB
/
privilege_granter.rb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
module PrivilegeGranter
def self.unit_specific_privilege_groups
[:computers, :computer_groups, :bundles, :user_groups, :packages, :permissions]
end
# ===================
# = Computer Groups =
# ===================
def read_computer_groups(unit_ids)
can :read, ComputerGroup, :unit_id => unit_ids
end
def modify_computer_groups(unit_ids)
can [:update, :environment_change], ComputerGroup, :unit_id => unit_ids
end
def create_computer_groups(unit_ids)
can :create, ComputerGroup, :unit_id => unit_ids
end
def destroy_computer_groups(unit_ids)
can :destroy, ComputerGroup, :unit_id => unit_ids
end
# ===========
# = Bundles =
# ===========
def read_bundles(unit_ids)
can :read, Bundle, :unit_id => unit_ids
end
def modify_bundles(unit_ids)
can [:update, :environment_change], Bundle, :unit_id => unit_ids
end
def create_bundles(unit_ids)
can :create, Bundle, :unit_id => unit_ids
end
def destroy_bundles(unit_ids)
can :destroy, Bundle, :unit_id => unit_ids
end
# =============
# = Computers =
# =============
def read_computers(unit_ids)
can [:read, :client_prefs, :download, :update_warranty], Computer, :unit_id => unit_ids
can :read, ManagedInstallReport
end
def modify_computers(unit_ids)
can [:update, :edit_multiple, :update_multiple, :environment_change], Computer, :unit_id => unit_ids
end
def create_computers(unit_ids)
can [:create, :import, :create_import], Computer, :unit_id => unit_ids
end
def destroy_computers(unit_ids)
can :destroy, Computer, :unit_id => unit_ids
end
# ============
# = Packages =
# ============
def read_packages(unit_ids)
can [:read, :download, :check_for_updates, :index_shared], Package, :unit_id => unit_ids
can [:read], PackageBranch, :unit_id => unit_ids
end
def modify_packages(unit_ids)
can [:update, :environment_change, :edit_multiple, :update_multiple], Package, :unit_id => unit_ids
can [:update], PackageBranch, :unit_id => unit_ids
end
def create_packages(unit_ids)
can [:create, :import_shared, :import_multiple_shared], Package, :unit_id => unit_ids
end
def destroy_packages(unit_ids)
can :destroy, Package, :unit_id => unit_ids
end
# ===============
# = Permissions =
# ===============
def read_permissions(unit_ids)
can [:read, :edit], Permission, :unit_id => unit_ids
end
def modify_permissions(unit_ids)
can [:update, :destroy], Permission, :unit_id => unit_ids
end
def read_system_permissions(unit_ids)
can [:read, :edit], Permission, :unit_id => nil
end
def modify_system_permissions(unit_ids)
can [:update, :destroy], Permission, :unit_id => nil
end
# =========
# = Users =
# =========
def read_users(unit_ids)
can :read, User
end
def modify_users(unit_ids)
can :update, User
end
def create_users(unit_ids)
can :create, User
end
def destroy_users(unit_ids)
can :destroy, User
end
# =========
# = Units =
# =========
def read_units(unit_ids)
can :read, Unit
end
def modify_units(unit_ids)
can :update, Unit
end
def create_units(unit_ids)
can :create, Unit
end
def destroy_units(unit_ids)
can :destroy, Unit
end
# ===============
# = User Groups =
# ===============
def read_user_groups(unit_ids)
can :read, UserGroup, :unit_id => unit_ids
end
def modify_user_groups(unit_ids)
can [:update, :environment_change], UserGroup, :unit_id => unit_ids
end
def create_user_groups(unit_ids)
can :create, UserGroup, :unit_id => unit_ids
end
def destroy_user_groups(unit_ids)
can :destroy, UserGroup, :unit_id => unit_ids
end
end