add HCardController to deliver the hCard
This commit is contained in:
parent
49739327aa
commit
e8d047f9fb
8 changed files with 106 additions and 6 deletions
20
app/controllers/diaspora_federation/h_card_controller.rb
Normal file
20
app/controllers/diaspora_federation/h_card_controller.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
require_dependency "diaspora_federation/application_controller"
|
||||||
|
|
||||||
|
module DiasporaFederation
|
||||||
|
##
|
||||||
|
# this controller generates the hcard
|
||||||
|
class HCardController < ApplicationController
|
||||||
|
##
|
||||||
|
# returns the hcard of the user
|
||||||
|
#
|
||||||
|
# GET /hcard/users/:guid
|
||||||
|
def hcard
|
||||||
|
person = DiasporaFederation.person_class.find_local_by_guid(params[:guid])
|
||||||
|
|
||||||
|
return render nothing: true, status: 404 if person.nil?
|
||||||
|
|
||||||
|
logger.info "hcard profile request for: #{person.diaspora_handle}"
|
||||||
|
render html: WebFinger::HCard.from_profile(person.hcard_profile_hash).to_html.html_safe
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -8,4 +8,8 @@ DiasporaFederation::Engine.routes.draw do
|
||||||
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
|
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
|
||||||
get "webfinger" => :legacy_webfinger, :as => "legacy_webfinger"
|
get "webfinger" => :legacy_webfinger, :as => "legacy_webfinger"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
controller :h_card do
|
||||||
|
get "hcard/users/:guid" => :hcard
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,13 @@ module DiasporaFederation
|
||||||
# This class must have the following methods:
|
# This class must have the following methods:
|
||||||
#
|
#
|
||||||
# *find_local_by_diaspora_handle*
|
# *find_local_by_diaspora_handle*
|
||||||
# This should return a +Person+, which is on this pod.
|
# This should return a +Person+, which is on this pod and the account is not closed.
|
||||||
|
#
|
||||||
|
# *find_local_by_guid*
|
||||||
|
# This should return a +Person+, which is on this pod and the account is not closed.
|
||||||
#
|
#
|
||||||
# *webfinger_hash*
|
# *webfinger_hash*
|
||||||
# This should return a +Hash+ with the followong informations:
|
# This should return a +Hash+ with the following information:
|
||||||
# {
|
# {
|
||||||
# acct_uri: "acct:user@server.example",
|
# acct_uri: "acct:user@server.example",
|
||||||
# alias_url: "https://server.example/people/0123456789abcdef",
|
# alias_url: "https://server.example/people/0123456789abcdef",
|
||||||
|
|
@ -42,6 +45,22 @@ module DiasporaFederation
|
||||||
# guid: "0123456789abcdef",
|
# guid: "0123456789abcdef",
|
||||||
# pubkey: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
# pubkey: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
||||||
# }
|
# }
|
||||||
|
#
|
||||||
|
# *hcard_profile_hash*
|
||||||
|
# This should return a +Hash+ with the following information:
|
||||||
|
# {
|
||||||
|
# guid: "0123456789abcdef",
|
||||||
|
# nickname: "user",
|
||||||
|
# full_name: "User Name",
|
||||||
|
# url: "https://server.example/",
|
||||||
|
# photo_full_url: "https://server.example/uploads/f.jpg",
|
||||||
|
# photo_medium_url: "https://server.example/uploads/m.jpg",
|
||||||
|
# photo_small_url: "https://server.example/uploads/s.jpg",
|
||||||
|
# pubkey: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----",
|
||||||
|
# searchable: true,
|
||||||
|
# first_name: "User",
|
||||||
|
# last_name: "Name"
|
||||||
|
# }
|
||||||
attr_accessor :person_class
|
attr_accessor :person_class
|
||||||
def person_class
|
def person_class
|
||||||
const_get(@person_class)
|
const_get(@person_class)
|
||||||
|
|
@ -66,7 +85,9 @@ module DiasporaFederation
|
||||||
configuration_error "missing server_uri" unless @server_uri.respond_to? :host
|
configuration_error "missing server_uri" unless @server_uri.respond_to? :host
|
||||||
validate_class(@person_class, "person_class", %i(
|
validate_class(@person_class, "person_class", %i(
|
||||||
find_local_by_diaspora_handle
|
find_local_by_diaspora_handle
|
||||||
|
find_local_by_guid
|
||||||
webfinger_hash
|
webfinger_hash
|
||||||
|
hcard_profile_hash
|
||||||
))
|
))
|
||||||
logger.info "successfully configured the federation engine"
|
logger.info "successfully configured the federation engine"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe HCardController, type: :controller do
|
||||||
|
routes { DiasporaFederation::Engine.routes }
|
||||||
|
|
||||||
|
describe "GET #hcard" do
|
||||||
|
it "succeeds when the person exists", fixture: true do
|
||||||
|
get :hcard, "guid" => alice.guid
|
||||||
|
expect(response).to be_success
|
||||||
|
save_fixture(response.body, "hcard")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contains the guid" do
|
||||||
|
get :hcard, "guid" => alice.guid
|
||||||
|
expect(response.body).to include "<span class=\"uid\">#{alice.guid}</span>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contains the username" do
|
||||||
|
get :hcard, "guid" => alice.guid
|
||||||
|
expect(response.body).to include "<span class=\"nickname\">alice</span>"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "404s when the person does not exist" do
|
||||||
|
get :hcard, "guid" => "unknown_guid"
|
||||||
|
expect(response).to be_not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
it "calls WebFinger::HCard.from_profile" do
|
||||||
|
expect(WebFinger::HCard).to receive(:from_profile).with(alice.hcard_profile_hash).and_call_original
|
||||||
|
get :hcard, "guid" => alice.guid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -59,7 +59,6 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls WebFinger::WebFinger.from_person" do
|
it "calls WebFinger::WebFinger.from_person" do
|
||||||
alice = Person.find_local_by_diaspora_handle("alice@localhost:3000")
|
|
||||||
expect(WebFinger::WebFinger).to receive(:from_person).with(alice.webfinger_hash).and_call_original
|
expect(WebFinger::WebFinger).to receive(:from_person).with(alice.webfinger_hash).and_call_original
|
||||||
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ require "rspec/rails"
|
||||||
# load factory girl factories
|
# load factory girl factories
|
||||||
require "factories"
|
require "factories"
|
||||||
|
|
||||||
|
# some helper methods
|
||||||
|
|
||||||
|
def alice
|
||||||
|
@alice ||= Person.find_local_by_diaspora_handle("alice@localhost:3000")
|
||||||
|
end
|
||||||
|
|
||||||
# Force fixture rebuild
|
# Force fixture rebuild
|
||||||
FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml"))
|
FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml"))
|
||||||
|
|
||||||
|
|
|
||||||
BIN
test/dummy/app/assets/images/user/default.png
Normal file
BIN
test/dummy/app/assets/images/user/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
|
|
@ -15,12 +15,29 @@ class Person < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_diaspora_handle(identifier)
|
def hcard_profile_hash
|
||||||
find_by(diaspora_handle: identifier)
|
{
|
||||||
|
guid: guid,
|
||||||
|
nickname: diaspora_handle.split("@")[0],
|
||||||
|
full_name: "Dummy User",
|
||||||
|
url: url,
|
||||||
|
photo_full_url: "#{url}assets/user/default.png",
|
||||||
|
photo_medium_url: "#{url}assets/user/default.png",
|
||||||
|
photo_small_url: "#{url}assets/user/default.png",
|
||||||
|
pubkey: serialized_public_key,
|
||||||
|
searchable: true,
|
||||||
|
first_name: "Dummy",
|
||||||
|
last_name: "User"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_local_by_diaspora_handle(identifier)
|
def self.find_local_by_diaspora_handle(identifier)
|
||||||
# no remote? check ... this class is only for testing
|
# no remote? and closed_account? check ... this class is only for testing
|
||||||
find_by_diaspora_handle(identifier)
|
find_by_diaspora_handle(identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_local_by_guid(guid)
|
||||||
|
# no remote? and closed_account? check ... this class is only for testing
|
||||||
|
find_by_guid(guid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue