FEATURE: DiscourseEvent hook for sync_sso (#16329)

This commit is contained in:
Rafael dos Santos Silva 2022-03-30 16:22:22 -03:00 committed by GitHub
parent b974375239
commit 4d809e984d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -455,6 +455,7 @@ class Admin::UsersController < Admin::AdminController
begin
user = sso.lookup_or_create_user
DiscourseEvent.trigger(:sync_sso, user)
render_serialized(user, AdminDetailedUserSerializer, root: false)
rescue ActiveRecord::RecordInvalid => ex
render json: failed_json.merge(message: ex.message), status: 403

View File

@ -1075,6 +1075,24 @@ RSpec.describe Admin::UsersController do
expect(user.ip_address).to be_blank
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
sso.email = ""
sso.name = ""