mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-02 00:44:47 -04:00
FIX: refresh automatic group if SSO specifies admin/mod
This commit is contained in:
parent
75d8e6f1ec
commit
b04ab83f12
2 changed files with 28 additions and 0 deletions
|
@ -72,11 +72,17 @@ class DiscourseSingleSignOn < SingleSignOn
|
||||||
end
|
end
|
||||||
|
|
||||||
user.ip_address = ip_address
|
user.ip_address = ip_address
|
||||||
|
|
||||||
user.admin = admin unless admin.nil?
|
user.admin = admin unless admin.nil?
|
||||||
user.moderator = moderator unless moderator.nil?
|
user.moderator = moderator unless moderator.nil?
|
||||||
|
|
||||||
# optionally save the user and sso_record if they have changed
|
# optionally save the user and sso_record if they have changed
|
||||||
user.save!
|
user.save!
|
||||||
|
|
||||||
|
unless admin.nil? && moderator.nil?
|
||||||
|
Group.refresh_automatic_groups!(:admins, :moderators, :staff)
|
||||||
|
end
|
||||||
|
|
||||||
sso_record.save!
|
sso_record.save!
|
||||||
|
|
||||||
sso_record && sso_record.user
|
sso_record && sso_record.user
|
||||||
|
|
|
@ -64,6 +64,28 @@ describe DiscourseSingleSignOn do
|
||||||
expect(user).to_not be_nil
|
expect(user).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can set admin and moderator" do
|
||||||
|
admin_group = Group[:admins]
|
||||||
|
mod_group = Group[:moderators]
|
||||||
|
staff_group = Group[:staff]
|
||||||
|
|
||||||
|
sso = DiscourseSingleSignOn.new
|
||||||
|
sso.username = "misteradmin"
|
||||||
|
sso.name = "Bob Admin"
|
||||||
|
sso.email = "admin@admin.com"
|
||||||
|
sso.external_id = "id"
|
||||||
|
sso.admin = true
|
||||||
|
sso.moderator = true
|
||||||
|
|
||||||
|
user = sso.lookup_or_create_user(ip_address)
|
||||||
|
staff_group.reload
|
||||||
|
|
||||||
|
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
|
it "can override name / email / username" do
|
||||||
admin = Fabricate(:admin)
|
admin = Fabricate(:admin)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue