Merge pull request #5357 from techAPJ/invite-trust-level

FIX: invited users were not granted trust level based on their group
This commit is contained in:
Arpit Jalan 2017-11-23 23:42:20 +05:30 committed by GitHub
commit 406ad1a1f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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