kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.1 KiB
71 lines
2.1 KiB
15 years ago
|
require_dependency 'redmine/access_control'
|
||
15 years ago
|
|
||
15 years ago
|
module CostsAccessControlPermissionPatch
|
||
15 years ago
|
def self.included(base) # :nodoc:
|
||
|
base.send(:include, InstanceMethods)
|
||
15 years ago
|
|
||
15 years ago
|
base.class_eval do
|
||
|
unloadable
|
||
|
|
||
15 years ago
|
# fancy alias_method_chain
|
||
15 years ago
|
alias_method :initialize_without_inheritance, :initialize
|
||
|
alias_method :initialize, :initialize_with_inheritance
|
||
15 years ago
|
end
|
||
15 years ago
|
end
|
||
|
|
||
|
module InstanceMethods
|
||
|
def initialize_with_inheritance(name, hash, options)
|
||
|
initialize_without_inheritance(name, hash, options)
|
||
|
if options[:inherits].is_a? Array
|
||
|
@inherits = options[:inherits].collect{|i| i.is_a?(self.class) ? i.name : i}
|
||
|
else
|
||
|
@inherits = []
|
||
|
if i = options[:inherits]
|
||
|
@inherits << (i.is_a?(self.class) ? i.name : i)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
g = options[:granular_for]
|
||
|
@granular_for = (g.is_a? self.class) ? g.name : g
|
||
|
end
|
||
|
|
||
|
def inherits(recursive = true)
|
||
|
recursive = (recursive == true)
|
||
|
@inherits_result ||= {}
|
||
|
return @inherits_result[recursive] if @inherits_result.has_key?(recursive)
|
||
|
|
||
|
found = (@inherits || []).collect{|i| Redmine::AccessControl.permission(i)}
|
||
|
granulars = Redmine::AccessControl.permissions.select{|p| p.granular_for == self}
|
||
|
found += granulars
|
||
|
|
||
|
result = found
|
||
15 years ago
|
while (found.length > 0) && recursive
|
||
15 years ago
|
found = found.collect{|p| p.inherits(false)}.flatten - result
|
||
|
result += found
|
||
|
end
|
||
|
@inherits_result[recursive] = result
|
||
|
end
|
||
|
|
||
|
def inherited_by(recursive = true)
|
||
|
def parent_perms(perm)
|
||
|
Redmine::AccessControl.permissions.collect{|p| p if p.inherits(false).detect{|i| i.name == name}}
|
||
|
end
|
||
|
|
||
|
result = found = parent_perms(self)
|
||
15 years ago
|
while (found.length > 0) && recursive
|
||
15 years ago
|
found = found.collect{|p| parent_perms(p)}.flatten - result
|
||
|
result += found
|
||
|
end
|
||
|
result
|
||
|
end
|
||
|
|
||
|
def granular_for
|
||
|
@granular_for_obj ||= begin
|
||
|
Redmine::AccessControl.permission(@granular_for) if @granular_for
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
15 years ago
|
end
|
||
|
|
||
|
Redmine::AccessControl::Permission.send(:include, CostsAccessControlPermissionPatch)
|