Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
danielvincent 2010-09-21 16:35:25 -07:00
commit 03638ee68e
14 changed files with 89 additions and 72 deletions

View file

@ -10,10 +10,7 @@ class PhotosController < ApplicationController
respond_to :json, :only => :show respond_to :json, :only => :show
def create def create
album = Album.find_by_id params[:album_id] album = Album.find_by_id params[:album_id]
puts params
begin begin
######################## dealing with local files ############# ######################## dealing with local files #############

View file

@ -32,7 +32,6 @@ module RequestsHelper
def relationship_flow(identifier) def relationship_flow(identifier)
action = :none action = :none
person = nil person = nil
puts identifier
person = Person.by_webfinger identifier person = Person.by_webfinger identifier
if person if person
action = (person == current_user.person ? :none : :friend) action = (person == current_user.person ? :none : :friend)

View file

@ -25,8 +25,6 @@ class User
key :visible_post_ids, Array key :visible_post_ids, Array
key :visible_person_ids, Array key :visible_person_ids, Array
key :url, String
one :person, :class_name => 'Person', :foreign_key => :owner_id one :person, :class_name => 'Person', :foreign_key => :owner_id
many :friends, :in => :friend_ids, :class_name => 'Person' many :friends, :in => :friend_ids, :class_name => 'Person'
@ -97,7 +95,6 @@ class User
######## Posting ######## ######## Posting ########
def post(class_name, options = {}) def post(class_name, options = {})
if class_name == :photo if class_name == :photo
raise ArgumentError.new("No album_id given") unless options[:album_id] raise ArgumentError.new("No album_id given") unless options[:album_id]
aspect_ids = aspects_with_post( options[:album_id] ) aspect_ids = aspects_with_post( options[:album_id] )
@ -242,11 +239,8 @@ class User
###Helpers############ ###Helpers############
def self.instantiate!( opts = {} ) def self.instantiate!( opts = {} )
hostname = opts[:url].gsub(/(https?:|www\.)\/\//, '') opts[:person][:diaspora_handle] = "#{opts[:username]}@#{terse_url}"
hostname.chop! if hostname[-1, 1] == '/' opts[:person][:url] = APP_CONFIG[:pod_url]
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{hostname}"
puts opts[:person][:diaspora_handle]
opts[:person][:serialized_key] = generate_key opts[:person][:serialized_key] = generate_key
User.create(opts) User.create(opts)
end end
@ -257,7 +251,7 @@ class User
end end
def terse_url def terse_url
terse = self.url.gsub(/(https?:|www\.)\/\//, '') terse = APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '')
terse = terse.chop! if terse[-1, 1] == '/' terse = terse.chop! if terse[-1, 1] == '/'
terse terse
end end

View file

@ -10,7 +10,7 @@
= f.label :username = f.label :username
= f.text_field :username = f.text_field :username
%p.user_network %p.user_network
="@#{request.host}" ="@#{APP_CONFIG[:pod_url]}"
%p %p
= f.label :password = f.label :password

View file

@ -2,7 +2,6 @@
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= f.hidden_field :url, :value => request.host
%p %p
= f.label :username = f.label :username
= f.text_field :username = f.text_field :username
@ -17,8 +16,6 @@
= f.password_field :password_confirmation = f.password_field :password_confirmation
= f.fields_for :person do |p| = f.fields_for :person do |p|
= p.hidden_field :url, :value => request.host
= p.fields_for :profile do |pr| = p.fields_for :profile do |pr|
%p %p
= pr.label :first_name = pr.label :first_name

View file

@ -17,11 +17,11 @@
%h3 Picture %h3 Picture
%div#image_picker %div#image_picker
= p.hidden_field :image_url, :value => (@profile.image_url.sub(@user.url,'/') if @profile.image_url), :id => 'image_url_field' = p.hidden_field :image_url, :value => (@profile.image_url.sub(APP_CONFIG[:pod_url],'/') if @profile.image_url), :id => 'image_url_field'
- unless @photos.nil? || @photos.empty? - unless @photos.nil? || @photos.empty?
- for photo in @photos - for photo in @photos
- if @profile.image_url && (photo.url(:thumb_medium) == @profile.image_url.sub(@user.url,'/')) - if @profile.image_url && (photo.url(:thumb_medium) == @profile.image_url.sub(APP_CONFIG[:pod_url],'/'))
%div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'}
= check_box_tag 'checked_photo', true, true = check_box_tag 'checked_photo', true, true
= link_to image_tag(photo.url(:thumb_medium)), "#" = link_to image_tag(photo.url(:thumb_medium)), "#"

View file

@ -3,8 +3,8 @@
# the COPYRIGHT file. # the COPYRIGHT file.
default:
development: pod_url: "http://example.org/"
debug: false debug: false
socket_debug : false socket_debug : false
socket_host: 0.0.0.0 socket_host: 0.0.0.0
@ -13,21 +13,11 @@ development:
pubsub_server: 'https://pubsubhubbub.appspot.com/' pubsub_server: 'https://pubsubhubbub.appspot.com/'
mongo_host: 'localhost' mongo_host: 'localhost'
mongo_post: 27017 mongo_post: 27017
development:
test: test:
debug: false pod_url: "http://example.org/"
socket_debug : false
socket_host: 0.0.0.0
socket_port: 8081 socket_port: 8081
pubsub_server: 'https://pubsubhubbub.appspot.com/'
mongo_host: 'localhost'
mongo_post: 27017
production: production:
debug: false
socket_debug : false
socket_host: 0.0.0.0
socket_port: 8080
pubsub_server: 'https://pubsubhubbub.appspot.com/'
mongo_host: 'localhost'
mongo_post: 27017

View file

@ -2,6 +2,12 @@
# licensed under the Affero General Public License version 3. See # licensed under the Affero General Public License version 3. See
# the COPYRIGHT file. # the COPYRIGHT file.
raw_config = File.read("#{Rails.root}/config/app_config.yml") raw_config = File.read("#{Rails.root}/config/app_config.yml")
APP_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys all_envs = YAML.load(raw_config)
if all_envs[Rails.env]
APP_CONFIG = all_envs['default'].merge(all_envs[Rails.env]).symbolize_keys
else
APP_CONFIG = all_envs['default'].symbolize_keys
end
puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" if APP_CONFIG[:pod_url] == "http://example.org/" && Rails.env != :test

View file

@ -15,25 +15,38 @@
require 'config/environment' require 'config/environment'
def create def create
config = YAML.load_file(File.dirname(__FILE__) + '/../../config/deploy_config.yml') config = YAML.load_file(File.dirname(__FILE__) + '/../../config/deploy_config.yml')
backer_info = config['servers']['backer'] backer_info = config['servers']['backer']
backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i
# Create seed user
#set pod url
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
set_app_config username
require 'config/initializers/_load_app_config.rb'
# Create seed user
user = User.instantiate!(:email => "#{username}@#{username}.joindiaspora.com", user = User.instantiate!(:email => "#{username}@#{username}.joindiaspora.com",
:username => username, :username => username,
:password => "#{username+backer_info[backer_number]['pin'].to_s}", :password => "#{username+backer_info[backer_number]['pin'].to_s}",
:password_confirmation => "#{username+backer_info[backer_number]['pin'].to_s}", :password_confirmation => "#{username+backer_info[backer_number]['pin'].to_s}",
:url=> "http://#{username}.joindiaspora.com/",
:person => Person.new( :person => Person.new(
:diaspora_handle => "#{username}@#{username}.joindiaspora.com",
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'], :profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'],
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg"), :image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg")
:url=> "http://#{username}.joindiaspora.com/") ))
)
user.person.save! user.person.save!
user.aspect(:name => "Presidents") user.aspect(:name => "Presidents")
end end
def set_app_config username
current_config = YAML.load(Rails.root.join('config', 'app_config.yml')).symbolize_keys
current_config[Rails.env] ||= {}
current_config[Rails.env][:pod_url] = "#{username}.joindiaspora.com"
current_config[:default][:pod_url] = "#{username}.joindiaspora.com"
file = File.new(Rails.root.join('config','app_config.yml'),'w')
file.write(current_config.to_yaml)
file.close
end

View file

@ -6,31 +6,23 @@
require 'config/environment' require 'config/environment'
host = "localhost:3000"
url = "http://#{host}/"
username = "tom" username = "tom"
# Create seed user # Create seed user
user = User.instantiate!( :email => "tom@tom.joindiaspora.com", user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
:username => "tom", :username => "tom",
:password => "evankorth", :password => "evankorth",
:password_confirmation => "evankorth", :password_confirmation => "evankorth",
:url=> "http://#{username}.joindiaspora.com/"
:person => Person.new( :person => Person.new(
:diaspora_handle => "tom@tom.joindiaspora.com",
:url => url,
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" )) :profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
) )
user.person.save! user.person.save!
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com", user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
:username => "korth", :username => "korth",
:url=> "http://#{username}.joindiaspora.com/"
:password => "evankorth", :password => "evankorth",
:password_confirmation => "evankorth", :password_confirmation => "evankorth",
:person => Person.new( :diaspora_handle => "korth@tom.joindiaspora.com", :person => Person.new(
:url => url, :profile => Profile.new( :first_name => "Evan", :last_name => "Korth")))
:profile => Profile.new( :first_name => "Evan",
:last_name => "Korth")))
user2.person.save! user2.person.save!

View file

@ -6,17 +6,26 @@
require 'config/environment' require 'config/environment'
remote_url = "http://tom.joindiaspora.com/" def set_app_config username
#remote_url = "http://localhost:3000/" current_config = YAML.load(Rails.root.join('config', 'app_config.yml')).symbolize_keys
current_config[Rails.env] ||= {}
current_config[Rails.env][:pod_url] = "#{username}.joindiaspora.com"
current_config[:default][:pod_url] = "#{username}.joindiaspora.com"
file = File.new(Rails.root.join('config','app_config.yml'),'w')
file.write(current_config.to_yaml)
file.close
end
set_app_config "tom"
require 'config/initializers/_load_app_config.rb'
# Create seed user # Create seed user
user = User.instantiate!( :email => "tom@tom.joindiaspora.com", user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
:username => "tom", :username => "tom",
:password => "evankorth", :password => "evankorth",
:password_confirmation => "evankorth", :password_confirmation => "evankorth",
:url => remote_url,
:person => { :person => {
:diaspora_handle => "tom@tom.joindiaspora.com",
:url => remote_url,
:profile => { :first_name => "Alexander", :last_name => "Hamiltom", :profile => { :first_name => "Alexander", :last_name => "Hamiltom",
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}} :image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}}
) )
@ -26,11 +35,7 @@ user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
:password => "evankorth", :password => "evankorth",
:password_confirmation => "evankorth", :password_confirmation => "evankorth",
:username => "korth", :username => "korth",
:url => remote_url, :person => {:profile => { :first_name => "Evan", :last_name => "Korth",
:person => { :diaspora_handle => "korth@tom.joindiaspora.com",
:url => remote_url,
:profile => { :first_name => "Evan",
:last_name => "Korth",
:image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}}) :image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}})
user2.person.save! user2.person.save!
@ -41,3 +46,5 @@ request = user.send_friend_request_to(user2, aspect)
reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id ) reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id )
user.receive reversed_request.to_diaspora_xml user.receive reversed_request.to_diaspora_xml
user.aspect(:name => "Presidents") user.aspect(:name => "Presidents")

View file

@ -39,7 +39,10 @@ Factory.define :user do |u|
u.sequence(:email) {|n| "bob#{n}@pivotallabs.com"} u.sequence(:email) {|n| "bob#{n}@pivotallabs.com"}
u.password "bluepin7" u.password "bluepin7"
u.password_confirmation "bluepin7" u.password_confirmation "bluepin7"
u.person { |a| Factory.create(:person_with_user, :owner_id => a._id)} u.person { |a| Factory.create(:person_with_user,
:owner_id => a._id,
:diaspora_handle => "#{a.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
}
end end
Factory.define :status_message do |m| Factory.define :status_message do |m|

View file

@ -15,6 +15,20 @@ describe Person do
@aspect2 = @user2.aspect(:name => "Abscence of Babes") @aspect2 = @user2.aspect(:name => "Abscence of Babes")
end end
describe '#diaspora_handle' do
context 'local people' do
it 'uses the pod config url to set the diaspora_handle' do
@user.person.diaspora_handle.should == @user.username + "@example.org"
end
end
context 'remote people' do
it 'stores the diaspora_handle in the database' do
@person.diaspora_handle.include?(@user.terse_url).should be false
end
end
end
it 'should not allow two people with the same diaspora_handle' do it 'should not allow two people with the same diaspora_handle' do
person_two = Factory.build(:person, :url => @person.diaspora_handle) person_two = Factory.build(:person, :url => @person.diaspora_handle)
person_two.valid?.should == false person_two.valid?.should == false
@ -148,13 +162,11 @@ describe Person do
end end
it 'should search by diaspora_handle exactly' do it 'should search by diaspora_handle exactly' do
stub_success("tom@tom.joindiaspora.com") stub_success("tom@tom.joindiaspora.com")
Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one
end end
it 'should create a stub for a remote user' do it 'should create a stub for a remote user' do
stub_success("tom@tom.joindiaspora.com") stub_success("tom@tom.joindiaspora.com")
tom = Person.by_webfinger('tom@tom.joindiaspora.com') tom = Person.by_webfinger('tom@tom.joindiaspora.com')
tom.real_name.include?("Hamiltom").should be true tom.real_name.include?("Hamiltom").should be true

View file

@ -7,11 +7,18 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe User do describe User do
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@aspect = @user.aspect(:name => 'heroes') @aspect = @user.aspect(:name => 'heroes')
end end
describe '#diaspora_handle' do
it 'uses the pod config url to set the diaspora_handle' do
@user.diaspora_handle.should == @user.username + "@example.org"
end
end
describe 'profiles' do describe 'profiles' do
it 'should be able to update their profile and send it to their friends' do it 'should be able to update their profile and send it to their friends' do
@ -41,12 +48,12 @@ describe User do
friend_users(@user, Aspect.find_by_id(@aspect.id), user2, Aspect.find_by_id(aspect2.id)) friend_users(@user, Aspect.find_by_id(@aspect.id), user2, Aspect.find_by_id(aspect2.id))
@aspect.reload @aspect.reload
@user.aspects.include?(@aspect).should == true @user.aspects.include?(@aspect).should == true
proc{@user.drop_aspect(@aspect)}.should raise_error /Aspect not empty/ proc{@user.drop_aspect(@aspect)}.should raise_error /Aspect not empty/
@user.reload @user.reload
@user.aspects.include?(@aspect).should == true @user.aspects.include?(@aspect).should == true
end end
end end