fix bug: no more anonymous user when notifying of group membership removals

before, the email sent on group membership removal/ deletion was from Anonymous user. Now it is from the real user having performed the action in the administration
pull/10063/head
Christophe Bliard 3 years ago
parent 8ad0c9c070
commit 582c811091
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 7
      app/services/groups/concerns/membership_manipulation.rb
  2. 14
      app/workers/notifications/group_member_altered_job.rb
  3. 3
      spec/services/groups/add_users_service_integration_spec.rb
  4. 6
      spec/services/groups/cleanup_inherited_roles_service_integration_spec.rb
  5. 3
      spec/services/groups/update_roles_service_integration_spec.rb
  6. 15
      spec/workers/notifications/group_member_altered_job_spec.rb

@ -78,7 +78,12 @@ module Groups::Concerns
end
def send_notifications(member_ids, message, send_notifications)
Notifications::GroupMemberAlteredJob.perform_later(member_ids, message, send_notifications)
Notifications::GroupMemberAlteredJob.perform_later(
User.current,
member_ids,
message,
send_notifications
)
end
end
end

@ -31,12 +31,14 @@
class Notifications::GroupMemberAlteredJob < ApplicationJob
queue_with_priority :notification
def perform(members_ids, message, send_notifications)
each_member(members_ids) do |member|
OpenProject::Notifications.send(event_type(member),
member: member,
message: message,
send_notifications: send_notifications)
def perform(current_user, members_ids, message, send_notifications)
User.execute_as(current_user) do
each_member(members_ids) do |member|
OpenProject::Notifications.send(event_type(member),
member: member,
message: message,
send_notifications: send_notifications)
end
end
end

@ -76,7 +76,8 @@ describe Groups::AddUsersService, 'integration', type: :model do
expect(Notifications::GroupMemberAlteredJob)
.to have_received(:perform_later)
.with(a_collection_containing_exactly(*ids),
.with(current_user,
a_collection_containing_exactly(*ids),
message,
true)
end

@ -145,7 +145,8 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
expect(Notifications::GroupMemberAlteredJob)
.to have_received(:perform_later)
.with([first_user_member.id],
.with(current_user,
[first_user_member.id],
message,
true)
end
@ -187,7 +188,8 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
expect(Notifications::GroupMemberAlteredJob)
.to have_received(:perform_later)
.with([first_user_member.id],
.with(current_user,
[first_user_member.id],
message,
true)
end

@ -82,7 +82,8 @@ describe Groups::UpdateRolesService, 'integration', type: :model do
expect(Notifications::GroupMemberAlteredJob)
.to have_received(:perform_later)
.with(a_collection_containing_exactly(*Member.where(principal: user).pluck(:id)),
.with(current_user,
a_collection_containing_exactly(*Member.where(principal: user).pluck(:id)),
message,
true)
end

@ -32,9 +32,10 @@ require 'spec_helper'
describe Notifications::GroupMemberAlteredJob, type: :model do
subject(:service_call) do
described_class.new.perform(members_ids, message, send_notification)
described_class.new.perform(current_user, members_ids, message, send_notification)
end
let(:current_user) { build_stubbed(:user) }
let(:time) { Time.now }
let(:member1) do
build_stubbed(:member, updated_at: time, created_at: time)
@ -72,4 +73,16 @@ describe Notifications::GroupMemberAlteredJob, type: :model do
.to have_received(:send)
.with(OpenProject::Events::MEMBER_UPDATED, member: member2, message: message, send_notifications: send_notification)
end
it 'propagates the given current user when sending notifications' do
notifications_called = false
allow(OpenProject::Notifications)
.to receive(:send) do |_args|
expect(User.current).to be(current_user)
notifications_called = true
end
service_call
expect(notifications_called).to be(true)
end
end

Loading…
Cancel
Save