Add a way to get user based on sso external id
This commit is contained in:
parent
b16e283d0f
commit
ad2bd11d6e
|
@ -208,10 +208,13 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_user_from_params
|
def fetch_user_from_params
|
||||||
username_lower = params[:username].downcase
|
user = if params[:username]
|
||||||
username_lower.gsub!(/\.json$/, '')
|
username_lower = params[:username].downcase
|
||||||
|
username_lower.gsub!(/\.json$/, '')
|
||||||
user = User.find_by(username_lower: username_lower)
|
User.find_by(username_lower: username_lower)
|
||||||
|
elsif params[:external_id]
|
||||||
|
SingleSignOnRecord.find_by(external_id: params[:external_id]).try(:user)
|
||||||
|
end
|
||||||
raise Discourse::NotFound.new if user.blank?
|
raise Discourse::NotFound.new if user.blank?
|
||||||
|
|
||||||
guardian.ensure_can_see!(user)
|
guardian.ensure_can_see!(user)
|
||||||
|
|
|
@ -211,6 +211,7 @@ Discourse::Application.routes.draw do
|
||||||
get "users/:username/activity/:filter" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/activity/:filter" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "users/:username/badges" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/badges" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
delete "users/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT}
|
delete "users/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
get "users/by-external/:external_id" => "users#show"
|
||||||
|
|
||||||
post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar"
|
post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar"
|
||||||
get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter",
|
get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter",
|
||||||
|
|
|
@ -25,6 +25,20 @@ describe UsersController do
|
||||||
xhr :get, :show, username: user.username
|
xhr :get, :show, username: user.username
|
||||||
response.should be_forbidden
|
response.should be_forbidden
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "fetching a user by external_id" do
|
||||||
|
before { user.create_single_sign_on_record(external_id: '997', last_payload: '') }
|
||||||
|
|
||||||
|
it "returns fetch for a matching external_id" do
|
||||||
|
xhr :get, :show, external_id: '997'
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns not found when external_id doesn't match" do
|
||||||
|
xhr :get, :show, external_id: '99'
|
||||||
|
response.should_not be_success
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.user_preferences_redirect' do
|
describe '.user_preferences_redirect' do
|
||||||
|
|
Loading…
Reference in New Issue