[35508] Add global permission to manage placeholder users (#9000)
* Add global permission to manage (but not delete) placeholders https://community.openproject.com/work_packages/35508 * Restore breadcrumbs for non-show routes * Remove permissions to memberships for add_placeholder_user permission * Allow non-admins with global permission to access membership * Remove permissions to memberships for add_placeholder_user permission * Rename shared_examples for admin contract validations Co-authored-by: ulferts <jens.ulferts@googlemail.com>pull/9019/head
parent
cd628b5c75
commit
bbeae32698
@ -0,0 +1,93 @@ |
||||
shared_context 'principal membership management context' do |
||||
shared_let(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' } |
||||
shared_let(:project2) { FactoryBot.create :project, name: 'Project 2', identifier: 'project2' } |
||||
|
||||
shared_let(:manager) { FactoryBot.create :role, name: 'Manager', permissions: %i[view_members manage_members] } |
||||
shared_let(:developer) { FactoryBot.create :role, name: 'Developer' } |
||||
end |
||||
|
||||
shared_examples 'principal membership management flows' do |
||||
scenario 'handles role modification flow' do |
||||
principal_page.visit! |
||||
principal_page.open_projects_tab! |
||||
|
||||
principal_page.add_to_project! project.name, as: 'Manager' |
||||
|
||||
member = principal.memberships.where(project_id: project.id).first |
||||
principal_page.edit_roles!(member, %w(Manager Developer)) |
||||
|
||||
# Modify roles |
||||
principal_page.expect_project(project.name) |
||||
principal_page.expect_roles(project.name, %w(Manager Developer)) |
||||
|
||||
principal_page.expect_no_membership(project2.name) |
||||
|
||||
# Remove all roles |
||||
principal_page.expect_project(project.name) |
||||
principal_page.edit_roles!(member, %w()) |
||||
|
||||
expect(page).to have_selector('.flash.error', text: 'Roles need to be assigned.') |
||||
|
||||
# Remove the user from the project |
||||
principal_page.remove_from_project!(project.name) |
||||
principal_page.expect_no_membership(project.name) |
||||
|
||||
# Re-add the user |
||||
principal_page.add_to_project! project.name, as: %w(Manager Developer) |
||||
|
||||
principal_page.expect_project(project.name) |
||||
principal_page.expect_roles(project.name, %w(Manager Developer)) |
||||
end |
||||
end |
||||
|
||||
shared_examples 'global user principal membership management flows' do |permission| |
||||
context 'as global user' do |
||||
shared_let(:global_user) { FactoryBot.create :user, global_permission: permission } |
||||
current_user { global_user } |
||||
|
||||
context 'when the user is member in the projects' do |
||||
it_behaves_like 'principal membership management flows' do |
||||
before do |
||||
project.add_member global_user, [manager] |
||||
project.save! |
||||
|
||||
project2.add_member global_user, [manager] |
||||
project2.save! |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'when the user cannot see the two projects' do |
||||
it 'does not show them' do |
||||
principal_page.visit! |
||||
principal_page.open_projects_tab! |
||||
|
||||
expect(page).to have_no_selector('#membership_project_id option', text: project.name, visible: :all) |
||||
expect(page).to have_no_selector('#membership_project_id option', text: project2.name, visible: :all) |
||||
end |
||||
|
||||
it 'does not show the membership' do |
||||
project.add_member principal, [developer] |
||||
project.save! |
||||
|
||||
principal_page.visit! |
||||
principal_page.open_projects_tab! |
||||
|
||||
expect(page).to have_no_selector('tr.member') |
||||
expect(page).to have_text 'There is currently nothing to display.' |
||||
expect(page).to have_no_text project2.name |
||||
expect(page).to have_no_text project2.name |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'as user without global permission' do |
||||
current_user { FactoryBot.create :user } |
||||
|
||||
it 'returns an error' do |
||||
principal_page.visit! |
||||
expect(page).to have_text 'You are not authorized to access this page.' |
||||
expect(page).to have_no_text principal.name |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,36 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 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-2013 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' |
||||
require 'services/base_services/behaves_like_create_service' |
||||
|
||||
describe PlaceholderUsers::CreateService, type: :model do |
||||
it_behaves_like 'BaseServices create service' |
||||
end |
@ -0,0 +1,116 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 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-2013 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 PlaceholderUsers::SetAttributesService, type: :model do |
||||
let(:current_user) { FactoryBot.build_stubbed(:user) } |
||||
|
||||
let(:contract_instance) do |
||||
contract = double('contract_instance') |
||||
allow(contract) |
||||
.to receive(:validate) |
||||
.and_return(contract_valid) |
||||
allow(contract) |
||||
.to receive(:errors) |
||||
.and_return(contract_errors) |
||||
contract |
||||
end |
||||
|
||||
let(:contract_errors) { double('contract_errors') } |
||||
let(:contract_valid) { true } |
||||
let(:model_valid) { true } |
||||
|
||||
let(:instance) do |
||||
described_class.new(user: current_user, |
||||
model: model_instance, |
||||
contract_class: contract_class, |
||||
contract_options: {}) |
||||
end |
||||
let(:model_instance) { PlaceholderUser.new } |
||||
let(:contract_class) do |
||||
allow(PlaceholderUsers::CreateContract) |
||||
.to receive(:new) |
||||
.and_return(contract_instance) |
||||
|
||||
PlaceholderUsers::CreateContract |
||||
end |
||||
|
||||
let(:params) { {} } |
||||
|
||||
before do |
||||
allow(model_instance) |
||||
.to receive(:valid?) |
||||
.and_return(model_valid) |
||||
end |
||||
|
||||
subject { instance.call(params) } |
||||
|
||||
it 'returns the instance as the result' do |
||||
expect(subject.result) |
||||
.to eql model_instance |
||||
end |
||||
|
||||
it 'is a success' do |
||||
is_expected |
||||
.to be_success |
||||
end |
||||
|
||||
context 'with params' do |
||||
let(:params) do |
||||
{ |
||||
name: 'Foobar' |
||||
} |
||||
end |
||||
|
||||
it 'assigns the params' do |
||||
subject |
||||
|
||||
expect(model_instance.name).to eq 'Foobar' |
||||
expect(model_instance.lastname).to eq 'Foobar' |
||||
end |
||||
end |
||||
|
||||
context 'with an invalid contract' do |
||||
let(:contract_valid) { false } |
||||
let(:expect_time_instance_save) do |
||||
expect(model_instance) |
||||
.not_to receive(:save) |
||||
end |
||||
|
||||
it 'returns failure' do |
||||
is_expected |
||||
.not_to be_success |
||||
end |
||||
|
||||
it "returns the contract's errors" do |
||||
expect(subject.errors) |
||||
.to eql(contract_errors) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,36 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 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-2013 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' |
||||
require 'services/base_services/behaves_like_update_service' |
||||
|
||||
describe PlaceholderUsers::UpdateService, type: :model do |
||||
it_behaves_like 'BaseServices update service' |
||||
end |
Loading…
Reference in new issue