diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bf9e764b39e..aa29468fb26 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3a10834b85c..ad0b3699fcb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 86ceb31d2ed..98b2f9df822 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"