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.
183 lines
5.3 KiB
183 lines
5.3 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
7 years ago
|
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
8 years ago
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
11 years ago
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
7 years ago
|
# See docs/COPYRIGHT.rdoc for more details.
|
||
14 years ago
|
#++
|
||
|
|
||
6 years ago
|
module OpenProject
|
||
17 years ago
|
module AccessControl
|
||
|
class << self
|
||
6 years ago
|
include ::Redmine::I18n
|
||
|
|
||
17 years ago
|
def map
|
||
|
mapper = Mapper.new
|
||
|
yield mapper
|
||
|
@permissions ||= []
|
||
|
@permissions += mapper.mapped_permissions
|
||
6 years ago
|
@modules ||= []
|
||
|
@modules += mapper.mapped_modules
|
||
11 years ago
|
@project_modules_without_permissions ||= []
|
||
|
@project_modules_without_permissions += mapper.project_modules_without_permissions
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
6 years ago
|
# Get a sorted array of module names
|
||
|
def sorted_modules
|
||
6 years ago
|
modules
|
||
|
.sort_by { |a| [-a[:order], l_or_humanize(a[:name], prefix: 'project_module_')] }
|
||
6 years ago
|
.map { |entry| entry[:name].to_s }
|
||
|
end
|
||
|
|
||
17 years ago
|
def permissions
|
||
|
@permissions
|
||
|
end
|
||
14 years ago
|
|
||
6 years ago
|
def modules
|
||
|
@modules.uniq { |mod| mod[:name] }
|
||
|
end
|
||
|
|
||
16 years ago
|
# Returns the permission of given name or nil if it wasn't found
|
||
|
# Argument should be a symbol
|
||
|
def permission(name)
|
||
10 years ago
|
permissions.detect { |p| p.name == name }
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
16 years ago
|
# Returns the actions that are allowed by the permission of given name
|
||
17 years ago
|
def allowed_actions(permission_name)
|
||
16 years ago
|
perm = permission(permission_name)
|
||
17 years ago
|
perm ? perm.actions : []
|
||
|
end
|
||
14 years ago
|
|
||
8 years ago
|
def allow_actions(action_hash)
|
||
|
action = "#{action_hash[:controller]}/#{action_hash[:action]}"
|
||
|
|
||
|
permissions.select { |p| p.actions.include? action }
|
||
|
end
|
||
|
|
||
17 years ago
|
def public_permissions
|
||
10 years ago
|
@public_permissions ||= @permissions.select(&:public?)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def members_only_permissions
|
||
10 years ago
|
@members_only_permissions ||= @permissions.select(&:require_member?)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def loggedin_only_permissions
|
||
10 years ago
|
@loggedin_only_permissions ||= @permissions.select(&:require_loggedin?)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def available_project_modules
|
||
11 years ago
|
@available_project_modules ||= (
|
||
6 years ago
|
@permissions.map(&:project_module) + @project_modules_without_permissions
|
||
9 years ago
|
).uniq.compact
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def modules_permissions(modules)
|
||
10 years ago
|
@permissions.select { |p| p.project_module.nil? || modules.include?(p.project_module.to_s) }
|
||
17 years ago
|
end
|
||
10 years ago
|
|
||
|
def remove_modules_permissions(module_name)
|
||
|
permissions = @permissions
|
||
|
|
||
|
module_permissions = permissions.select { |p| p.project_module.to_s == module_name.to_s }
|
||
|
|
||
10 years ago
|
clear_caches
|
||
10 years ago
|
|
||
|
@permissions = permissions - module_permissions
|
||
|
end
|
||
|
|
||
10 years ago
|
def clear_caches
|
||
10 years ago
|
@available_project_modules = nil
|
||
|
@public_permissions = nil
|
||
|
@members_only_permissions = nil
|
||
|
@loggedin_only_permissions = nil
|
||
|
end
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
class Mapper
|
||
10 years ago
|
def permission(name, hash, options = {})
|
||
6 years ago
|
options[:project_module] = @project_module
|
||
10 years ago
|
mapped_permissions << Permission.new(name, hash, options)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
6 years ago
|
def project_module(name, options = {})
|
||
6 years ago
|
mapped_modules << {name: name, order: 0}.merge(options)
|
||
6 years ago
|
|
||
11 years ago
|
if block_given?
|
||
|
@project_module = name
|
||
|
yield self
|
||
|
@project_module = nil
|
||
|
else
|
||
10 years ago
|
project_modules_without_permissions << name
|
||
11 years ago
|
end
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
6 years ago
|
def mapped_modules
|
||
|
@mapped_modules ||= []
|
||
|
end
|
||
|
|
||
17 years ago
|
def mapped_permissions
|
||
10 years ago
|
@permissions ||= []
|
||
17 years ago
|
end
|
||
11 years ago
|
|
||
|
def project_modules_without_permissions
|
||
10 years ago
|
@project_modules_without_permissions ||= []
|
||
11 years ago
|
end
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
class Permission
|
||
17 years ago
|
attr_reader :name, :actions, :project_module
|
||
14 years ago
|
|
||
17 years ago
|
def initialize(name, hash, options)
|
||
|
@name = name
|
||
|
@actions = []
|
||
|
@public = options[:public] || false
|
||
|
@require = options[:require]
|
||
17 years ago
|
@project_module = options[:project_module]
|
||
17 years ago
|
hash.each do |controller, actions|
|
||
6 years ago
|
@actions << if actions.is_a? Array
|
||
|
actions.map { |action| "#{controller}/#{action}" }
|
||
|
else
|
||
|
"#{controller}/#{actions}"
|
||
|
end
|
||
17 years ago
|
end
|
||
16 years ago
|
@actions.flatten!
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def public?
|
||
|
@public
|
||
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def require_member?
|
||
|
@require && @require == :member
|
||
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def require_loggedin?
|
||
|
@require && (@require == :member || @require == :loggedin)
|
||
|
end
|
||
14 years ago
|
end
|
||
17 years ago
|
end
|
||
|
end
|