Skip to content

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

[38017] Don't remove group users if no replacement provided

Oliver Günther843779c48304
diff --git a/app/services/groups/set_attributes_service.rb b/app/services/groups/set_attributes_service.rb
index b3edb371ad8..94a98ebfc82 100644
--- a/app/services/groups/set_attributes_service.rb
+++ b/app/services/groups/set_attributes_service.rb
@@ -33,7 +33,7 @@ module Groups
private
def set_attributes(params)
- set_users(params)
+ set_users(params) if params.key?(:user_ids)
super
end
diff --git a/spec/services/groups/set_attributes_service_spec.rb b/spec/services/groups/set_attributes_service_spec.rb
index db2f0f48283..c2b1385ecc6 100644
--- a/spec/services/groups/set_attributes_service_spec.rb
+++ b/spec/services/groups/set_attributes_service_spec.rb
@@ -102,6 +102,34 @@ describe Groups::SetAttributesService, type: :model do
.not_to have_received(:save)
end
+ context 'with no changes to the users' do
+ let(:call_attributes) do
+ {
+ name: 'My new group name'
+ }
+ end
+ let(:first_user) { FactoryBot.build_stubbed(:user) }
+ let(:second_user) { FactoryBot.build_stubbed(:user) }
+ let(:first_group_user) { FactoryBot.build_stubbed(:group_user, user: first_user) }
+ let(:second_group_user) { FactoryBot.build_stubbed(:group_user, user: second_user) }
+
+ let(:group) do
+ FactoryBot.build_stubbed(:group, group_users: [first_group_user, second_group_user])
+ end
+
+ let(:updated_group) do
+ service_call.result
+ end
+
+ it 'does not change the users (Regression #38017)' do
+ expect(updated_group.name).to eq 'My new group name'
+ expect(updated_group.group_users.map(&:user_id))
+ .to eql [first_user.id, second_user.id]
+
+ expect(updated_group.group_users.any?(&:marked_for_destruction?)).to eq false
+ end
+ end
+
context 'with changes to the users do' do
let(:first_user) { FactoryBot.build_stubbed(:user) }
let(:second_user) { FactoryBot.build_stubbed(:user) }