Skip to content

Commit

Permalink
FIX: unstage users when using SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Jun 21, 2016
1 parent bf7ea8b commit 874c18c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/models/discourse_single_sign_on.rb
Expand Up @@ -56,6 +56,9 @@ def lookup_or_create_user(ip_address=nil)
sso_record = user.single_sign_on_record
end

# ensure it's not staged anymore
user.staged = false

# if the user isn't new or it's attached to the SSO record we might be overriding username or email
unless user.new_record?
change_external_attributes_and_override(sso_record, user)
Expand Down
17 changes: 15 additions & 2 deletions spec/models/discourse_single_sign_on_spec.rb
Expand Up @@ -64,6 +64,21 @@ def test_parsed(parsed, sso)
expect(user).to_not be_nil
end

it "unstaged users" do
email = "staged@user.com"
Fabricate(:user, staged: true, email: email)

sso = DiscourseSingleSignOn.new
sso.username = "staged"
sso.name = "Staged User"
sso.email = email
sso.external_id = "B"
user = sso.lookup_or_create_user(ip_address)

expect(user).to_not be_nil
expect(user.staged).to be(false)
end

it "can set admin and moderator" do
admin_group = Group[:admins]
mod_group = Group[:moderators]
Expand All @@ -83,7 +98,6 @@ def test_parsed(parsed, sso)
expect(mod_group.users.where('users.id = ?', user.id).exists?).to eq(true)
expect(staff_group.users.where('users.id = ?', user.id).exists?).to eq(true)
expect(admin_group.users.where('users.id = ?', user.id).exists?).to eq(true)

end

it "can override name / email / username" do
Expand Down Expand Up @@ -156,7 +170,6 @@ def test_parsed(parsed, sso)
end

it "generates a correct sso url" do

url, payload = DiscourseSingleSignOn.generate_url.split("?")
expect(url).to eq @sso_url

Expand Down

0 comments on commit 874c18c

Please sign in to comment.