Merge branch 'master' of github.com:diaspora/diaspora_rails into encryption
This commit is contained in:
commit
fd18ac6c4b
13 changed files with 108 additions and 101 deletions
|
|
@ -1,31 +1,18 @@
|
|||
class DashboardsController < ApplicationController
|
||||
|
||||
before_filter :authenticate_user!, :except => [:receive, :hub]
|
||||
before_filter :authenticate_user!, :except => :receive
|
||||
include ApplicationHelper
|
||||
include DashboardsHelper
|
||||
|
||||
def index
|
||||
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
end
|
||||
|
||||
def receive
|
||||
|
||||
puts "SOMEONE JUST SENT ME: #{params[:xml]}"
|
||||
|
||||
store_objects_from_xml params[:xml]
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def hub
|
||||
if params[:mode] == "subscribe"
|
||||
response.status = subscribe(params)
|
||||
end
|
||||
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def warzombie
|
||||
render :nothing => true
|
||||
|
|
|
|||
23
app/controllers/publics_controller.rb
Normal file
23
app/controllers/publics_controller.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class PublicsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include PublicsHelper
|
||||
|
||||
def hcard
|
||||
end
|
||||
|
||||
def host_meta
|
||||
@user = User.owner
|
||||
render 'host_meta', :layout => false, :content_type => 'application/xrd+xml'
|
||||
end
|
||||
|
||||
def webfinger
|
||||
@user = Person.first(:email => params[:q])
|
||||
render 'webfinger', :layout => false, :content_type => 'application/xrd+xml'
|
||||
end
|
||||
|
||||
def hubbub
|
||||
if params['hub.mode'] == 'subscribe' || params['hub.mode'] == 'unsubscribe'
|
||||
render :text => params['hub.challenge'], :status => 202
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,19 +1,2 @@
|
|||
module DashboardsHelper
|
||||
|
||||
def subscribe(opts = {})
|
||||
subscriber = Subscriber.first(:url => opts[:callback], :topic => opts[:topic])
|
||||
subscriber ||= Subscriber.new(:url => opts[:callback], :topic => opts[:topic])
|
||||
|
||||
if subscriber.save
|
||||
|
||||
if opts[:verify] == 'sync'
|
||||
204
|
||||
elsif opts[:verify] == 'async'
|
||||
202
|
||||
end
|
||||
else
|
||||
400
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
17
app/helpers/publics_helper.rb
Normal file
17
app/helpers/publics_helper.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module PublicsHelper
|
||||
def subscribe(opts = {})
|
||||
subscriber = Subscriber.first(:url => opts[:callback], :topic => opts[:topic])
|
||||
subscriber ||= Subscriber.new(:url => opts[:callback], :topic => opts[:topic])
|
||||
|
||||
if subscriber.save
|
||||
|
||||
if opts[:verify] == 'sync'
|
||||
204
|
||||
elsif opts[:verify] == 'async'
|
||||
202
|
||||
end
|
||||
else
|
||||
400
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
class Subscriber
|
||||
include MongoMapper::Document
|
||||
|
||||
key :url
|
||||
key :topic
|
||||
|
||||
validates_presence_of :url, :topic
|
||||
|
||||
end
|
||||
9
app/views/publics/host_meta.erb
Normal file
9
app/views/publics/host_meta.erb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
||||
xmlns:hm='http://host-meta.net/xrd/1.0'>
|
||||
<hm:Host xmlns='http://host-meta.net/xrd/1.0'><%=@user.url%></hm:Host>
|
||||
<Link rel='lrdd'
|
||||
template='<%=@user.url%>webfinger/?q={uri}'>
|
||||
<Title>Resource Descriptor</Title>
|
||||
</Link>
|
||||
</XRD>
|
||||
13
app/views/publics/webfinger.erb
Normal file
13
app/views/publics/webfinger.erb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>acct:<%=@user.email%></Subject>
|
||||
<Alias><%=@user.url%></Alias>
|
||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="<%=@user.url%>public/profile"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@user.url%>status_messages.atom"/>
|
||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%@user.url%>public/hcard"/>
|
||||
//<Link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://identi.ca/main/salmon/user/169966"/>
|
||||
//<Link rel="http://salmon-protocol.org/ns/salmon-mention" href="http://identi.ca/main/salmon/user/169966"/>
|
||||
//<Link rel="magic-public-key" href="data:application/magic-public-key,RSA.mGJbO8SYr9CSzfpI0TDLTvn7mnYWmTYcg4uP80rVh_lHJI-IGs7k9nb5XzGzyr4Ah8wHaxLVvmgdChw1eOd6VPDm58Bkpx9iwd9oMXwrrSBvlmE8grlzlb15GuvywPQJ7tCerNYGFNhtqBk1iUB5mue6UZAE0Y3ZaAgYfYNwITE=.AQAB"/>
|
||||
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="http://identi.ca/main/ostatussub?profile={uri}"/>
|
||||
</XRD>
|
||||
|
||||
14
app/views/status_messages/_status_message.haml
Normal file
14
app/views/status_messages/_status_message.haml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%span.from
|
||||
= link_to post.person.real_name, post.person
|
||||
= auto_link post.message
|
||||
|
||||
%div.time
|
||||
= link_to(how_long_ago(post), status_message_path(post))
|
||||
\--
|
||||
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||
= render "comments/comments", :post => post
|
||||
|
||||
- if mine?(post)
|
||||
.destroy_link
|
||||
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
require 'em-websocket'
|
||||
require 'eventmachine'
|
||||
|
||||
|
||||
|
||||
module WebSocket
|
||||
EM.next_tick {
|
||||
initialize_channel
|
||||
|
|
@ -13,7 +11,7 @@ module WebSocket
|
|||
:debug =>APP_CONFIG[:debug]) do |ws|
|
||||
ws.onopen {
|
||||
@ws = ws
|
||||
sid = SocketsController.new.new_subscriber
|
||||
sid = @channel.subscribe{ |msg| ws.send msg }#SocketsController.new.new_subscriber
|
||||
|
||||
ws.onmessage { |msg| SocketsController.new.incoming(msg) }#@channel.push msg; puts msg}
|
||||
|
||||
|
|
@ -36,7 +34,7 @@ module WebSocket
|
|||
|
||||
|
||||
def self.subscribe
|
||||
@channel.subscribe{ |msg| @ws.send msg }
|
||||
@channel.subscribe{ |msg| ws.send msg }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ Diaspora::Application.routes.draw do |map|
|
|||
|
||||
resources :users
|
||||
match 'receive', :to => 'dashboards#receive'
|
||||
match 'hub', :to => 'dashboards#hub'
|
||||
match 'hubbub', :to => 'publics#hubbub'
|
||||
match '.well-known/host-meta', :to => 'publics#host_meta'
|
||||
match 'webfinger', :to => 'publics#webfinger'
|
||||
root :to => 'dashboards#index'
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,45 +15,4 @@ describe DashboardsController do
|
|||
assigns[:friends].should == Person.friends.all
|
||||
end
|
||||
|
||||
describe 'PubSubHubBuB intergration' do
|
||||
|
||||
describe 'incoming subscriptions' do
|
||||
it 'should register a friend' do
|
||||
Subscriber.all.count.should == 0
|
||||
|
||||
post :hub, {:callback => "http://example.com/",
|
||||
:mode => 'subscribe',
|
||||
:topic => '/status_messages',
|
||||
:verify => 'async'}
|
||||
response.status.should == 202
|
||||
|
||||
Subscriber.all.count.should == 1
|
||||
end
|
||||
|
||||
it 'should keep track of what topic a subscriber wants' do
|
||||
post :hub, {:callback => "http://example.com/",
|
||||
:mode => 'subscribe',
|
||||
:topic => '/status_messages',
|
||||
:verify => 'async'}
|
||||
Subscriber.first.topic.should == '/status_messages'
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return a 204 for a sync request' do
|
||||
post :hub, {:callback => "http://example.com/",
|
||||
:mode => 'subscribe',
|
||||
:topic => '/status_messages',
|
||||
:verify => 'sync'}
|
||||
response.status.should == 204
|
||||
end
|
||||
|
||||
it 'should confirm subscription of a sync request' do
|
||||
post :hub, {:callback => "http://example.com/",
|
||||
:mode => 'subscribe',
|
||||
:topic => '/status_messages',
|
||||
:verify => 'sync'}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
26
spec/controllers/publics_controller_spec.rb
Normal file
26
spec/controllers/publics_controller_spec.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe PublicsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith"))
|
||||
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)
|
||||
end
|
||||
|
||||
describe 'PubSubHubBuB intergration' do
|
||||
|
||||
describe 'incoming subscriptions' do
|
||||
it 'should respond to a incoming subscription request' do
|
||||
|
||||
get :hubbub, {'hub.callback' => "http://example.com/",
|
||||
'hub.mode' => 'subscribe',
|
||||
'hub.topic' => '/status_messages',
|
||||
'hub.verify' => 'sync',
|
||||
'hub.challenge' => 'foobar'}
|
||||
response.status.should == 202
|
||||
response.body.should == 'foobar'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe Subscriber do
|
||||
it 'should require a url' do
|
||||
n = Subscriber.new
|
||||
n.valid?.should be false
|
||||
|
||||
n.topic = '/status_messages'
|
||||
n.valid?.should be false
|
||||
|
||||
n.url = "http://clown.com/"
|
||||
|
||||
n.valid?.should be true
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue