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.
160 lines
5.2 KiB
160 lines
5.2 KiB
11 years ago
|
#-- copyright
|
||
11 years ago
|
# OpenProject Global Roles Plugin
|
||
11 years ago
|
#
|
||
11 years ago
|
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
|
||
11 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
11 years ago
|
# modify it under the terms of the GNU General Public License
|
||
|
# version 3.
|
||
11 years ago
|
#
|
||
11 years ago
|
# 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.
|
||
11 years ago
|
#++
|
||
|
|
||
12 years ago
|
module OpenProject
|
||
|
module GlobalRoles
|
||
|
module PluginSpecHelper
|
||
|
def mobile_tan_plugin_loaded?
|
||
9 years ago
|
plugin_loaded?('openproject_mobile_otp')
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def privacy_plugin_loaded?
|
||
9 years ago
|
plugin_loaded?('openproject_dtag_customizing')
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def costs_plugin_loaded?
|
||
9 years ago
|
plugin_loaded?('openproject_costs')
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def plugin_loaded?(name)
|
||
9 years ago
|
Redmine::Plugin.all.detect { |x| x.id == name.to_sym }.present?
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mocks_for_member_roles
|
||
|
@role = mock_model Role
|
||
11 years ago
|
allow(Role).to receive(:new).and_return(@role)
|
||
14 years ago
|
|
||
12 years ago
|
mock_permissions_on @role
|
||
14 years ago
|
|
||
12 years ago
|
mock_role_find
|
||
14 years ago
|
|
||
12 years ago
|
@non_mem = mock_model Role
|
||
11 years ago
|
allow(@non_mem).to receive(:permissions).and_return(@non_mem_perm)
|
||
|
allow(Role).to receive(:non_member).and_return(@non_mem)
|
||
12 years ago
|
@non_mem_perm = [:nm_perm1, :nm_perm2]
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mocks_for_global_roles
|
||
|
@role = mock_model GlobalRole
|
||
11 years ago
|
allow(GlobalRole).to receive(:new).and_return(@role)
|
||
12 years ago
|
mock_permissions_on @role
|
||
|
end
|
||
14 years ago
|
|
||
9 years ago
|
def mock_permissions_on(role)
|
||
12 years ago
|
permissions = [:perm1, :perm2, :perm3]
|
||
11 years ago
|
allow(role).to receive(:setable_permissions).and_return(permissions)
|
||
|
allow(role).to receive(:permissions).and_return(permissions << :perm4)
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mock_role_find
|
||
|
mock_member_role_find
|
||
|
mock_global_role_find
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mock_member_role_find
|
||
|
@role1 = mock_model Role
|
||
|
@role2 = mock_model Role
|
||
|
@global_role1 = mock_model GlobalRole
|
||
|
@global_role2 = mock_model GlobalRole
|
||
|
@roles = [@role1, @global_role2, @role2, @global_role1]
|
||
11 years ago
|
allow(Role).to receive(:find).and_return(@roles)
|
||
|
allow(Role).to receive(:all).and_return(@roles)
|
||
|
allow(Role).to receive(:order).and_return(@roles)
|
||
|
allow(@roles).to receive(:page).and_return(@roles)
|
||
|
allow(@roles).to receive(:per_page).and_return(@roles)
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mock_global_role_find
|
||
|
@global_role1 = mock_model GlobalRole
|
||
|
@global_role2 = mock_model GlobalRole
|
||
|
@global_roles = [@global_role1, @global_role2]
|
||
11 years ago
|
allow(GlobalRole).to receive(:find).and_return(@global_roles)
|
||
|
allow(GlobalRole).to receive(:all).and_return(@global_roles)
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
9 years ago
|
def mocks_for_creating(role_class)
|
||
12 years ago
|
role = mock_model role_class
|
||
11 years ago
|
allow(role_class).to receive(:new).and_return role
|
||
12 years ago
|
mock_permissions_on role
|
||
|
role
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def disable_flash_sweep
|
||
9 years ago
|
@controller.instance_eval { allow(flash).to receive(:sweep) }
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def disable_log_requesting_user
|
||
11 years ago
|
allow(@controller).to receive(:log_requesting_user)
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
9 years ago
|
def response_should_render(method, *params)
|
||
12 years ago
|
unless @page
|
||
9 years ago
|
@page ||= double('page')
|
||
11 years ago
|
expect(controller).to receive(:render).with(:update).and_yield(@page)
|
||
10 years ago
|
expect(controller).to receive(:render).with(no_args)
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
expect(@page).to receive(method).with(*params)
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mock_permissions_for_setable_permissions
|
||
|
@public_perm = mock_permissions(true, false)
|
||
|
@perm1 = mock_permissions(false, false)
|
||
|
@perm2 = mock_permissions(false, false)
|
||
|
@global_perm = mock_permissions(false, true)
|
||
14 years ago
|
|
||
12 years ago
|
@perms = [@public_perm, @perm1, @global_perm, @perm2]
|
||
11 years ago
|
allow(Redmine::AccessControl).to receive(:permissions).and_return(@perms)
|
||
|
allow(Redmine::AccessControl).to receive(:public_permissions).and_return([@public_perm])
|
||
|
allow(Redmine::AccessControl).to receive(:global_permissions).and_return([@global_perm])
|
||
12 years ago
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def mock_permissions(is_public, is_global)
|
||
12 years ago
|
permission = Object.new
|
||
11 years ago
|
allow(permission).to receive(:public?).and_return(is_public)
|
||
|
allow(permission).to receive(:global?).and_return(is_global)
|
||
12 years ago
|
permission
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def create_non_member_role
|
||
|
create_builtin_role 'No member', Role::BUILTIN_NON_MEMBER
|
||
|
end
|
||
14 years ago
|
|
||
12 years ago
|
def create_anonymous_role
|
||
9 years ago
|
create_builtin_role 'Anonymous', Role::BUILTIN_ANONYMOUS
|
||
12 years ago
|
end
|
||
|
|
||
|
def create_builtin_role(name, const)
|
||
9 years ago
|
Role.create(name: name, position: 0) do |role|
|
||
12 years ago
|
role.builtin = const
|
||
|
end
|
||
14 years ago
|
end
|
||
|
|
||
12 years ago
|
def stash_access_control_permissions
|
||
|
@stashed_permissions = Redmine::AccessControl.permissions.dup
|
||
|
Redmine::AccessControl.permissions.clear
|
||
|
end
|
||
|
|
||
|
def restore_access_control_permissions
|
||
|
Redmine::AccessControl.instance_variable_set(:@permissions, @stashed_permissions)
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
12 years ago
|
end
|