hide bim permission group in role view if bim disabled

pull/8112/head
ulferts 5 years ago
parent f1b2434a29
commit 112f8c1be3
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 2
      app/helpers/roles_helper.rb
  2. 5
      lib/open_project/access_control.rb
  3. 81
      modules/bim/spec/lib/open_project/access_control_spec.rb
  4. 1
      spec/lib/open_project/access_control_spec.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]]

@ -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

@ -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

@ -27,6 +27,7 @@
#++
require 'spec_helper'
describe OpenProject::AccessControl do
describe '.remove_modules_permissions' do
let!(:all_former_permissions) { OpenProject::AccessControl.permissions }

Loading…
Cancel
Save