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.
72 lines
2.2 KiB
72 lines
2.2 KiB
12 years ago
|
module OpenProject::Costs::Patches::RolePatch
|
||
15 years ago
|
def self.included(base) # :nodoc:
|
||
|
base.send(:include, InstanceMethods)
|
||
12 years ago
|
|
||
|
# Same as typing in the class
|
||
15 years ago
|
base.class_eval do
|
||
|
unloadable
|
||
12 years ago
|
|
||
15 years ago
|
alias_method_chain :allowed_to?, :inheritance
|
||
15 years ago
|
end
|
||
|
end
|
||
12 years ago
|
|
||
15 years ago
|
module InstanceMethods
|
||
|
# Return true if the user is allowed to do the specified action on project
|
||
|
# action can be:
|
||
|
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||
|
# * a permission Symbol (eg. :edit_project)
|
||
15 years ago
|
def allowed_to_with_inheritance?(action)
|
||
12 years ago
|
allowed_to_with_caching(action)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def allowed_to_with_caching(action)
|
||
|
@allowed_to_with_inheritance ||= {}
|
||
|
|
||
|
return @allowed_to_with_inheritance[action] if @allowed_to_with_inheritance.has_key?(action)
|
||
|
|
||
|
@allowed_to_with_inheritance[action] = allowed_to_without_caching(action)
|
||
|
end
|
||
|
|
||
|
def allowed_to_without_caching(action)
|
||
15 years ago
|
return true if allowed_to_without_inheritance?(action)
|
||
15 years ago
|
|
||
15 years ago
|
if action.is_a? Hash
|
||
|
# action is a parameter hash
|
||
15 years ago
|
|
||
15 years ago
|
# check the action based on the permissions of the role and all
|
||
|
# included permissions
|
||
|
allowed_inherited_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||
|
else
|
||
|
# check, if the role has one of the parent permissions granted
|
||
12 years ago
|
|
||
15 years ago
|
permission = Redmine::AccessControl.permission(action)
|
||
13 years ago
|
|
||
|
return if permission.blank?
|
||
|
|
||
15 years ago
|
(permission.inherited_by + [permission]).map(&:name).detect {|parent| allowed_inherited_permissions.include? parent}
|
||
15 years ago
|
|
||
15 years ago
|
end
|
||
|
end
|
||
12 years ago
|
|
||
15 years ago
|
def allowed_inherited_permissions
|
||
|
@allowed_inherited_permissions ||= begin
|
||
|
all_permissions = allowed_permissions || []
|
||
12 years ago
|
(all_permissions | allowed_permissions.collect do |sym|
|
||
15 years ago
|
p = Redmine::AccessControl.permission(sym)
|
||
|
p ? p.inherits.collect(&:name) : []
|
||
|
end.flatten).uniq
|
||
15 years ago
|
end
|
||
|
end
|
||
12 years ago
|
|
||
15 years ago
|
def allowed_inherited_actions
|
||
|
@actions_allowed_inherited ||= begin
|
||
|
allowed_inherited_permissions.inject({}){|actions, p| actions[p] = Redmine::AccessControl.allowed_actions(p); actions}
|
||
|
end
|
||
|
end
|
||
15 years ago
|
end
|
||
|
end
|
||
15 years ago
|
|
||
12 years ago
|
Role.send(:include, OpenProject::Costs::Patches::RolePatch)
|