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
Restore suppressing of notifications in groups service
Oliver Günther447151fc9814
diff --git a/app/models/journal/notification_configuration.rb b/app/models/journal/notification_configuration.rbindex 1d31bf97d45..b52f676b0b7 100644--- a/app/models/journal/notification_configuration.rb+++ b/app/models/journal/notification_configuration.rb@@ -61,10 +61,10 @@ class Journal::NotificationConfigurationenddef log_warning(send_notifications)- return if active == send_notifications+ return if active? == send_notificationsmessage = <<~MSG- Ignoring setting journal notifications to '#{send_notifications}' as a parent block already set it to #{active}"+ Ignoring setting journal notifications to '#{send_notifications}' as a parent block already set it to #{active?}"MSGRails.logger.debug messageenddiff --git a/app/services/base_services/write.rb b/app/services/base_services/write.rbindex 26e3e0d7275..dd238c8ef18 100644--- a/app/services/base_services/write.rb+++ b/app/services/base_services/write.rb@@ -77,7 +77,7 @@ module BaseServicesenddef set_attributes_params(params)- params+ params.except(:send_notifications)endendenddiff --git a/app/services/groups/add_users_service.rb b/app/services/groups/add_users_service.rbindex 6389fc87683..86c945198be 100644--- a/app/services/groups/add_users_service.rb+++ b/app/services/groups/add_users_service.rb@@ -52,7 +52,11 @@ module Groupsdef after_perform(call)Groups::CreateInheritedRolesService.new(model, current_user: user, contract_class:)- .call(user_ids: params[:ids], message: params[:message])+ .call(+ user_ids: params[:ids],+ message: params[:message],+ send_notifications: params.fetch(:send_notifications, true)+ )callenddiff --git a/app/services/groups/update_service.rb b/app/services/groups/update_service.rbindex 72a3ced7e06..ade44280976 100644--- a/app/services/groups/update_service.rb+++ b/app/services/groups/update_service.rb@@ -49,7 +49,7 @@ class Groups::UpdateService < ::BaseServices::Updateif new_user_ids.any?db_call = ::Groups::AddUsersService.new(call.result, current_user: user)- .call(ids: new_user_ids)+ .call(ids: new_user_ids, send_notifications: params.fetch(:send_notifications, true))call.add_dependent!(db_call)enddiff --git a/spec/factories/group_factory.rb b/spec/factories/group_factory.rbindex 119e95b7d4c..f6ad55a332e 100644--- a/spec/factories/group_factory.rb+++ b/spec/factories/group_factory.rb@@ -42,7 +42,7 @@ FactoryBot.define doUser.system.run_given do |system_user|Groups::AddUsersService.new(group, current_user: system_user)- .call(ids: members.map(&:id))+ .call(ids: members.map(&:id), send_notifications: false).on_failure { |call| raise call.message }endenddiff --git a/spec/services/groups/update_roles_service_integration_spec.rb b/spec/services/groups/update_roles_service_integration_spec.rbindex 7b29c87b46b..9f8b820c342 100644--- a/spec/services/groups/update_roles_service_integration_spec.rb+++ b/spec/services/groups/update_roles_service_integration_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'describe Groups::UpdateRolesService, 'integration', type: :model do- subject(:service_call) { instance.call(member:, message:) }+ subject(:service_call) { instance.call(member:, message:, send_notifications:) }let(:project) { create :project }let(:role) { create :role }@@ -46,12 +46,13 @@ describe Groups::UpdateRolesService, 'integration', type: :model do::Groups::CreateInheritedRolesService.new(group, current_user: User.system, contract_class: EmptyContract)- .call(user_ids: users.map(&:id))+ .call(user_ids: users.map(&:id), send_notifications: false)endendlet(:users) { create_list :user, 2 }let(:member) { Member.find_by(principal: group) }let(:message) { "Some message" }+ let(:send_notifications) { true }let(:instance) dodescribed_class.new(group, current_user:)@@ -89,6 +90,15 @@ describe Groups::UpdateRolesService, 'integration', type: :model doendend+ shared_examples_for 'sends no notification' do+ it 'on the updated membership' do+ service_call++ expect(Notifications::GroupMemberAlteredJob)+ .not_to have_received(:perform_later)+ end+ end+context 'when adding a role' dolet(:added_role) { create(:role) }@@ -113,6 +123,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'with global membership' do@@ -154,6 +170,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when removing a global role' do@@ -180,6 +202,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendend@@ -222,6 +250,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users.last }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when removing a role' do@@ -248,6 +282,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when removing a role but with a user having had the role before (no inherited_from)' do@@ -290,6 +330,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users.last }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when replacing roles' do@@ -316,6 +362,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when replacing a role but with a user having had the replaced role before (no inherited_from)' do@@ -358,6 +410,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when adding a role and the user has a role already granted by a different group' do@@ -373,7 +431,7 @@ describe Groups::UpdateRolesService, 'integration', type: :model do::Groups::CreateInheritedRolesService.new(group, current_user: User.system, contract_class: EmptyContract)- .call(user_ids: users.map(&:id))+ .call(user_ids: users.map(&:id), send_notifications: false)endend@@ -399,6 +457,12 @@ describe Groups::UpdateRolesService, 'integration', type: :model doit_behaves_like 'sends notification' dolet(:user) { users }end++ context 'when notifications are suppressed' do+ let(:send_notifications) { false }++ it_behaves_like 'sends no notification'+ endendcontext 'when not allowed' dodiff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rbindex e88d729ea1f..703e0293338 100644--- a/spec/services/groups/update_service_spec.rb+++ b/spec/services/groups/update_service_spec.rb@@ -76,7 +76,7 @@ describe Groups::UpdateService, type: :model doexpect(add_users_service).to have_received(:call)- .with(ids: [new_group_user.user_id])+ .with(ids: [new_group_user.user_id], send_notifications: true)endend@@ -94,7 +94,7 @@ describe Groups::UpdateService, type: :model doexpect(add_users_service).to have_received(:call)- .with(ids: [new_group_user.user_id])+ .with(ids: [new_group_user.user_id], send_notifications: true)endend