diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb index 9b68b8b03ad..37a37a978c4 100644 --- a/app/models/invite_redeemer.rb +++ b/app/models/invite_redeemer.rb @@ -28,11 +28,6 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f user = User.new(email: invite.email, username: available_username, name: available_name, active: true, trust_level: SiteSetting.default_invitee_trust_level) - if password - user.password_required! - user.password = password - end - if !SiteSetting.must_approve_users? || (SiteSetting.must_approve_users? && invite.invited_by.staff?) user.approved = true user.approved_by_id = invite.invited_by_id @@ -52,9 +47,14 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f end user.moderator = true if invite.moderator? && invite.invited_by.staff? - user.save! - user + if password + user.password = password + user.password_required! + end + + user.save! + User.find(user.id) end private diff --git a/spec/models/invite_redeemer_spec.rb b/spec/models/invite_redeemer_spec.rb index 9c2c0de93ca..49b800daa22 100644 --- a/spec/models/invite_redeemer_spec.rb +++ b/spec/models/invite_redeemer_spec.rb @@ -107,5 +107,14 @@ describe InviteRedeemer do expect(user.custom_fields["user_field_#{required_field.id}"]).to eq('value1') expect(user.custom_fields["user_field_#{optional_field.id}"]).to eq('value2') end + + it "adds user to group" do + group = Fabricate(:group, grant_trust_level: 2) + InvitedGroup.create(group_id: group.id, invite_id: invite.id) + user = InviteRedeemer.new(invite, username, name, password).redeem + + expect(user.group_users.count).to eq(4) + expect(user.trust_level).to eq(2) + end end end