diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 42b00007c..afc193413 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 ############# diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb index faefe1f6e..fec093aac 100644 --- a/app/helpers/requests_helper.rb +++ b/app/helpers/requests_helper.rb @@ -32,7 +32,6 @@ module RequestsHelper def relationship_flow(identifier) action = :none person = nil - puts identifier person = Person.by_webfinger identifier if person action = (person == current_user.person ? :none : :friend) diff --git a/app/models/user.rb b/app/models/user.rb index 91d84340d..87f11fc29 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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' @@ -97,7 +95,6 @@ class User ######## 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] ) @@ -242,11 +239,8 @@ class User ###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 @@ -257,7 +251,7 @@ class User 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 diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 7ce75f5f3..15880df0b 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -10,7 +10,7 @@ = f.label :username = f.text_field :username %p.user_network - ="@#{request.host}" + ="@#{APP_CONFIG[:pod_url]}" %p = f.label :password diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index eefa94519..3e1dc0830 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -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 @@ -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 diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index fd94b2a42..880d25ef4 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -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)), "#" diff --git a/config/app_config.yml b/config/app_config.yml index b4fd6f0ab..5ee07c405 100644 --- a/config/app_config.yml +++ b/config/app_config.yml @@ -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 @@ -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 diff --git a/config/initializers/_load_app_config.rb b/config/initializers/_load_app_config.rb index 1a5094d9b..ac14c97d8 100644 --- a/config/initializers/_load_app_config.rb +++ b/config/initializers/_load_app_config.rb @@ -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 diff --git a/db/seeds/backer.rb b/db/seeds/backer.rb index b32b62377..9ebe1248f 100644 --- a/db/seeds/backer.rb +++ b/db/seeds/backer.rb @@ -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 diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index 12c728ddf..ef9dddecf 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -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! diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index 61b2ad44f..c35058bf7 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -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"}} ) @@ -26,11 +35,7 @@ user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com", :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! @@ -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 ) user.receive reversed_request.to_diaspora_xml user.aspect(:name => "Presidents") + + diff --git a/spec/factories.rb b/spec/factories.rb index c1dfcd50a..21a7ad110 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -39,7 +39,10 @@ Factory.define :user do |u| 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| diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 4f236b733..3275d9245 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -15,6 +15,20 @@ describe Person do @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 @@ -148,13 +162,11 @@ describe Person do 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ef9a08cc5..2249ae0b1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 @@ -41,12 +48,12 @@ describe User do 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