Skip to content

Commit

Permalink
Merge branch 'master' of github.com:diaspora/diaspora
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrippi committed Sep 21, 2010
2 parents 107c05e + c8e5252 commit 03638ee
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 72 deletions.
3 changes: 0 additions & 3 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class PhotosController < ApplicationController
respond_to :json, :only => :show

def create

album = Album.find_by_id params[:album_id]
puts params

begin

######################## dealing with local files #############
Expand Down
1 change: 0 additions & 1 deletion app/helpers/requests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def subscription_url(action, profile)
def relationship_flow(identifier)
action = :none
person = nil
puts identifier
person = Person.by_webfinger identifier
if person
action = (person == current_user.person ? :none : :friend)
Expand Down
12 changes: 3 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class User
key :visible_post_ids, Array
key :visible_person_ids, Array

key :url, String

one :person, :class_name => 'Person', :foreign_key => :owner_id

many :friends, :in => :friend_ids, :class_name => 'Person'
Expand Down Expand Up @@ -97,7 +95,6 @@ def move_friend( opts = {})

######## Posting ########
def post(class_name, options = {})

if class_name == :photo
raise ArgumentError.new("No album_id given") unless options[:album_id]
aspect_ids = aspects_with_post( options[:album_id] )
Expand Down Expand Up @@ -242,11 +239,8 @@ def update_profile(params)

###Helpers############
def self.instantiate!( opts = {} )
hostname = opts[:url].gsub(/(https?:|www\.)\/\//, '')
hostname.chop! if hostname[-1, 1] == '/'

opts[:person][:diaspora_handle] = "#{opts[:username]}@#{hostname}"
puts opts[:person][:diaspora_handle]
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{terse_url}"
opts[:person][:url] = APP_CONFIG[:pod_url]
opts[:person][:serialized_key] = generate_key
User.create(opts)
end
Expand All @@ -257,7 +251,7 @@ def seed_aspects
end

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
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
= f.label :username
= f.text_field :username
%p.user_network
="@#{request.host}"
="@#{APP_CONFIG[:pod_url]}"

%p
= f.label :password
Expand Down
3 changes: 0 additions & 3 deletions app/views/registrations/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= f.hidden_field :url, :value => request.host
%p
= f.label :username
= f.text_field :username
Expand All @@ -17,8 +16,6 @@
= f.password_field :password_confirmation

= f.fields_for :person do |p|
= p.hidden_field :url, :value => request.host

= p.fields_for :profile do |pr|
%p
= pr.label :first_name
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

%h3 Picture
%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?
- 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'}
= check_box_tag 'checked_photo', true, true
= link_to image_tag(photo.url(:thumb_medium)), "#"
Expand Down
20 changes: 5 additions & 15 deletions config/app_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# the COPYRIGHT file.



development:
default:
pod_url: "http://example.org/"
debug: false
socket_debug : false
socket_host: 0.0.0.0
Expand All @@ -13,21 +13,11 @@ development:
pubsub_server: 'https://pubsubhubbub.appspot.com/'
mongo_host: 'localhost'
mongo_post: 27017

development:

test:
debug: false
socket_debug : false
socket_host: 0.0.0.0
pod_url: "http://example.org/"
socket_port: 8081
pubsub_server: 'https://pubsubhubbub.appspot.com/'
mongo_host: 'localhost'
mongo_post: 27017

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
10 changes: 8 additions & 2 deletions config/initializers/_load_app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# licensed under the Affero General Public License version 3. See
# the COPYRIGHT file.


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
25 changes: 19 additions & 6 deletions db/seeds/backer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,38 @@
require 'config/environment'

def create


config = YAML.load_file(File.dirname(__FILE__) + '/../../config/deploy_config.yml')
backer_info = config['servers']['backer']

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
set_app_config username
require 'config/initializers/_load_app_config.rb'

# Create seed user
user = User.instantiate!(:email => "#{username}@#{username}.joindiaspora.com",
:username => username,
:password => "#{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(
: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'],
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg"),
:url=> "http://#{username}.joindiaspora.com/")
)
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg")
))
user.person.save!

user.aspect(:name => "Presidents")
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
12 changes: 2 additions & 10 deletions db/seeds/dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@

require 'config/environment'

host = "localhost:3000"
url = "http://#{host}/"
username = "tom"
# Create seed user
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
:username => "tom",
:password => "evankorth",
:password_confirmation => "evankorth",
:url=> "http://#{username}.joindiaspora.com/"
:person => Person.new(
:diaspora_handle => "tom@tom.joindiaspora.com",
:url => url,
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
)
user.person.save!

user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
:username => "korth",
:url=> "http://#{username}.joindiaspora.com/"
:password => "evankorth",
:password_confirmation => "evankorth",
:person => Person.new( :diaspora_handle => "korth@tom.joindiaspora.com",
:url => url,
:profile => Profile.new( :first_name => "Evan",
:last_name => "Korth")))
:person => Person.new(
:profile => Profile.new( :first_name => "Evan", :last_name => "Korth")))

user2.person.save!

Expand Down
27 changes: 17 additions & 10 deletions db/seeds/tom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@

require 'config/environment'

remote_url = "http://tom.joindiaspora.com/"
#remote_url = "http://localhost:3000/"
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

set_app_config "tom"
require 'config/initializers/_load_app_config.rb'


# Create seed user
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
:username => "tom",
:password => "evankorth",
:password_confirmation => "evankorth",
:url => remote_url,
:person => {
:diaspora_handle => "tom@tom.joindiaspora.com",
:url => remote_url,
:profile => { :first_name => "Alexander", :last_name => "Hamiltom",
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}}
)
Expand All @@ -26,11 +35,7 @@
:password => "evankorth",
:password_confirmation => "evankorth",
:username => "korth",
:url => remote_url,
:person => { :diaspora_handle => "korth@tom.joindiaspora.com",
:url => remote_url,
:profile => { :first_name => "Evan",
:last_name => "Korth",
:person => {:profile => { :first_name => "Evan", :last_name => "Korth",
:image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}})

user2.person.save!
Expand All @@ -41,3 +46,5 @@
reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id )
user.receive reversed_request.to_diaspora_xml
user.aspect(:name => "Presidents")


5 changes: 4 additions & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
u.sequence(:email) {|n| "bob#{n}@pivotallabs.com"}
u.password "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

Factory.define :status_message do |m|
Expand Down
16 changes: 14 additions & 2 deletions spec/models/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
@aspect2 = @user2.aspect(:name => "Abscence of Babes")
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
person_two = Factory.build(:person, :url => @person.diaspora_handle)
person_two.valid?.should == false
Expand Down Expand Up @@ -148,13 +162,11 @@
end

it 'should search by diaspora_handle exactly' do

stub_success("tom@tom.joindiaspora.com")
Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one
end

it 'should create a stub for a remote user' do

stub_success("tom@tom.joindiaspora.com")
tom = Person.by_webfinger('tom@tom.joindiaspora.com')
tom.real_name.include?("Hamiltom").should be true
Expand Down
21 changes: 14 additions & 7 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe User do
before do
@user = Factory.create(:user)
@aspect = @user.aspect(:name => 'heroes')
end

before do
@user = Factory.create(:user)
@aspect = @user.aspect(:name => 'heroes')
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
it 'should be able to update their profile and send it to their friends' do
Expand Down Expand Up @@ -41,12 +48,12 @@

friend_users(@user, Aspect.find_by_id(@aspect.id), user2, Aspect.find_by_id(aspect2.id))
@aspect.reload

@user.aspects.include?(@aspect).should == true

proc{@user.drop_aspect(@aspect)}.should raise_error /Aspect not empty/

@user.reload
@user.reload
@user.aspects.include?(@aspect).should == true
end
end
Expand Down

0 comments on commit 03638ee

Please sign in to comment.