Replace cukes with specs

pull/7288/head
Oliver Günther 6 years ago
parent bf638d7077
commit b3ec4792c5
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 9
      lib/redmine/access_control.rb
  2. 72
      modules/global_roles/features/global_create_project.feature
  3. 79
      modules/global_roles/features/global_role_assignment.feature
  4. 43
      modules/global_roles/features/global_role_crud.feature
  5. 33
      modules/global_roles/features/member_roles.feature
  6. 29
      modules/global_roles/features/no_module.feature
  7. 93
      modules/global_roles/features/step_definitions/global_role_steps.rb
  8. 1
      modules/global_roles/lib/open_project/global_roles/patches/roles_controller_patch.rb
  9. 23
      modules/global_roles/spec/controllers/roles_controller_spec.rb
  10. 105
      modules/global_roles/spec/features/global_create_project_spec.rb
  11. 108
      modules/global_roles/spec/features/global_role_assignment_spec.rb
  12. 64
      modules/global_roles/spec/features/global_role_crud_spec.rb
  13. 63
      modules/global_roles/spec/features/member_roles_spec.rb
  14. 59
      modules/global_roles/spec/features/no_module_spec.rb
  15. 48
      modules/global_roles/spec/plugin_spec_helper.rb
  16. 4
      spec/support/pages/members.rb

@ -45,16 +45,19 @@ module Redmine
# Get a sorted array of module names
def sorted_modules
@modules
.sort_by { |a| [-a[:order], l_or_humanize(a[:name], prefix: 'project_module')] }
modules
.sort_by { |a| [-a[:order], l_or_humanize(a[:name], prefix: 'project_module_')] }
.map { |entry| entry[:name].to_s }
.uniq
end
def permissions
@permissions
end
def modules
@modules.uniq { |mod| mod[:name] }
end
# Returns the permission of given name or nil if it wasn't found
# Argument should be a symbol
def permission(name)

@ -1,72 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Feature: Global Create Project
Scenario: Create Project is not a member permission
Given there is a role "Member"
And I am already admin
When I go to the edit page of the role "Member"
Then I should not see "Create project"
Scenario: Create Project is a global permission
Given there is a global role "Global"
And I am already admin
When I go to the edit page of the role "Global"
Then I should see "Create project"
Scenario: Create Project displayed to user
Given there is a global role "Global"
And the global role "Global" may have the following rights:
| add_project |
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And the user "bob" has the global role "Global"
When I am already logged in as "bob"
And I go to the overall projects page
Then I should see "Project" within ".toolbar-items"
Scenario: Create Project not displayed to user without global role
Given there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
When I am already logged in as "bob"
And I go to the overall projects page
Then I should not see "Project" within ".toolbar-items"
@javascript
Scenario: Create Project displayed to user
Given there is a global role "Global"
And the global role "Global" may have the following rights:
| add_project |
And there is a role "Manager"
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And the user "bob" has the global role "Global"
When I am already logged in as "bob"
And I go to the new page of "Project"
And I fill in "project_name" with "ProjectName"
And I press "Create"
Then I should see "Successful creation."
And I should be on the overview page of the project called "ProjectName"

@ -1,79 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Feature: Global Role Assignment
@javascript
Scenario: Going to the global role assignment page
Given there is the global permission "global1" of the module "global"
And there is the global permission "global2" of the module "global"
And there is a global role "global_role1"
And there is a global role "global_role2"
And the global role "global_role1" may have the following rights:
| global1 |
And the global role "global_role2" may have the following rights:
| global2 |
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And the user "bob" has the global role "global_role1"
And I am already admin
When I go to the edit page of the user called "bob"
And I click on "tab-global_roles"
Then I should see "global_role1" within "#table_principal_roles"
And I should not see "global_role1" within "#available_principal_roles"
And I should see "global_role2" within "#available_principal_roles"
@javascript
Scenario: Assigning a global role to a user
Given there is the global permission "global1" of the module "global"
And there is a global role "global_role"
And the global role "global_role" may have the following rights:
| global1 |
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And I am already admin
When I go to the edit page of the user called "bob"
And I click on "tab-global_roles"
And I select the available global role "global_role"
And I press "Add"
Then I should see "global_role" within "#table_principal_roles"
And I should not see "global_role" within "#available_principal_roles"
And I should see "There is currently nothing to display"
@javascript
Scenario: Deleting a global role of a user
Given there is the global permission "global1" of the module "global"
And there is a global role "global_role"
And the global role "global_role" may have the following rights:
| global1 |
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And the user "bob" has the global role "global_role"
And I am already admin
When I go to the edit page of the user called "bob"
And I click on "tab-global_roles"
And I delete the assigned role "global_role"
Then I should see "Nothing to display" within "#assigned_principal_roles"
And I should see "global_role" within "#available_principal_roles"

@ -1,43 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Feature: As an admin
I want to administrate global roles with permissions
So that I can modify permission groups
@javascript
Scenario: Global Role creation
Given there is the global permission "glob_test" of the module "global_group"
And I am already admin
When I go to the new page of "Role"
Then I should not see block with "#global_permissions"
When I check "Global Role"
Then I should see block with "#global_permissions"
And I should see "Global group"
And I should see "Glob test"
And I should not see "Issues can be assigned to this role"
When I fill in "Name" with "Manager"
And I click on "Create"
Then I should see "Successful creation."
Scenario: Global Roles can not be assigned issues to
Given there is a global role "global_role_x"
And I am already admin
When I go to the edit page of the role called "global_role_x"
Then I should not see "Issues can be assigned to this role"

@ -1,33 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Feature: Unchanged Member Roles
@javascript
Scenario: Global Roles should not be displayed as assignable project roles
Given there is 1 project with the following:
| Name | projectname |
| Identifier | projectid |
And there is a global role "GlobalRole1"
And there is a role "MemberRole1"
And I am already admin
When I go to the members page of the project "projectid"
And I click "Add member"
Then I should see "MemberRole1" within "#member_role_ids"
Then I should not see "GlobalRole1" within "#member_role_ids"

@ -1,29 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Feature: No Module
Scenario: Global Rights Modules do not exist as Project -> Settings -> Modules
Given there is the global permission "glob_test" of the module "global"
And there is 1 project with the following:
| name | test |
| identifier | test |
And I am already admin
When I go to the members tab of the settings page for the project "test"
Then I should not see "Global"

@ -1,93 +0,0 @@
#-- copyright
# OpenProject Global Roles Plugin
#
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
Given /^there is the global permission "(.+)?" of the module "(.+)?"$/ do |perm_name, perm_module|
Redmine::AccessControl.map do |map|
map.project_module perm_module.to_sym do |mod|
mod.permission perm_name.to_sym, { dont: :care }, project_module: perm_module.to_sym, global: true
end
end
end
Given /^the global permission "(.+)?" of the module "(.+)?" is defined$/ do |perm_name, perm_module|
as_admin do
permissions = Redmine::AccessControl.modules_permissions(perm_module)
permissions.detect { |p| p.name == perm_name.to_sym && p.global? }.should_not be_nil
end
end
Given /^there is a global [rR]ole "([^\"]*)"$/ do |name|
FactoryBot.create(:global_role, name: name) unless GlobalRole.find_by_name(name)
end
Given /^the global [rR]ole "([^\"]*)" may have the following [rR]ights:$/ do |role, table|
r = GlobalRole.find_by_name(role)
fail "No such role was defined: #{role}" unless r
as_admin do
available_perms = Redmine::AccessControl.permissions.collect(&:name)
r.permissions = []
table.raw.each do |perm|
permission = perm.first
unless permission.blank?
permission = permission.tr(' ', '_').underscore.to_sym
if available_perms.include?(:"#{permission}")
r.add_permission! permission
end
end
end
r.save!
end
end
Given /^the [Uu]ser (.+) has the global role (.+)$/ do |user, role|
user = User.find_by_login(user.delete("\""))
role = GlobalRole.find_by_name(role.delete("\""))
as_admin do
FactoryBot.create(:principal_role, principal: user, role: role)
end
end
When /^I select the available global role (.+)$/ do |role|
r = GlobalRole.find_by_name(role.delete("\""))
fail "No such role was defined: #{role}" unless r
steps %(
When I check "principal_role_role_ids_#{r.id}"
)
end
When /^I delete the assigned role (.+)$/ do |role|
g = GlobalRole.find_by_name(role.delete("\""))
fail "No such role was defined: #{role}" unless g
fail 'More than one or no principal has this role' if g.principal_roles.length != 1
steps %(
When I follow "Delete" within "#principal_role-#{g.principal_roles[0].id}"
)
end
Then /^I should (not )?see block with "(.+)?"$/ do |negative, id|
unless negative
expect(page).to have_css("#{id}", visible: true)
else
expect(page).to have_css("#{id}", visible: false)
end
end

@ -49,6 +49,7 @@ module OpenProject::GlobalRoles::Patches
redirect_to action: 'index'
else
define_setable_permissions
@roles = Role.order(Arel.sql('builtin, position'))
render template: 'roles/new'
end
end

@ -37,16 +37,10 @@ describe RolesController, type: :controller do
end
shared_examples_for 'global assigns' do
it {expect(assigns(:global_permissions)).to eql @global_role.setable_permissions}
it {expect(assigns(:global_roles)).to eql @global_roles}
it {expect(assigns(:global_role)).to eql @global_role}
end
shared_examples_for 'permission assigns' do
it {expect(assigns(:member_permissions)).to eql @member_role.setable_permissions}
it {expect(assigns(:global_permissions)).to eql GlobalRole.setable_permissions}
end
shared_examples_for 'successful create' do
it {expect(response).to be_redirect}
it {expect(response).to redirect_to '/admin/roles'}
@ -80,6 +74,7 @@ describe RolesController, type: :controller do
describe 'VERB', :new do
before do
@member_role = mocks_for_creating Role
allow(::Redmine::AccessControl).to receive(:sorted_modules).and_return(%w(Foo))
allow(GlobalRole).to receive(:setable_permissions).and_return(doubled_permissions)
@non_member_role = mock_model Role
mock_permissions_on @non_member_role
@ -89,12 +84,14 @@ describe RolesController, type: :controller do
get 'new'
end
it {expect(response).to be_successful}
it {expect(response).to render_template 'roles/new'}
it {expect(assigns(:member_permissions)).to eql @member_role.setable_permissions}
it {expect(assigns(:roles)).to eql @roles}
it {expect(assigns(:role)).to eql @member_role}
it {expect(assigns(:global_permissions)).to eql GlobalRole.setable_permissions}
it 'renders new' do
expect(response).to be_successful
expect(response).to render_template 'roles/new'
expect(assigns(:permissions))
.to eql([['Foo', @member_role.setable_permissions]])
expect(assigns(:roles)).to eql @roles
expect(assigns(:role)).to eql @member_role
end
end
describe 'VERB', :edit do
@ -187,7 +184,6 @@ describe RolesController, type: :controller do
it_should_behave_like 'failed create'
it {expect(assigns(:role)).to eql @member_role}
it {expect(assigns(:roles)).to eql Role.all}
it_should_behave_like 'permission assigns'
end
end
end
@ -233,7 +229,6 @@ describe RolesController, type: :controller do
it_should_behave_like 'failed create'
it {expect(assigns(:role)).to eql @global_role}
it {expect(assigns(:roles)).to eql Role.all}
it_should_behave_like 'permission assigns'
end
end
end

@ -0,0 +1,105 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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_relative '../spec_helper'
describe 'Global role: Global Create project', type: :feature, js: true do
let(:user) { FactoryBot.create(:admin) }
let(:project) { FactoryBot.create :project }
before do
login_as(user)
end
describe 'Create Project is not a member permission' do
# Given there is a role "Member"
let!(:role) { FactoryBot.create(:role, name: 'Member') }
# And I am already admin
# When I go to the edit page of the role "Member"
# Then I should not see "Create project"
it 'does not show the global permission' do
visit edit_role_path(role)
expect(page).to have_selector('.form--label-with-check-box', text: 'Edit project')
expect(page).to have_no_selector('.form--label-with-check-box', text: 'Create project')
end
end
describe 'Create Project is a global permission' do
# Given there is a global role "Global"
let!(:role) { FactoryBot.create(:global_role, name: 'Global') }
# And I am already admin
# When I go to the edit page of the role "Global"
# Then I should see "Create project"
it 'does show the global permission' do
visit edit_role_path(role)
expect(page).to have_no_selector('.form--label-with-check-box', text: 'Edit project')
expect(page).to have_selector('.form--label-with-check-box', text: 'Create project')
end
end
describe 'Create Project displayed to user' do
# Given there is a global role "Global"
let!(:role) { FactoryBot.create(:global_role, name: 'Global', permissions: %i[add_project]) }
# And the global role "Global" may have the following rights:
# And the user "bob" has the global role "Global"
let(:user) { FactoryBot.create :user }
let!(:principal_role) { FactoryBot.create(:principal_role, principal: user, role: role) }
# When I am already logged in as "bob"
it 'does show the global permission' do
# And I go to the overall projects page
visit projects_path
# Then I should see "Project" within ".toolbar-items
expect(page).to have_selector('.button.-alt-highlight', text: 'Project')
# Can add new project
visit new_project_path
fill_in 'project_name', with: 'New project name'
click_on 'Create'
expect(page).to have_text 'Successful creation.'
expect(current_path).to match /projects\/new-project-name/
end
end
describe 'Create Project not displayed to user without global role' do
# Given there is 1 User with:
# | Login | bob |
# | Firstname | Bob |
# | Lastname | Bobbit |
# When I am already logged in as "bob"
let(:user) { FactoryBot.create :user }
it 'does show the global permission' do
# And I go to the overall projects page
visit projects_path
# Then I should not see "Project" within ".toolbar-items"
expect(page).to have_no_selector('.button.-alt-highlight', text: 'Project')
end
end
end

@ -0,0 +1,108 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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_relative '../spec_helper'
describe 'Global role: Global role assignment', type: :feature, js: true do
before do
login_as(current_user)
end
# @javascript
describe 'Going to the global role assignment page' do
# Given there is the global permission "global1" of the module "global"
# And there is the global permission "global2" of the module "global"
before do
mock_global_permissions [['global1', project_module: :global], ['global2', project_module: :global]]
end
# And there is a global role "global_role1"
let!(:global_role1) { FactoryBot.create :global_role, name: 'global_role1', permissions: %i[global1] }
# And there is a global role "global_role2"
let!(:global_role2) { FactoryBot.create :global_role, name: 'global_role2', permissions: %i[global2] }
# And there is 1 User with:
# | Login | bob |
# | Firstname | Bob |
# | Lastname | Bobbit |
# And the user "bob" has the global role "global_role1"
let!(:user) { FactoryBot.create :user }
let!(:principal_role) { FactoryBot.create(:principal_role, principal: user, role: global_role1) }
# And I am already admin
let(:current_user) { FactoryBot.create :admin }
it 'allows global roles management' do
# When I go to the edit page of the user called "bob"
visit edit_user_path user
# And I click on "tab-global_roles"
page.find('#tab-global_roles').click
# Then I should see "global_role1" within "#table_principal_roles"
page.within('#table_principal_roles') do
expect(page).to have_text 'global_role1'
end
# And I should not see "global_role1" within "#available_principal_roles"
# And I should see "global_role2" within "#available_principal_roles"
page.within('#available_principal_roles') do
expect(page).to have_no_text 'global_role1'
expect(page).to have_text 'global_role2'
end
# And I select the available global role "global_role"
check 'global_role2'
# And I press "Add"
click_on 'Add'
# Then I should see "global_role" within "#table_principal_roles"
page.within('#available_principal_roles') do
expect(page).to have_no_text 'global_role1'
expect(page).to have_no_text 'global_role2'
end
# And I should not see "global_role" within "#available_principal_roles"
# And I should see "There is currently nothing to display"
page.within('#table_principal_roles') do
expect(page).to have_text 'global_role1'
expect(page).to have_text 'global_role2'
end
# And I delete the assigned role "global_role"
page.within("#principal_role-#{principal_role.id}") do
page.find('.buttons a.icon-delete').click
end
# Then I should see "global_role" within "#table_principal_roles"
page.within('#available_principal_roles') do
expect(page).to have_text 'global_role1'
expect(page).to have_no_text 'global_role2'
end
# And I should not see "global_role" within "#available_principal_roles"
# And I should see "There is currently nothing to display"
page.within('#table_principal_roles') do
expect(page).to have_no_text 'global_role1'
expect(page).to have_text 'global_role2'
end
end
end
end

@ -0,0 +1,64 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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_relative '../spec_helper'
describe 'Global role: Global role CRUD', type: :feature, js: true do
# Scenario: Global Role creation
# Given there is the global permission "glob_test" of the module "global_group"
before do
mock_global_permissions [['glob_test', project_module: 'global_group']]
login_as(current_user)
end
# And I am already admin
let(:current_user) { FactoryBot.create :admin }
it 'can create global role with that perm' do
# When I go to the new page of "Role"
visit new_role_path
# Then I should not see block with "#global_permissions"
expect(page).to have_no_selector('#global_permissions', visible: true)
# When I check "Global Role"
check 'Global Role'
# Then I should see block with "#global_permissions"
expect(page).to have_selector('#global_permissions', visible: true)
# And I should see "Global group"
expect(page).to have_text 'GLOBAL GROUP'
# And I should see "Glob test"
expect(page).to have_text 'Glob test'
# And I should not see "Issues can be assigned to this role"
expect(page).to have_no_text 'Issues can be assigned to this role'
# When I fill in "Name" with "Manager"
fill_in 'Name', with: 'Manager'
# And I click on "Create"
click_on 'Create'
# Then I should see "Successful creation."
expect(page).to have_text 'Successful creation.'
end
end

@ -0,0 +1,63 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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_relative '../spec_helper'
describe 'Global role: Unchanged Member Roles', type: :feature, js: true do
let(:admin) { FactoryBot.create(:admin) }
let(:project) { FactoryBot.create :project }
let!(:role) { FactoryBot.create(:role, name: 'MemberRole1') }
let!(:global_role) { FactoryBot.create(:global_role, name: 'GlobalRole1') }
let(:members) { ::Pages::Members.new project.identifier }
before do
login_as(admin)
end
scenario 'Global Rights Modules do not exist as Project -> Settings -> Modules' do
# Scenario: Global Roles should not be displayed as assignable project roles
# Given there is 1 project with the following:
# | Name | projectname |
# | Identifier | projectid |
# And there is a global role "GlobalRole1"
# And there is a role "MemberRole1"
# And I am already admin
# When I go to the members page of the project "projectid"
visit project_members_path(project)
# And I click "Add member"
members.open_new_member!
# Then I should see "MemberRole1" within "#member_role_ids"
members.expect_role 'MemberRole1'
# Then I should not see "GlobalRole1" within "#member_role_ids"
members.expect_role 'GlobalRole1', present: false
end
end

@ -0,0 +1,59 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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_relative '../spec_helper'
describe 'Global role: No module', type: :feature, js: true do
let(:admin) { FactoryBot.create(:admin) }
let(:project) { FactoryBot.create :project }
let!(:role) { FactoryBot.create(:role) }
before do
login_as(admin)
end
scenario 'Global Rights Modules do not exist as Project -> Settings -> Modules' do
# Scenario:
# Given there is the global permission "glob_test" of the module "global"
mock_global_permissions [['global_perm1', project_module: :global]]
# And there is 1 project with the following:
# | name | test |
# | identifier | test |
# And I am already admin
# When I go to the modules tab of the settings page for the project "test"
# Then I should not see "Global"
visit settings_project_path(project, tab: 'modules')
expect(page).to have_selector('#tab-content-modules')
page.within('#tab-content-modules') do
expect(page).to have_text 'Activity'
expect(page).to have_no_text 'Foo'
end
end
end

@ -20,14 +20,6 @@
module OpenProject
module GlobalRoles
module PluginSpecHelper
def mobile_tan_plugin_loaded?
plugin_loaded?('openproject_mobile_otp')
end
def privacy_plugin_loaded?
plugin_loaded?('openproject_dtag_customizing')
end
def costs_plugin_loaded?
plugin_loaded?('openproject_costs')
end
@ -123,10 +115,10 @@ module OpenProject
end
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)
@public_perm = mock_permissions('public_perm1', public: true)
@perm1 = mock_permissions('member_perm1')
@perm2 = mock_permissions('member_perm2')
@global_perm = mock_permissions('global_perm1', global: true)
@perms = [@public_perm, @perm1, @global_perm, @perm2]
allow(Redmine::AccessControl).to receive(:permissions).and_return(@perms)
@ -134,12 +126,32 @@ module OpenProject
allow(Redmine::AccessControl).to receive(:global_permissions).and_return([@global_perm])
end
def mock_permissions(is_public, is_global)
permission = Object.new
allow(permission).to receive(:public?).and_return(is_public)
allow(permission).to receive(:global?).and_return(is_global)
allow(permission).to receive(:project_module).and_return('Foo')
permission
def mock_global_permissions(permissions)
mapped = permissions.map do |name, options|
mock_permissions(name, options.merge(global: true))
end
mapped_modules = permissions.map do |_, options|
options[:project_module] || 'Foo'
end.uniq
allow(Redmine::AccessControl).to receive(:modules).and_wrap_original do |m, *args|
m.call(*args) + mapped_modules.map { |name| { order: 0, name: name } }
end
allow(Redmine::AccessControl).to receive(:permissions).and_wrap_original do |m, *args|
m.call(*args) + mapped
end
allow(Redmine::AccessControl).to receive(:global_permissions).and_wrap_original do |m, *args|
m.call(*args) + mapped
end
end
def mock_permissions(name, options = {})
::Redmine::AccessControl::Permission.new(
name,
{ does_not: :matter },
{ project_module: 'Foo', public: false, global: false }.merge(options)
)
end
def create_non_member_role

@ -213,6 +213,10 @@ module Pages
select.select role_name
end
def expect_role(role_name, present: true)
expect(page).to have_conditional_selector(present, '#member_role_ids option', text: role_name)
end
def enter_principal_search!(principal_name)
find('#s2id_member_user_ids')
.find('.select2-choices .select2-input')

Loading…
Cancel
Save