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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
allow adding members to invalid groups
ulfertsf28013f332f2
diff --git a/app/contracts/groups/add_users_contract.rb b/app/contracts/groups/add_users_contract.rbnew file mode 100644index 00000000000..97e42c32ab2--- /dev/null+++ b/app/contracts/groups/add_users_contract.rb@@ -0,0 +1,39 @@+#-- 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.+#++++module Groups+ class AddUsersContract < Groups::BaseContract+ protected++ # No need to validate the whole of the group when we only want to ensure that the user is an admin.+ # In case more conditions are added to the BaseContract, we might need an extra AdminOnlyContract+ def validate_model?+ false+ end+ end+enddiff --git a/app/services/groups/add_users_service.rb b/app/services/groups/add_users_service.rbindex b6ac3f898e8..81042aaec44 100644--- a/app/services/groups/add_users_service.rb+++ b/app/services/groups/add_users_service.rb@@ -35,7 +35,7 @@ module Groups@group = groupsuper user: current_user,- contract_class: BaseContract+ contract_class: Groups::AddUsersContractenddef after_validate(user_ids, _call)diff --git a/spec/services/groups/add_users_service_integration_spec.rb b/spec/services/groups/add_users_service_integration_spec.rbindex 0111e454c98..481ca6962bc 100644--- a/spec/services/groups/add_users_service_integration_spec.rb+++ b/spec/services/groups/add_users_service_integration_spec.rb@@ -31,6 +31,7 @@ require 'spec_helper'describe Groups::AddUsersService, 'integration', type: :model dolet(:projects) { FactoryBot.create_list :project, 2 }let(:role) { FactoryBot.create :role }+ let(:admin) { FactoryBot.create :admin }let(:group) doFactoryBot.create :group,@@ -50,7 +51,7 @@ describe Groups::AddUsersService, 'integration', type: :model dosubject { instance.call(user_ids) }context 'as an admin user' do- using_shared_fixtures :admin+ #using_shared_fixtures :adminlet(:current_user) { admin }it 'adds the users to the group and project' do@@ -60,6 +61,22 @@ describe Groups::AddUsersService, 'integration', type: :model doexpect(user1.memberships.map(&:roles).flatten).to eq [role, role]expect(user2.memberships.map(&:roles).flatten).to eq [role, role]end++ context 'if the group has a failure (e.g. required cf not set)' do+ before do+ group+ # The group is now invalid as it has no cv for this field+ FactoryBot.create(:custom_field, type: 'GroupCustomField', is_required: true, field_format: 'int')+ end++ it 'adds the users to the group and project' do+ expect(subject).to be_success++ expect(user1.memberships.where(project_id: projects).count).to eq 2+ expect(user1.memberships.map(&:roles).flatten).to eq [role, role]+ expect(user2.memberships.map(&:roles).flatten).to eq [role, role]+ end+ endendcontext 'as not allowed' do