mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 05:16:39 +08:00
FEATURE: DiscourseEvent hook for sync_sso (#16329)
This commit is contained in:
parent
b974375239
commit
4d809e984d
@ -455,6 +455,7 @@ class Admin::UsersController < Admin::AdminController
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
user = sso.lookup_or_create_user
|
user = sso.lookup_or_create_user
|
||||||
|
DiscourseEvent.trigger(:sync_sso, user)
|
||||||
render_serialized(user, AdminDetailedUserSerializer, root: false)
|
render_serialized(user, AdminDetailedUserSerializer, root: false)
|
||||||
rescue ActiveRecord::RecordInvalid => ex
|
rescue ActiveRecord::RecordInvalid => ex
|
||||||
render json: failed_json.merge(message: ex.message), status: 403
|
render json: failed_json.merge(message: ex.message), status: 403
|
||||||
|
@ -1075,6 +1075,24 @@ RSpec.describe Admin::UsersController do
|
|||||||
expect(user.ip_address).to be_blank
|
expect(user.ip_address).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "triggers :sync_sso DiscourseEvent" do
|
||||||
|
sso.name = "Bob The Bob"
|
||||||
|
sso.username = "bob"
|
||||||
|
sso.email = "bob@bob.com"
|
||||||
|
sso.external_id = "1"
|
||||||
|
|
||||||
|
user = DiscourseConnect.parse(sso.payload, secure_session: read_secure_session).lookup_or_create_user
|
||||||
|
|
||||||
|
sso.name = "Bill"
|
||||||
|
sso.username = "Hokli$$!!"
|
||||||
|
sso.email = "bob2@bob.com"
|
||||||
|
|
||||||
|
events = DiscourseEvent.track_events do
|
||||||
|
post "/admin/users/sync_sso.json", params: Rack::Utils.parse_query(sso.payload)
|
||||||
|
end
|
||||||
|
expect(events).to include(event_name: :sync_sso, params: [user])
|
||||||
|
end
|
||||||
|
|
||||||
it 'should return the right message if the record is invalid' do
|
it 'should return the right message if the record is invalid' do
|
||||||
sso.email = ""
|
sso.email = ""
|
||||||
sso.name = ""
|
sso.name = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user