Merge pull request #3163 from rcfox/fix-by-external
Allow periods in the external_id value used in the /users/by-external route.
This commit is contained in:
commit
b052179ae6
|
@ -269,7 +269,8 @@ class ApplicationController < ActionController::Base
|
|||
find_opts[:active] = true unless opts[:include_inactive]
|
||||
User.find_by(find_opts)
|
||||
elsif params[:external_id]
|
||||
SingleSignOnRecord.find_by(external_id: params[:external_id]).try(:user)
|
||||
external_id = params[:external_id].gsub(/\.json$/, '')
|
||||
SingleSignOnRecord.find_by(external_id: external_id).try(:user)
|
||||
end
|
||||
raise Discourse::NotFound if user.blank?
|
||||
|
||||
|
|
|
@ -39,6 +39,12 @@ class UsersController < ApplicationController
|
|||
user_serializer.topic_post_count = {topic_id => Post.where(topic_id: topic_id, user_id: @user.id).count }
|
||||
end
|
||||
|
||||
# This is a hack to get around a Rails issue where values with periods aren't handled correctly
|
||||
# when used as part of a route.
|
||||
if params[:external_id] and params[:external_id].ends_with? '.json'
|
||||
return render_json_dump(user_serializer)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@restrict_fields = guardian.restrict_user_fields?(@user)
|
||||
|
|
|
@ -275,7 +275,8 @@ Discourse::Application.routes.draw do
|
|||
get "users/:username/notifications" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username/pending" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
delete "users/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/by-external/:external_id" => "users#show"
|
||||
# The external_id constraint is to allow periods to be used in the value without becoming part of the format. ie: foo.bar.json
|
||||
get "users/by-external/:external_id" => "users#show", constraints: {external_id: /[^\/]+/}
|
||||
get "users/:username/flagged-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "users/:username/deleted-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "user-badges/:username" => "user_badges#username"
|
||||
|
|
Loading…
Reference in New Issue