fix #2627 (webfinger produces 500 error, and refactor a little to encapsulate into Webfinger object a bit more

This commit is contained in:
Maxwell Salzberg 2012-01-14 00:40:42 -08:00
parent 1251f7433c
commit 35676cddac
4 changed files with 21 additions and 14 deletions

View file

@ -42,7 +42,7 @@ class PeopleController < ApplicationController
#only do it if it is an email address
if diaspora_id?(params[:q])
people = Person.where(:diaspora_handle => params[:q].downcase)
webfinger(params[:q]) if people.empty?
Webfinger.in_background(params[:q]) if people.empty?
else
people = Person.search(params[:q], current_user)
end
@ -53,7 +53,7 @@ class PeopleController < ApplicationController
#only do it if it is an email address
if diaspora_id?(params[:q])
people = Person.where(:diaspora_handle => params[:q])
webfinger(params[:q]) if people.empty?
Webfinger.in_background(params[:q]) if people.empty?
else
people = Person.search(params[:q], current_user)
end
@ -131,7 +131,7 @@ class PeopleController < ApplicationController
def retrieve_remote
if params[:diaspora_handle]
webfinger(params[:diaspora_handle], :single_aspect_form => true)
Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true)
render :nothing => true
else
render :nothing => true, :status => 422
@ -161,7 +161,6 @@ class PeopleController < ApplicationController
@contact = current_user.contact_for(@person) || Contact.new
render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'}
end
Webfinger.new(account, opts)
end
def diaspora_id?(query)
@ -169,9 +168,6 @@ class PeopleController < ApplicationController
end
private
def webfinger(account, opts = {})
Webfinger.new(account, opts)
end
def remote_profile_with_no_user_session?
@person && @person.remote? && !user_signed_in?

View file

@ -0,0 +1,14 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'lib/webfinger'
module Jobs
class FetchWebfinger < Base
@queue = :socket_webfinger
def self.perform(account)
Webfinger.new(account).fetch
end
end
end

View file

@ -9,6 +9,10 @@ class Webfinger
Rails.logger.info("event=webfinger status=initialized target=#{account}")
end
def self.in_background(account, opts={})
Resque.enqueue(Jobs::FetchWebfinger, account)
end
def fetch
begin
person = Person.by_account_identifier(@account)

View file

@ -385,11 +385,4 @@ describe PeopleController do
@controller.diaspora_id?("ilya_2%3@joindiaspora.com").should be_false
end
end
describe '#webfinger' do
it 'calls Webfinger.new' do
Webfinger.should_receive(:new).with(@user.diaspora_handle, anything).once
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
end
end
end