Fix #690 - Webfinger should handle new shortform profile URLs now (nice)

pull/806/head
Eugen Rochko 2017-03-28 11:23:33 +02:00
parent 448a07cc3f
commit 1c6b02f936
3 changed files with 9 additions and 6 deletions

View File

@ -36,11 +36,14 @@ class XrdController < ApplicationController
end end
def username_from_resource def username_from_resource
if resource_param.start_with?('acct:') || resource_param.include?('@') if resource_param =~ /\Ahttps?:\/\//
resource_param.split('@').first.gsub('acct:', '') path_params = Rails.application.routes.recognize_path(resource_param)
raise ActiveRecord::RecordNotFound unless path_params[:controller] == 'users' && path_params[:action] == 'show'
path_params[:username]
else else
url = Addressable::URI.parse(resource_param) username, domain = resource_param.gsub(/\Aacct:/, '').split('@')
url.path.gsub('/users/', '') raise ActiveRecord::RecordNotFound unless TagManager.instance.local_domain?(domain)
username
end end
end end

View File

@ -1,6 +1,6 @@
object @account object @account
attributes :id, :username, :acct, :display_name, :locked attributes :id, :username, :acct, :display_name, :locked, :created_at
node(:note) { |account| Formatter.instance.simplified_format(account) } node(:note) { |account| Formatter.instance.simplified_format(account) }
node(:url) { |account| TagManager.instance.url_for(account) } node(:url) { |account| TagManager.instance.url_for(account) }

View File

@ -14,7 +14,7 @@ RSpec.describe XrdController, type: :controller do
let(:alice) { Fabricate(:account, username: 'alice') } let(:alice) { Fabricate(:account, username: 'alice') }
it 'returns http success when account can be found' do it 'returns http success when account can be found' do
get :webfinger, params: { resource: "acct:#{alice.username}@anything.com" } get :webfinger, params: { resource: "acct:#{alice.username}@#{Rails.configuration.x.local_domain}" }
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end