activeaclplus 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,281 @@
1
+ module ActiveAcl #:nodoc:
2
+ module Acts #:nodoc:
3
+ module AccessObject #:nodoc:
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ # Extend self with access object capabilites. See README for details
12
+ # on usage. Accepts the following options as a hash:
13
+ # grouped_by:: name of the association acting as a group for access privilege
14
+ # group_class_name:: class name of group class
15
+ # join_table:: name of the join table
16
+ # foreign_key:: foreign key of self in the join table
17
+ # association_foreign_key:: foreign_key of the group class
18
+ # habtm:: set to <code>true</code> if the grup is joined with a habtm association. If not specified, the plugin tries to guess if the association is has_and_belongs_to_many or belongs_to by creating the singular form of the :grouped_by option and comparing it to itself: If it matches, it assumes a belongs_to association.
19
+ def acts_as_access_object(options = {})
20
+ configuration = {
21
+ :controller => ActiveAcl::OPTIONS[:default_selector_controller],
22
+ :action => ActiveAcl::OPTIONS[:default_selector_action]
23
+ }
24
+ if options[:grouped_by]
25
+ configuration[:group_class_name] = options[:grouped_by].to_s.classify
26
+ configuration[:join_table] = [name.pluralize.underscore, configuration[:group_class_name].pluralize.underscore].sort.join('_')
27
+ configuration[:foreign_key] = "#{name.underscore}_id"
28
+ configuration[:association_foreign_key] = "#{configuration[:group_class_name].underscore}_id"
29
+ configuration[:habtm] = (options[:grouped_by].to_s.demodulize.singularize != options[:grouped_by].to_s.demodulize)
30
+ end
31
+
32
+ configuration.update(options) if options.is_a?(Hash)
33
+
34
+ ActiveAcl::ACCESS_CLASSES[self.name] = configuration
35
+
36
+ has_many :requester_links, :as => :requester, :dependent => :delete_all, :class_name => 'ActiveAcl::RequesterLink'
37
+ has_many :requester_acls, :through => :requester_links, :source => :acl, :class_name => 'ActiveAcl::Acl'
38
+
39
+ has_many :target_links, :as => :target, :dependent => :delete_all, :class_name => 'ActiveAcl::TargetLink'
40
+ has_many :target_acls, :through => :target_links, :source => :acl, :class_name => 'ActiveAcl::Acl'
41
+
42
+ include InstanceMethods
43
+ extend SingletonMethods
44
+
45
+ from_classes = ActiveAcl::ACCESS_CLASSES.keys.collect do |x|
46
+ x.split('::').join('/').underscore.pluralize.to_sym
47
+ end
48
+
49
+ ActiveAcl::Acl.instance_eval do
50
+ has_many_polymorphs :requesters, {:from => from_classes,
51
+ :through => :"active_acl/requester_links",
52
+ :rename_individual_collections => true}
53
+
54
+ has_many_polymorphs :targets, {:from => from_classes,
55
+ :through => :"active_acl/target_links",
56
+ :rename_individual_collections => true}
57
+ end
58
+
59
+ self.module_eval do
60
+ # checks if method is defined to not break tests
61
+ unless instance_methods.include? "reload_before_gacl"
62
+ alias :reload_before_gacl :reload
63
+
64
+ # Redefines reload, making shure privilege caches are cleared on reload
65
+ def reload
66
+ clear_cached_permissions
67
+ reload_before_gacl
68
+ end
69
+ end
70
+ end
71
+
72
+ # build ACL query strings once, so we don't need to do this on every request
73
+ requester_groups_table = configuration[:group_class_name].constantize.table_name
74
+ requester_group_type = configuration[:group_class_name].constantize.name
75
+ requester_join_table = configuration[:join_table]
76
+ requester_assoc_fk = configuration[:association_foreign_key]
77
+ requester_fk = configuration[:foreign_key]
78
+ requester_group_left = ActiveAcl::GROUP_CLASSES[configuration[:group_class_name]][:left_column].to_s
79
+ requester_group_right = ActiveAcl::GROUP_CLASSES[configuration[:group_class_name]][:right_column].to_s
80
+ requester_type = self.base_class.name
81
+
82
+ # last join is necessary to weed out rules associated with targets groups
83
+ query = <<-QUERY
84
+ SELECT acls.id, acls.allow, privileges.id AS privilege_id FROM #{ActiveAcl::OPTIONS[:acls_table]} acls
85
+ LEFT JOIN #{ActiveAcl::OPTIONS[:acls_privileges_table]} acls_privileges ON acls_privileges.acl_id=acls.id
86
+ LEFT JOIN #{ActiveAcl::OPTIONS[:privileges_table]} privileges ON privileges.id = acls_privileges.privilege_id
87
+ LEFT JOIN #{ActiveAcl::OPTIONS[:requester_links_table]} r_links ON r_links.acl_id=acls.id
88
+ LEFT JOIN #{ActiveAcl::OPTIONS[:requester_group_links_table]} r_g_links ON acls.id = r_g_links.acl_id AND r_g_links.requester_group_type = '#{requester_group_type}'
89
+ LEFT JOIN #{requester_groups_table} r_groups ON r_g_links.requester_group_id = r_groups.id
90
+ LEFT JOIN #{ActiveAcl::OPTIONS[:target_group_links_table]} t_g_links ON t_g_links.acl_id=acls.id
91
+ QUERY
92
+
93
+ acl_query_on_target = '' << query
94
+ acl_query_prefetch = '' << query
95
+
96
+ # if there are no target groups, don't bother doing the join
97
+ # else append type condition
98
+ acl_query_on_target << " AND t_g_links.target_group_type = '%{target_group_type}' "
99
+ acl_query_on_target << " LEFT JOIN #{ActiveAcl::OPTIONS[:target_links_table]} t_links ON t_links.acl_id=acls.id"
100
+ acl_query_on_target << " LEFT JOIN %{target_groups_table} t_groups ON t_groups.id=t_g_links.target_group_id"
101
+
102
+ acl_query_on_target << " WHERE acls.enabled = #{connection.quote(true)} AND (privileges.id = %{privilege_id}) "
103
+ acl_query_prefetch << " WHERE acls.enabled = #{connection.quote(true)} "
104
+
105
+ query = " AND (((r_links.requester_id=%{requester_id} ) AND (r_links.requester_type='#{requester_type}')) OR (r_g_links.requester_group_id IN "
106
+
107
+ if configuration[:habtm]
108
+ configuration[:query_group] = <<-QUERY
109
+ (SELECT DISTINCT g2.id FROM #{requester_join_table} ml
110
+ LEFT JOIN #{requester_groups_table} g1 ON ml.#{requester_assoc_fk} = g1.id CROSS JOIN #{requester_groups_table} g2
111
+ WHERE ml.#{requester_fk} = %{requester_id} AND (g2.#{requester_group_left} <= g1.#{requester_group_left} AND g2.#{requester_group_right} >= g1.#{requester_group_right})))
112
+ QUERY
113
+ else
114
+ configuration[:query_group] = <<-QUERY
115
+ (SELECT DISTINCT g2.id FROM #{requester_groups_table} g1 CROSS JOIN #{requester_groups_table} g2
116
+ WHERE g1.id = %{requester_group_id} AND (g2.#{requester_group_left} <= g1.#{requester_group_left} AND g2.#{requester_group_right} >= g1.#{requester_group_right})))
117
+ QUERY
118
+ end
119
+
120
+ query << configuration[:query_group]
121
+ query << " ) AND ( "
122
+
123
+ acl_query_on_target << query
124
+ acl_query_prefetch << query
125
+
126
+ query = "(t_links.target_id=%{target_id} AND t_links.target_type = '%{target_type}' ) OR t_g_links.target_group_id IN %{target_group_query} "
127
+
128
+ acl_query_on_target << query
129
+ acl_query_prefetch << '(t_g_links.acl_id IS NULL)) '
130
+
131
+ # The ordering is always very tricky and makes all the difference in the world.
132
+ # Order (CASE WHEN r_links.requester_type = \'Group\' THEN 1 ELSE 0 END) ASC
133
+ # should put ACLs given to specific AROs ahead of any ACLs given to groups.
134
+ # This works well for exceptions to groups.
135
+ order_by_on_target = ['(CASE WHEN r_g_links.acl_id IS NULL THEN 0 ELSE 1 END) ASC ', "r_groups.#{requester_group_left} - r_groups.#{requester_group_right} ASC",
136
+ '(CASE WHEN t_g_links.acl_id IS NULL THEN 0 ELSE 1 END) ASC', 't_groups.%{target_group_left} - t_groups.%{target_group_right} ASC', 'acls.updated_at DESC']
137
+ order_by_prefetch = ['privileges.id', '(CASE WHEN r_g_links.acl_id IS NULL THEN 0 ELSE 1 END) ASC ', "r_groups.#{requester_group_left} - r_groups.#{requester_group_right} ASC", 'acls.updated_at DESC']
138
+
139
+ acl_query_on_target << 'ORDER BY ' + order_by_on_target.join(',') + ' LIMIT 1'
140
+ acl_query_prefetch << 'ORDER BY ' + order_by_prefetch.join(',')
141
+
142
+ # save query string to configuration
143
+ configuration[:query_target] = acl_query_on_target.gsub(/\n+/, "\n")
144
+ configuration[:query_simple] = acl_query_prefetch.gsub(/\n+/, "\n")
145
+ end
146
+ end
147
+
148
+ module SingletonMethods
149
+ # class description in engine interface
150
+ def active_acl_description
151
+ return name
152
+ end
153
+ end
154
+
155
+ module InstanceMethods
156
+
157
+ # checks if the user has a certain privilege, optionally on the given object.
158
+ # Option :on defines the target object.
159
+ def has_privilege?(privilege, options = {})
160
+ target = options[:on] #TODO: add error handling if not a hash
161
+
162
+ unless (privilege and (privilege.is_a?(Privilege)))
163
+ # no need to check anything if privilege is not a Privilege
164
+ return false
165
+ end
166
+
167
+ unless (target.nil? or (target.class.respond_to?(:base_class) and ActiveAcl::ACCESS_CLASSES.has_key?(target.class.base_class.name)))
168
+ # no need to check anything if target is no Access Object
169
+ return false
170
+ end
171
+
172
+ query_id = [privilege.id, self.class.base_class.name, id, (target ? target.class.base_class.name : ''), (target ? target.id.to_s : '')].join('-')
173
+ cache_id = 'gacl_instance-' + self.class.base_class.name + '-' + id.to_s
174
+ cache = ActiveAcl::OPTIONS[:cache]
175
+
176
+ # try to load instance cache from second level cache if not present
177
+ @gacl_instance_cache = cache.get(cache_id) if @gacl_instance_cache.nil?
178
+
179
+ # try to get from instance cache
180
+ if @gacl_instance_cache
181
+ if not (value = @gacl_instance_cache[query_id]).nil?
182
+ logger.debug 'GACL::INSTANCE_CACHE::' + (value ? 'GRANT ' : 'DENY ') + query_id if logger.debug?
183
+ return value
184
+ elsif target.nil? and @gacl_instance_cache[:prefetch_done]
185
+ # we didn't get a simple query from prefetched cache => cache miss
186
+ logger.debug 'GACL::INSTANCE_CACHE::DENY ' + query_id if logger.debug?
187
+ return false
188
+ end
189
+ end
190
+
191
+ if value.nil? # still a cache miss?
192
+
193
+ value = false
194
+
195
+ r_config = ActiveAcl::ACCESS_CLASSES[self.class.base_class.name]
196
+
197
+ if target
198
+ qry = r_config[:query_target].clone
199
+
200
+ t_config = ActiveAcl::ACCESS_CLASSES[target.class.base_class.name]
201
+
202
+ qry.gsub!('%{target_group_type}', t_config[:group_class_name])
203
+ qry.gsub!('%{target_groups_table}', t_config[:group_class_name].constantize.table_name)
204
+ qry.gsub!('%{target_group_left}', ActiveAcl::GROUP_CLASSES[t_config[:group_class_name]][:left_column].to_s)
205
+ qry.gsub!('%{target_group_right}', ActiveAcl::GROUP_CLASSES[t_config[:group_class_name]][:right_column].to_s)
206
+ qry.gsub!('%{target_type}', target.class.base_class.name)
207
+ qry.gsub!('%{target_id}', target.id.to_s)
208
+
209
+ group_query = t_config[:query_group].clone
210
+ group_query.gsub!('%{requester_id}', target.id.to_s)
211
+ group_query.gsub!('%{requester_group_id}', target.send(t_config[:association_foreign_key]).to_s) unless t_config[:habtm]
212
+
213
+ qry.gsub!('%{target_group_query}', group_query)
214
+ else
215
+ qry = r_config[:query_simple].clone
216
+ end
217
+
218
+ # substitute variables
219
+ qry.gsub!('%{requester_id}', self.id.to_s)
220
+ qry.gsub!('%{privilege_id}', privilege.id.to_s)
221
+ qry.gsub!('%{requester_group_id}', self.send(r_config[:association_foreign_key]).to_s) unless r_config[:habtm]
222
+ results = ActiveAcl::OPTIONS[:db].query(qry)
223
+
224
+ if target.nil?
225
+ # prefetch privileges
226
+ privilegevalue = nil
227
+ @gacl_instance_cache = {}
228
+
229
+ results.each do |row|
230
+ if row['privilege_id'] != privilegevalue
231
+ privilegevalue = row['privilege_id']
232
+ c_id = [privilegevalue, self.class.base_class.name, id, '', ''].join('-')
233
+ @gacl_instance_cache[c_id] = ((row['allow'] == '1') or (row['allow'] == 't'))
234
+ end
235
+ end
236
+
237
+ value = @gacl_instance_cache[query_id]
238
+ @gacl_instance_cache[:prefetch_done] = true
239
+
240
+ elsif not results.empty?
241
+ # normal gacl query without prefetching
242
+ value = ((results[0]['allow'].to_s == '1') or (results[0]['allow'].to_s == 't'))
243
+ @gacl_instance_cache ||= {} # create if not exists
244
+
245
+ @gacl_instance_cache[query_id] = value
246
+ end
247
+
248
+ # nothing found, deny access
249
+ @gacl_instance_cache[query_id] = value = false if value.nil?
250
+
251
+ # save to second level cache
252
+ cache.set(cache_id, @gacl_instance_cache, ActiveAcl::OPTIONS[:cache_privilege_timeout])
253
+
254
+ logger.debug 'GACL::INSTANCE_CACHE::' + (value ? 'GRANT ' : 'DENY ') + query_id if logger.debug?
255
+
256
+ end # cache miss
257
+ return value
258
+ end
259
+
260
+ # override this to customize the description in the interface
261
+ def active_acl_description
262
+ to_s
263
+ end
264
+
265
+ # link to model selector
266
+ def self.model_selector_link params
267
+ AclsController.url_for(:action => :show_group_members, :clazz => self.class, *params)
268
+ end
269
+
270
+ # clears the permission caches (instance and memory cache)
271
+ def clear_cached_permissions
272
+ @gacl_instance_cache = nil
273
+ ActiveAcl::OPTIONS[:cache].delete('gacl_instance-' + self.class.name + '-' + id.to_s)
274
+ end
275
+
276
+ end
277
+ end
278
+ end
279
+ end
280
+
281
+ ActiveRecord::Base.send(:include, ActiveAcl::Acts::AccessObject)
@@ -0,0 +1,30 @@
1
+ # This model is a DB representation of actions on an ActionController::Base
2
+ # controller and is grouped by ActiveAcl::ControllerGroup.
3
+ class ActiveAcl::ControllerAction < ActiveRecord::Base
4
+ set_table_name ActiveAcl::OPTIONS[:controller_actions_table]
5
+ privilege_const_set('EXECUTE')
6
+
7
+ belongs_to :controller_group, :class_name => 'ActiveAcl::ControllerGroup'
8
+ acts_as_access_object :grouped_by => :"active_acl/controller_group"
9
+ validates_presence_of :action, :controller, :controller_group
10
+
11
+ # Returns the instance representation in the admin screens.
12
+ def active_acl_description
13
+ if action
14
+ if controller
15
+ return '/' + controller + '/' + action
16
+ else
17
+ return action
18
+ end
19
+ else
20
+ return nil
21
+ end
22
+ end
23
+
24
+ # Returns the class representation in the admin screens.
25
+ def self.active_acl_description
26
+ return 'Action'
27
+ end
28
+
29
+
30
+ end
@@ -0,0 +1,21 @@
1
+ # This model is used for grouping ActiveAcl::ControllerAction models.
2
+ class ActiveAcl::ControllerGroup < ActiveRecord::Base
3
+ set_table_name ActiveAcl::OPTIONS[:controller_groups_table]
4
+ acts_as_nested_set
5
+ has_many :controller_actions,:class_name => 'ActiveAcl::ControllerAction'
6
+ acts_as_access_group
7
+
8
+ validates_presence_of :description
9
+
10
+ # Returns the instance representation in the admin screens.
11
+ def active_acl_description
12
+ return description
13
+ end
14
+
15
+ # Returns the class representation in the admin screens.
16
+ def self.active_acl_description
17
+ return 'ControllerGroup'
18
+ end
19
+
20
+
21
+ end
@@ -0,0 +1,79 @@
1
+ #require 'active_support'
2
+ #require 'action_view'
3
+
4
+ class ActionController::Base
5
+ # Get the access object for the current action.
6
+ def current_action
7
+ ActiveAcl::CONTROLLERS[self.class.name][action_name]
8
+ end
9
+
10
+ # alias method_added class method
11
+ class << self
12
+ alias :method_added_before_active_acl_controller_action_loading :method_added
13
+ end
14
+
15
+ # Overrides method_added, so the needed ActiveAcl::ControllerAction is loaded/created
16
+ # when the action gets added to the controller.
17
+ def self.method_added(action)
18
+ method_added_before_active_acl_controller_action_loading(action)
19
+ ActiveAcl::CONTROLLERS[self.name] ||= {}
20
+
21
+ if (public_instance_methods.include?(action.to_s))
22
+ # if no loaded target found
23
+ unless ActiveAcl::CONTROLLERS[self.name][action.to_s]
24
+ # load it
25
+ stripped_name = self.name.underscore.gsub(/_controller/, '')
26
+
27
+ begin
28
+ target = (ActiveAcl::CONTROLLERS[self.name][action.to_s] ||= ActiveAcl::ControllerAction.find_by_action_and_controller(action.to_s, stripped_name))
29
+ unless target
30
+ grp_name = stripped_name + ActiveAcl::OPTIONS[:controller_group_name_suffix]
31
+
32
+ # find controller group
33
+ cgroup = ActiveAcl::CONTROLLERS[self.name][:cgroup] ||= ActiveAcl::ControllerGroup.find_by_description(grp_name)
34
+
35
+ unless cgroup
36
+ #try to get main group
37
+ main_group ||= (ActiveAcl::CONTROLLERS[ActiveAcl::OPTIONS[:controllers_group_name]] ||= ActiveAcl::ControllerGroup.find_by_description(ActiveAcl::OPTIONS[:controllers_group_name]))
38
+
39
+ unless main_group
40
+ # create main group
41
+ base_group = ActiveAcl::ControllerGroup.root
42
+ main_group = ActiveAcl::ControllerGroup.create(:description => ActiveAcl::OPTIONS[:controllers_group_name])
43
+ # check if better_nested_set functionality is available
44
+ if main_group.respond_to?(:move_to_child_of)
45
+ main_group.move_to_child_of base_group
46
+ else
47
+ base_group.add_child main_group
48
+ end
49
+
50
+ ActiveAcl::CONTROLLERS[ActiveAcl::OPTIONS[:controllers_group_name]] = main_group
51
+ end
52
+
53
+ # create controller group
54
+ cgroup = ActiveAcl::ControllerGroup.create(:description => grp_name)
55
+
56
+ # check if better_nested_set functionality is available
57
+ if cgroup.respond_to?(:move_to_child_of)
58
+ cgroup.move_to_child_of main_group
59
+ else
60
+ main_group.add_child cgroup
61
+ end
62
+ end
63
+
64
+ target = cgroup.controller_actions.create :action => action.to_s, :controller => stripped_name
65
+
66
+ # save to collection
67
+ ActiveAcl::CONTROLLERS[self.name][action.to_s] = target
68
+
69
+ end # unless target fetched from db
70
+
71
+ # return target
72
+ return target
73
+ rescue Exception => e
74
+ Rails.logger.error("error loading target actions in controller #{self.name}: #{e.message}")
75
+ end
76
+ end # unless target constant found
77
+ end # if method is a action
78
+ end # method_added
79
+ end
@@ -0,0 +1,21 @@
1
+ class ::Object
2
+
3
+ # Loads all files it finds at the specified path -
4
+ # use /path/**/[^.]*.rb to load from sub directories as well
5
+ #
6
+ # Silently fails if path is not found or an error occurs
7
+ def load_files_from(filenames)
8
+ # don't show files that begin with . and ensure .rb ending
9
+ cs = Dir["#{filenames}"]
10
+ for file_name in cs.sort
11
+ begin
12
+ # load file_name
13
+ load(file_name)
14
+ Rails.logger.info "#{file_name} loaded"
15
+ rescue Exception => e
16
+ Rails.logger.warn("error loading file #{file_name}: #{e.message}")
17
+ Rails.logger.warn(e.backtrace)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module ActiveAcl
2
+ unless const_defined?('OPTIONS')
3
+ OPTIONS = {}
4
+ end
5
+
6
+ ActiveAcl::ACCESS_CLASSES = {}
7
+ ActiveAcl::GROUP_CLASSES = {}
8
+
9
+ DEFAULT_OPTIONS = {
10
+ :acl_sections_table => 'acl_sections',
11
+ :acls_privileges_table => 'acls_privileges',
12
+ :acls_table => 'acls',
13
+ :privileges_table => 'privileges',
14
+ :requester_links_table => 'requester_links',
15
+ :target_links_table => 'target_links',
16
+ :requester_group_links_table => 'requester_group_links',
17
+ :target_group_links_table => 'target_group_links',
18
+ :controller_actions_table => 'controller_actions',
19
+ :controller_groups_table => 'controller_groups',
20
+
21
+ :controllers_group_name => 'unassigned_controller_actions',
22
+ :controller_group_name_suffix => '_controller',
23
+
24
+ :cache_privilege_timeout => 10,
25
+
26
+ :db => ActiveAcl::DB::ActiveRecordAdapter,
27
+ :cache => ActiveAcl::Cache::NoCacheAdapter,
28
+
29
+ :default_selector_controller => 'selector',
30
+ :default_selector_action => 'show_members',
31
+
32
+ :default_group_selector_controller => 'selector',
33
+ :default_group_selector_action => 'show_group_members'}
34
+
35
+ # merge options
36
+ OPTIONS.replace DEFAULT_OPTIONS.merge(OPTIONS)
37
+ end
@@ -0,0 +1,26 @@
1
+ # The basic "privilege" object, like Forum::VIEW might be the privilege to
2
+ # view a forum. Check the README for a detailed description on usage.
3
+ module ActiveAcl
4
+ class Privilege < ActiveRecord::Base
5
+ set_table_name ActiveAcl::OPTIONS[:privileges_table]
6
+
7
+ has_and_belongs_to_many :acls, :uniq => true, :join_table => ActiveAcl::OPTIONS[:acls_privileges_table],:class_name => 'ActiveAcl::Acl'
8
+
9
+ validates_presence_of :section, :value
10
+ validates_uniqueness_of :value, :scope => :section
11
+
12
+ # Returns the instance representation in the admin screens.
13
+ # Uses active_acl_description from class if present.
14
+ def active_acl_description
15
+ begin
16
+ section.constantize.active_acl_description
17
+ rescue
18
+ section
19
+ end + '/' + value
20
+ end
21
+
22
+ def self.reloadable? #:nodoc:
23
+ return false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ class ::Module
2
+ public
3
+ # Looks up or creates a privilege object using the caller's name and the constant's name.
4
+ # Finally sets the privilege object as a constant to the caller.
5
+ # Accepts a hash of names with descriptions like :name => description or a single string name value.
6
+ # If force_reload is set to true, the constant will be recreated from the DB.
7
+ # Returns an array of changed privileges.
8
+ def privilege_const_set(constant, force_reload = false)
9
+ result = []
10
+ constant.is_a?(Hash) ? constant_hash = constant : constant_hash = {constant.to_s => nil}
11
+ constant_hash.each_pair do |constant_name, description|
12
+ if !const_defined?(constant_name.to_s) or force_reload
13
+ remove_const(constant_name.to_s) if const_defined?(constant_name.to_s)
14
+ privilege = ActiveAcl::Privilege.find_by_section_and_value(self.name, constant_name.to_s)
15
+ privilege = ActiveAcl::Privilege.create(:section => self.name, :value => constant_name.to_s, :description => description) unless privilege
16
+ const_set(constant_name.to_s, privilege)
17
+ result << privilege
18
+ end
19
+ end
20
+ result
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveAcl
2
+ class RequesterGroupLink < ActiveRecord::Base
3
+ set_table_name ActiveAcl::OPTIONS[:requester_group_links_table]
4
+
5
+ belongs_to :acl, :class_name => "ActiveAcl::Acl"
6
+ belongs_to :requester_group, :polymorphic => true
7
+
8
+ def self.reloadable? #:nodoc:
9
+ return false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveAcl
2
+ class RequesterLink < ActiveRecord::Base
3
+ set_table_name ActiveAcl::OPTIONS[:requester_links_table]
4
+
5
+ belongs_to :acl, :class_name => "ActiveAcl::Acl"
6
+ belongs_to :requester, :polymorphic => true
7
+
8
+ def self.reloadable? #:nodoc:
9
+ return false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveAcl
2
+ class TargetGroupLink < ActiveRecord::Base
3
+ set_table_name ActiveAcl::OPTIONS[:target_group_links_table]
4
+
5
+ belongs_to :acl, :class_name => "ActiveAcl::Acl"
6
+ belongs_to :target_group, :polymorphic => true
7
+
8
+ def self.reloadable? #:nodoc:
9
+ return false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveAcl
2
+ class TargetLink < ActiveRecord::Base
3
+ set_table_name ActiveAcl::OPTIONS[:target_links_table]
4
+
5
+ belongs_to :acl, :class_name => "ActiveAcl::Acl"
6
+ belongs_to :target, :polymorphic => true
7
+
8
+ def self.reloadable? #:nodoc:
9
+ return false
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeaclplus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ - Gregor Melhorn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-12-07 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.1.0
25
+ version:
26
+ description: A flexible, fast and easy to use generic access control system.
27
+ email:
28
+ - peter.schrammel@gmx.de
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/active_acl/db
37
+ - lib/active_acl/cache
38
+ - lib/active_acl/target_group_link.rb
39
+ - lib/active_acl/controller_action.rb
40
+ - lib/active_acl/acl_section.rb
41
+ - lib/active_acl/load_files_from.rb
42
+ - lib/active_acl/acts_as_access_object.rb
43
+ - lib/active_acl/privilege.rb
44
+ - lib/active_acl/options.rb
45
+ - lib/active_acl/requester_link.rb
46
+ - lib/active_acl/controller_group.rb
47
+ - lib/active_acl/acl.rb
48
+ - lib/active_acl/load_controller_actions.rb
49
+ - lib/active_acl/target_link.rb
50
+ - lib/active_acl/privilege_const_set.rb
51
+ - lib/active_acl/requester_group_link.rb
52
+ - lib/active_acl/acts_as_access_group.rb
53
+ - generators/active_acl/templates
54
+ - generators/active_acl/active_acl_generator.rb
55
+ - db/migrate/001_base_table_setup.rb
56
+ - init.rb
57
+ - install.rb
58
+ - LICENSE
59
+ - Rakefile
60
+ - README.rdoc
61
+ - CHANGELOG
62
+ has_rdoc: true
63
+ homepage: http://activeaclplus.rubyforge.org/
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --main
67
+ - README.rdoc
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: activeaclplus
85
+ rubygems_version: 1.2.0
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: activeaclplus 0.3.0
89
+ test_files: []
90
+