FIX: Write to group logs when a user is added to group by invite (#18841)

This commit is contained in:
Osama Sayegh 2022-11-03 01:58:12 +03:00 committed by GitHub
parent 2e984f2eca
commit 391a456443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -209,6 +209,7 @@ class InviteRedeemer
group = Group.find_by(id: id)
if guardian.can_edit_group?(group)
invited_user.group_users.create!(group_id: group.id)
GroupActionLogger.new(invite.invited_by, group).log_add_user_to_group(invited_user)
DiscourseEvent.trigger(:user_added_to_group, invited_user, group, automatic: false)
end
end

View File

@ -216,6 +216,30 @@ RSpec.describe InviteRedeemer do
expect(user.trust_level).to eq(2)
end
it "adds an entry to the group logs when the invited user is added to a group" do
group = Fabricate(:group)
InvitedGroup.create(group_id: group.id, invite_id: invite.id)
group.add_owner(invite.invited_by)
GroupHistory.destroy_all
user = InviteRedeemer.new(
invite: invite,
email: invite.email,
username: username,
name: name,
password: password
).redeem
expect(group.reload.usernames.split(",")).to include(user.username)
expect(GroupHistory.exists?(
target_user_id: user.id,
acting_user: invite.invited_by.id,
group_id: group.id,
action: GroupHistory.actions[:add_user_to_group]
)).to eq(true)
end
it "only allows one user to be created per invite" do
user = invite_redeemer.redeem
invite.reload