Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

hide bim permission group in role view if bim disabled

ulferts112f8c1be374
diff --git a/app/helpers/roles_helper.rb b/app/helpers/roles_helper.rb
index 9a61c2a0349..3ae8fc36842 100644
--- a/app/helpers/roles_helper.rb
+++ b/app/helpers/roles_helper.rb
@@ -45,7 +45,7 @@ module RolesHelper
def group_permissions_by_module(perms)
perms_by_module = perms.group_by { |p| p.project_module.to_s }
::OpenProject::AccessControl
- .sorted_modules
+ .sorted_module_names(false)
.select { |module_name| perms_by_module[module_name].present? }
.map do |module_name|
[module_name, perms_by_module[module_name]]
diff --git a/lib/open_project/access_control.rb b/lib/open_project/access_control.rb
index 0323344cb3b..dc9036f2298 100644
--- a/lib/open_project/access_control.rb
+++ b/lib/open_project/access_control.rb
@@ -45,8 +45,11 @@ module OpenProject
end
# Get a sorted array of module names
- def sorted_modules
+ #
+ # @param include_disabled [boolean] Whether to return all modules or only those that are active (not disabled by config)
+ def sorted_module_names(include_disabled = true)
modules
+ .reject { |mod| !include_disabled && disabled_project_modules.include?(mod[:name]) }
.sort_by { |a| [-a[:order], l_or_humanize(a[:name], prefix: 'project_module_')] }
.map { |entry| entry[:name].to_s }
end
diff --git a/modules/bim/spec/lib/open_project/access_control_spec.rb b/modules/bim/spec/lib/open_project/access_control_spec.rb
new file mode 100644
index 00000000000..aaf4210b831
--- /dev/null
+++ b/modules/bim/spec/lib/open_project/access_control_spec.rb
@@ -0,0 +1,81 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# 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.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe OpenProject::AccessControl do
+ after do
+ OpenProject::AccessControl.instance_variable_set(:'@disabled_project_modules', nil)
+ end
+
+ describe '.sorted_module_names' do
+ context 'with bim disabled' do
+ before do
+ allow(OpenProject::Configuration)
+ .to receive(:bim?)
+ .and_return false
+ end
+
+ context 'if including disabled modules' do
+ it 'includes the bim module' do
+ expect(subject.sorted_module_names)
+ .to include('bim')
+ end
+ end
+
+ context 'if excluding disabled modules' do
+ it 'does not include the bim module' do
+ expect(subject.sorted_module_names(false))
+ .not_to include('bim')
+ end
+ end
+ end
+
+ context 'with bim enabled' do
+ before do
+ allow(OpenProject::Configuration)
+ .to receive(:bim?)
+ .and_return true
+ end
+
+ context 'if including disabled modules' do
+ it 'includes the bim module' do
+ expect(subject.sorted_module_names)
+ .to include('bim')
+ end
+ end
+
+ context 'if excluding disabled modules' do
+ it 'includes the bim module' do
+ expect(subject.sorted_module_names(false))
+ .to include('bim')
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/open_project/access_control_spec.rb b/spec/lib/open_project/access_control_spec.rb
index c65d3989042..5cb5383095a 100644
--- a/spec/lib/open_project/access_control_spec.rb
+++ b/spec/lib/open_project/access_control_spec.rb
@@ -27,6 +27,7 @@
#++
require 'spec_helper'
+
describe OpenProject::AccessControl do
describe '.remove_modules_permissions' do
let!(:all_former_permissions) { OpenProject::AccessControl.permissions }