mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Trust Level 3: invited users start at default_invitee_trust_level + 1, unless default_invitee_trust_level is 2 or higher
This commit is contained in:
parent
0c0833d6b9
commit
1806a7d4b3
3 changed files with 35 additions and 9 deletions
|
@ -9,19 +9,26 @@ InviteRedeemer = Struct.new(:invite) do
|
|||
end
|
||||
|
||||
# extracted from User cause it is very specific to invites
|
||||
def self.create_user_for_email(email)
|
||||
username = UserNameSuggester.suggest(email)
|
||||
def self.create_user_from_invite(invite)
|
||||
username = UserNameSuggester.suggest(invite.email)
|
||||
|
||||
DiscourseHub.nickname_operation do
|
||||
match, available, suggestion = DiscourseHub.nickname_match?(username, email)
|
||||
match, available, suggestion = DiscourseHub.nickname_match?(username, invite.email)
|
||||
username = suggestion unless match || available
|
||||
end
|
||||
|
||||
user = User.new(email: email, username: username, name: username, active: true)
|
||||
user.trust_level = SiteSetting.default_invitee_trust_level
|
||||
user = User.new(email: invite.email, username: username, name: username, active: true)
|
||||
if invite.invited_by and invite.invited_by.has_trust_level?(:leader)
|
||||
# People invited by users with trust level 3 will start at the default trust level + 1,
|
||||
# unless the default trust level is 2 or higher.
|
||||
user.trust_level = SiteSetting.default_invitee_trust_level
|
||||
user.trust_level += 1 if user.trust_level < TrustLevel.levels[:regular]
|
||||
else
|
||||
user.trust_level = SiteSetting.default_invitee_trust_level
|
||||
end
|
||||
user.save!
|
||||
|
||||
DiscourseHub.nickname_operation { DiscourseHub.register_nickname(username, email) }
|
||||
DiscourseHub.nickname_operation { DiscourseHub.register_nickname(username, invite.email) }
|
||||
|
||||
user
|
||||
end
|
||||
|
@ -52,7 +59,7 @@ InviteRedeemer = Struct.new(:invite) do
|
|||
|
||||
def get_invited_user
|
||||
result = get_existing_user
|
||||
result ||= InviteRedeemer.create_user_for_email(invite.email)
|
||||
result ||= InviteRedeemer.create_user_from_invite(invite)
|
||||
result.send_welcome_message = false
|
||||
result
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe InviteRedeemer do
|
||||
|
||||
describe '#create_for_email' do
|
||||
let(:user) { InviteRedeemer.create_user_for_email('walter.white@email.com') }
|
||||
let(:user) { InviteRedeemer.create_user_from_invite(Fabricate(:invite, email: 'walter.white@email.com')) }
|
||||
it "should be created correctly" do
|
||||
user.username.should == 'walter_white'
|
||||
user.name.should == 'walter_white'
|
||||
|
|
|
@ -165,10 +165,29 @@ describe Invite do
|
|||
invite.redeem.trust_level.should == TrustLevel.levels[:leader]
|
||||
end
|
||||
|
||||
context "invited by a trust level 3 user" do
|
||||
let(:leader) { Fabricate(:user, trust_level: TrustLevel.levels[:leader]) }
|
||||
let(:invitation) { Fabricate(:invite, invited_by: leader) }
|
||||
|
||||
it "default_invitee_trust_level is 1, then invited user should be trust level 2" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:basic])
|
||||
invitation.redeem.trust_level.should == TrustLevel.levels[:regular]
|
||||
end
|
||||
|
||||
it "default_invitee_trust_level is 2, then invited user should be trust level 2" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:regular])
|
||||
invitation.redeem.trust_level.should == TrustLevel.levels[:regular]
|
||||
end
|
||||
|
||||
it "default_invitee_trust_level is 3, then invited user should be trust level 3" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:leader])
|
||||
invitation.redeem.trust_level.should == TrustLevel.levels[:leader]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'inviting when must_approve_users? is enabled' do
|
||||
it 'correctly acitvates accounts' do
|
||||
it 'correctly activates accounts' do
|
||||
SiteSetting.stubs(:must_approve_users).returns(true)
|
||||
user = invite.redeem
|
||||
|
||||
|
|
Loading…
Reference in a new issue