mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: sso override code not triggered when attaching to existing user
This commit is contained in:
parent
914dd2dd8d
commit
4566a1e30a
2 changed files with 32 additions and 8 deletions
|
@ -110,20 +110,15 @@ class DiscourseSingleSignOn < SingleSignOn
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_external_attributes_and_override(sso_record, user)
|
def change_external_attributes_and_override(sso_record, user)
|
||||||
if SiteSetting.sso_overrides_email && email != sso_record.external_email
|
if SiteSetting.sso_overrides_email && user.email != email
|
||||||
# set the user's email to whatever came in the payload
|
|
||||||
user.email = email
|
user.email = email
|
||||||
end
|
end
|
||||||
|
|
||||||
if SiteSetting.sso_overrides_username && username != sso_record.external_username && user.username != username
|
if SiteSetting.sso_overrides_username && user.username != username
|
||||||
# we have an external username change, and the user's current username doesn't match
|
|
||||||
# run it through the UserNameSuggester to override it
|
|
||||||
user.username = UserNameSuggester.suggest(username || name || email)
|
user.username = UserNameSuggester.suggest(username || name || email)
|
||||||
end
|
end
|
||||||
|
|
||||||
if SiteSetting.sso_overrides_name && name != sso_record.external_name && user.name != name
|
if SiteSetting.sso_overrides_name && user.name != name
|
||||||
# we have an external name change, and the user's current name doesn't match
|
|
||||||
# run it through the name suggester to override it
|
|
||||||
user.name = User.suggest_name(name || username || email)
|
user.name = User.suggest_name(name || username || email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,35 @@ describe DiscourseSingleSignOn do
|
||||||
expect(user).to_not be_nil
|
expect(user).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can override name / email / username" do
|
||||||
|
admin = Fabricate(:admin)
|
||||||
|
|
||||||
|
SiteSetting.sso_overrides_name = true
|
||||||
|
SiteSetting.sso_overrides_email = true
|
||||||
|
SiteSetting.sso_overrides_username = true
|
||||||
|
|
||||||
|
sso = DiscourseSingleSignOn.new
|
||||||
|
sso.username = "bob%the$admin"
|
||||||
|
sso.name = "Bob Admin"
|
||||||
|
sso.email = admin.email
|
||||||
|
sso.external_id = "A"
|
||||||
|
|
||||||
|
sso.lookup_or_create_user(ip_address)
|
||||||
|
|
||||||
|
admin.reload
|
||||||
|
|
||||||
|
expect(admin.name).to eq "Bob Admin"
|
||||||
|
expect(admin.username).to eq "bob_the_admin"
|
||||||
|
expect(admin.email).to eq admin.email
|
||||||
|
|
||||||
|
sso.email = "TEST@bob.com"
|
||||||
|
|
||||||
|
sso.lookup_or_create_user(ip_address)
|
||||||
|
|
||||||
|
admin.reload
|
||||||
|
expect(admin.email).to eq("test@bob.com")
|
||||||
|
end
|
||||||
|
|
||||||
it "can fill in data on way back" do
|
it "can fill in data on way back" do
|
||||||
sso = make_sso
|
sso = make_sso
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue