Merge remote branch 'upstream/master'
This commit is contained in:
commit
b205cb84a5
9 changed files with 145 additions and 61 deletions
|
|
@ -34,15 +34,11 @@ class Photo < Post
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
|
||||||
def self.instantiate(params = {})
|
def self.instantiate(params = {})
|
||||||
|
photo = super(params)
|
||||||
image_file = params.delete(:user_file)
|
image_file = params.delete(:user_file)
|
||||||
person = params.delete(:person)
|
|
||||||
|
|
||||||
photo = Photo.new(params)
|
|
||||||
photo.diaspora_handle = params[:diaspora_handle]
|
|
||||||
|
|
||||||
|
photo.album_id = params[:album_id]
|
||||||
photo.image.store! image_file
|
photo.image.store! image_file
|
||||||
photo.person = person
|
|
||||||
photo.save
|
|
||||||
photo
|
photo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,30 +138,44 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
######## Posting ########
|
######## Posting ########
|
||||||
def post(class_name, options = {})
|
def post(class_name, opts = {})
|
||||||
if class_name == :photo && !options[:album_id].to_s.empty?
|
post = build_post(class_name, opts)
|
||||||
aspect_ids = aspects_with_post(options[:album_id])
|
|
||||||
|
if post.save
|
||||||
|
raise 'MongoMapper failed to catch a failed save' unless post.id
|
||||||
|
dispatch_post(post, :to => opts[:to])
|
||||||
|
end
|
||||||
|
post
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_post(class_name, opts = {})
|
||||||
|
opts[:person] = self.person
|
||||||
|
opts[:diaspora_handle] = self.person.diaspora_handle
|
||||||
|
|
||||||
|
model_class = class_name.to_s.camelize.constantize
|
||||||
|
model_class.instantiate(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def dispatch_post(post, opts = {})
|
||||||
|
if post.is_a?(Photo) && post.album_id
|
||||||
|
aspect_ids = aspects_with_post(post.album_id)
|
||||||
aspect_ids.map! { |aspect| aspect.id }
|
aspect_ids.map! { |aspect| aspect.id }
|
||||||
else
|
else
|
||||||
aspect_ids = options.delete(:to)
|
aspect_ids = opts.delete(:to)
|
||||||
end
|
end
|
||||||
|
|
||||||
aspect_ids = validate_aspect_permissions(aspect_ids)
|
aspect_ids = validate_aspect_permissions(aspect_ids)
|
||||||
|
self.raw_visible_posts << post
|
||||||
post = build_post(class_name, options)
|
self.save
|
||||||
|
|
||||||
if post.persisted?
|
|
||||||
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
|
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
|
||||||
push_to_aspects(post, aspect_ids)
|
push_to_aspects(post, aspect_ids)
|
||||||
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
|
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
|
||||||
if options[:public] == true
|
if post.public
|
||||||
self.services.each do |service|
|
self.services.each do |service|
|
||||||
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
post
|
|
||||||
end
|
|
||||||
|
|
||||||
def post_to_facebook(service, message)
|
def post_to_facebook(service, message)
|
||||||
Rails.logger.info("Sending a message: #{message} to Facebook")
|
Rails.logger.info("Sending a message: #{message} to Facebook")
|
||||||
|
|
@ -178,6 +192,8 @@ class User
|
||||||
def update_post(post, post_hash = {})
|
def update_post(post, post_hash = {})
|
||||||
if self.owns? post
|
if self.owns? post
|
||||||
post.update_attributes(post_hash)
|
post.update_attributes(post_hash)
|
||||||
|
aspects = aspects_with_post(post.id)
|
||||||
|
self.push_to_aspects(post, aspects)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -201,20 +217,6 @@ class User
|
||||||
aspect_ids
|
aspect_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_post(class_name, options = {})
|
|
||||||
options[:person] = self.person
|
|
||||||
options[:diaspora_handle] = self.person.diaspora_handle
|
|
||||||
|
|
||||||
model_class = class_name.to_s.camelize.constantize
|
|
||||||
post = model_class.instantiate(options)
|
|
||||||
if post.save
|
|
||||||
raise 'MongoMapper failed to catch a failed save' unless post.id
|
|
||||||
self.raw_visible_posts << post
|
|
||||||
self.save
|
|
||||||
end
|
|
||||||
post
|
|
||||||
end
|
|
||||||
|
|
||||||
def push_to_aspects(post, aspect_ids)
|
def push_to_aspects(post, aspect_ids)
|
||||||
if aspect_ids == :all || aspect_ids == "all"
|
if aspect_ids == :all || aspect_ids == "all"
|
||||||
aspects = self.aspects
|
aspects = self.aspects
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ class EMWebfinger
|
||||||
def initialize(account)
|
def initialize(account)
|
||||||
@account = account.strip.gsub('acct:','').to_s
|
@account = account.strip.gsub('acct:','').to_s
|
||||||
@callbacks = []
|
@callbacks = []
|
||||||
|
@ssl = true
|
||||||
# Raise an error if identifier has a port number
|
# Raise an error if identifier has a port number
|
||||||
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
||||||
# Raise an error if identifier is not a valid email (generous regexp)
|
# Raise an error if identifier is not a valid email (generous regexp)
|
||||||
|
|
@ -34,12 +35,21 @@ class EMWebfinger
|
||||||
profile_url = webfinger_profile_url(http.response)
|
profile_url = webfinger_profile_url(http.response)
|
||||||
if profile_url
|
if profile_url
|
||||||
get_webfinger_profile(profile_url)
|
get_webfinger_profile(profile_url)
|
||||||
|
elsif @ssl
|
||||||
|
@ssl = false
|
||||||
|
get_xrd
|
||||||
else
|
else
|
||||||
process_callbacks "webfinger does not seem to be enabled for #{@account}'s host"
|
process_callbacks "webfinger does not seem to be enabled for #{@account}'s host"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
http.errback { process_callbacks "there was an error getting the xrd from account#{@account}" }
|
http.errback {
|
||||||
|
if @ssl
|
||||||
|
@ssl = false
|
||||||
|
get_xrd
|
||||||
|
else
|
||||||
|
process_callbacks "there was an error getting the xrd from account#{@account}"
|
||||||
|
end }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -73,25 +83,18 @@ class EMWebfinger
|
||||||
##helpers
|
##helpers
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_nil_response(html)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def webfinger_profile_url(xrd_response)
|
def webfinger_profile_url(xrd_response)
|
||||||
doc = Nokogiri::XML::Document.parse(xrd_response)
|
doc = Nokogiri::XML::Document.parse(xrd_response)
|
||||||
return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
|
return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
|
||||||
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
||||||
end
|
end
|
||||||
|
|
||||||
def xrd_url(ssl = false)
|
def xrd_url
|
||||||
domain = @account.split('@')[1]
|
domain = @account.split('@')[1]
|
||||||
"http#{'s' if ssl}://#{domain}/.well-known/host-meta"
|
"http#{'s' if @ssl}://#{domain}/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
def swizzle(template)
|
def swizzle(template)
|
||||||
template.gsub '{uri}', @account
|
template.gsub '{uri}', @account
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
namespace :cruise do
|
namespace :cruise do
|
||||||
desc "Run all specs and features"
|
desc "Run all specs and features"
|
||||||
task :cruise => :environment do
|
task :cruise => :environment do
|
||||||
system('/etc/init.d/xvfb start')
|
puts "Starting virtual display..."
|
||||||
|
`sh -e /etc/init.d/xvfb start`
|
||||||
|
puts "Starting specs..."
|
||||||
system('export DISPLAY=:99.0 && export SELENIUM_SERVER_PORT=53809 && bundle exec rake')
|
system('export DISPLAY=:99.0 && export SELENIUM_SERVER_PORT=53809 && bundle exec rake')
|
||||||
exit_status = $?.exitstatus
|
exit_status = $?.exitstatus
|
||||||
system('/etc/init.d/xvfb stop')
|
puts "Stopping virtual display..."
|
||||||
|
`sh -e /etc/init.d/xvfb stop`
|
||||||
raise "tests failed!" unless exit_status == 0
|
raise "tests failed!" unless exit_status == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,11 @@ describe EMWebfinger do
|
||||||
EMWebfinger.new('eviljoe@diaspora.local:3000')
|
EMWebfinger.new('eviljoe@diaspora.local:3000')
|
||||||
}.should raise_error(RuntimeError, "Identifier is invalid")
|
}.should raise_error(RuntimeError, "Identifier is invalid")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should set ssl as the default' do
|
||||||
|
foo = EMWebfinger.new(account)
|
||||||
|
foo.instance_variable_get(:@ssl).should be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,14 +99,14 @@ describe EMWebfinger do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#xrd_url' do
|
describe '#xrd_url' do
|
||||||
it 'should return canonical host-meta url' do
|
it 'should return canonical host-meta url for http' do
|
||||||
|
finger.instance_variable_set(:@ssl, false)
|
||||||
finger.send(:xrd_url).should == "http://tom.joindiaspora.com/.well-known/host-meta"
|
finger.send(:xrd_url).should == "http://tom.joindiaspora.com/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can return the https version' do
|
it 'can return the https version' do
|
||||||
finger.send(:xrd_url, true).should == "https://tom.joindiaspora.com/.well-known/host-meta"
|
finger.send(:xrd_url).should == "https://tom.joindiaspora.com/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -132,6 +137,57 @@ describe EMWebfinger do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should retry with http if https fails' do
|
||||||
|
good_request.callbacks = [nil, diaspora_xrd, diaspora_finger, hcard_xml]
|
||||||
|
|
||||||
|
#new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com")
|
||||||
|
# http://tom.joindiaspora.com/.well-known/host-meta
|
||||||
|
f = EMWebfinger.new("tom@tom.joindiaspora.com")
|
||||||
|
|
||||||
|
EventMachine::HttpRequest.should_receive(:new).exactly(4).times.and_return(good_request)
|
||||||
|
|
||||||
|
f.should_receive(:xrd_url).twice
|
||||||
|
|
||||||
|
EM.run {
|
||||||
|
f.on_person{ |p|
|
||||||
|
EM.stop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'must try https first' do
|
||||||
|
single_request = FakeHttpRequest.new(:success)
|
||||||
|
single_request.callbacks = [diaspora_xrd]
|
||||||
|
good_request.callbacks = [diaspora_finger, hcard_xml]
|
||||||
|
EventMachine::HttpRequest.should_receive(:new).with("https://tom.joindiaspora.com/.well-known/host-meta").and_return(single_request)
|
||||||
|
EventMachine::HttpRequest.should_receive(:new).exactly(2).and_return(good_request)
|
||||||
|
|
||||||
|
f = EMWebfinger.new("tom@tom.joindiaspora.com")
|
||||||
|
|
||||||
|
EM.run {
|
||||||
|
f.on_person{ |p|
|
||||||
|
EM.stop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should retry with http if https fails with an http error code' do
|
||||||
|
bad_request = FakeHttpRequest.new(:failure)
|
||||||
|
|
||||||
|
good_request.callbacks = [diaspora_xrd, diaspora_finger, hcard_xml]
|
||||||
|
|
||||||
|
EventMachine::HttpRequest.should_receive(:new).with("https://tom.joindiaspora.com/.well-known/host-meta").and_return(bad_request)
|
||||||
|
EventMachine::HttpRequest.should_receive(:new).exactly(3).and_return(good_request)
|
||||||
|
|
||||||
|
f = EMWebfinger.new("tom@tom.joindiaspora.com")
|
||||||
|
|
||||||
|
EM.run {
|
||||||
|
f.on_person{ |p|
|
||||||
|
EM.stop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ describe Diaspora::WebSocket do
|
||||||
@user = make_user
|
@user = make_user
|
||||||
@aspect = @user.aspects.create(:name => "losers")
|
@aspect = @user.aspects.create(:name => "losers")
|
||||||
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
|
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
|
||||||
|
@post.save
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should queue a job' do
|
it 'should queue a job' do
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,19 @@ describe Photo do
|
||||||
it 'sets the persons diaspora handle' do
|
it 'sets the persons diaspora handle' do
|
||||||
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it 'has a constructor' do
|
it 'has a constructor' do
|
||||||
image = File.open(@fixture_name)
|
image = File.open(@fixture_name)
|
||||||
photo = Photo.instantiate(
|
photo = Photo.instantiate(
|
||||||
:person => @user.person, :album => @album, :user_file => image)
|
:person => @user.person, :album => @album, :user_file => image)
|
||||||
photo.created_at.nil?.should be false
|
photo.created_at.nil?.should be true
|
||||||
photo.image.read.nil?.should be false
|
photo.image.read.nil?.should be false
|
||||||
|
photo.album.should == @album
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it 'should save a photo' do
|
it 'should save a photo' do
|
||||||
@photo.image.store! File.open(@fixture_name)
|
@photo.image.store! File.open(@fixture_name)
|
||||||
@photo.save.should == true
|
@photo.save.should == true
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,19 @@ describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#post' do
|
describe '#build_post' do
|
||||||
|
it 'does not save a status_message' do
|
||||||
|
post = user.build_post(:status_message, :message => "hey", :to => aspect.id)
|
||||||
|
post.persisted?.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not save an album' do
|
||||||
|
post = user.build_post(:album, :name => "hey", :to => aspect.id)
|
||||||
|
post.persisted?.should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#dispatch_post' do
|
||||||
it 'should put the post in the aspect post array' do
|
it 'should put the post in the aspect post array' do
|
||||||
post = user.post(:status_message, :message => "hey", :to => aspect.id)
|
post = user.post(:status_message, :message => "hey", :to => aspect.id)
|
||||||
aspect.reload
|
aspect.reload
|
||||||
|
|
@ -67,7 +79,6 @@ describe User do
|
||||||
user.should_receive(:post_to_facebook).exactly(0).times
|
user.should_receive(:post_to_facebook).exactly(0).times
|
||||||
user.post :status_message, :message => "hi", :to => "all"
|
user.post :status_message, :message => "hi", :to => "all"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#update_post' do
|
describe '#update_post' do
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,15 @@ describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#update_post' do
|
||||||
|
|
||||||
|
it 'sends a notification to aspects' do
|
||||||
|
user.should_receive(:push_to_aspects).twice
|
||||||
|
album = user.post(:album, :name => "cat", :to => aspect.id)
|
||||||
|
user.update_post(album, :name => 'bat')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'account removal' do
|
describe 'account removal' do
|
||||||
it 'should unfriend everyone' do
|
it 'should unfriend everyone' do
|
||||||
user.should_receive(:unfriend_everyone)
|
user.should_receive(:unfriend_everyone)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue