From 453cb066917381c664f3db29acd4033df009c738 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:01:30 -0700 Subject: [PATCH 01/63] changing settings and deploy scripts, validating email --- app/models/user.rb | 2 ++ config/environments/production.rb | 9 +++------ config/thin.yml | 6 +++--- db/seeds/tom.rb | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7ab2987d9..80241fbed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,6 +21,8 @@ class User ######## Making things work ######## key :email, String + validates_true_for :email, :logic => lambda { + email.include?('@pivotallabs.com') || email.include?('@pivotalsf.com')} def method_missing(method, *args) self.person.send(method, *args) diff --git a/config/environments/production.rb b/config/environments/production.rb index 0dc2c9b99..48d9f701a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -10,10 +10,10 @@ Diaspora::Application.configure do config.action_controller.perform_caching = true # Specifies the header that your server uses for sending files - config.action_dispatch.x_sendfile_header = "X-Sendfile" + #config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files @@ -29,7 +29,7 @@ Diaspora::Application.configure do # Disable Rails's static asset server # In production, Apache or nginx will already do this - config.serve_static_assets = true + #config.serve_static_assets = true # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" @@ -37,9 +37,6 @@ Diaspora::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true diff --git a/config/thin.yml b/config/thin.yml index f60fed103..fa84529dd 100644 --- a/config/thin.yml +++ b/config/thin.yml @@ -8,8 +8,8 @@ require: [] max_persistent_conns: 512 environment: production -servers: 1 +servers: 4 daemonize: true #chdir: /usr/applications/localhash/current -#socket: /tmp/thin.sock -port: 80 +socket: /tmp/thin.sock +#port: 80 diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index c8b1d41a6..10a7e910e 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -1,6 +1,7 @@ require 'config/environment' remote_url = "http://tom.joindiaspora.com/" +remote_url = "http://localhost:3000/" # Create seed user user = User.create!( :email => "tom@tom.joindiaspora.com", :password => "evankorth", From 29e3fa4d04f34eb6aef2b18fd1e9eb4404c83fc7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:04:34 -0700 Subject: [PATCH 02/63] sprinkle role --- config/sprinkle/provision.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sprinkle/provision.rb b/config/sprinkle/provision.rb index 63302b874..8107f3f6e 100644 --- a/config/sprinkle/provision.rb +++ b/config/sprinkle/provision.rb @@ -33,7 +33,7 @@ require "#{File.dirname(__FILE__)}/packages/ruby" # If there's only one implementation of a virtual package, it's selected automatically, otherwise # the user is requested to select which one to use. -policy :diaspora, :roles => [:tom, :backer] do +policy :diaspora, :roles => [:pivots] do # requires :clean_dreamhost requires :tools requires :rubygems From 16f53922c5d913670655cbddbb32ace95c278ba3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:22:06 -0700 Subject: [PATCH 03/63] nginx conf done, comments deleted --- config/sprinkle/conf/nginx.conf | 7 ++++-- config/sprinkle/packages/server.rb | 32 -------------------------- config/sprinkle/provision.rb | 36 ------------------------------ 3 files changed, 5 insertions(+), 70 deletions(-) diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index ad79a9b5a..514bc2957 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -28,12 +28,15 @@ http { # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; upstream thin_cluster { server unix:/tmp/thin.0.sock; + server unix:/tmp/thin.1.sock; + server unix:/tmp/thin.2.sock; + server unix:/tmp/thin.3.sock; } server { - listen 80; - server_name babycakes.sofaer.net www.babycakes.sofaer.net; + listen 80 + server_name pivots.joindiaspora.com www.pivots.joindiaspora.com; root /usr/local/app/diaspora/current; location / { diff --git a/config/sprinkle/packages/server.rb b/config/sprinkle/packages/server.rb index 99f326c8b..0b9f416de 100644 --- a/config/sprinkle/packages/server.rb +++ b/config/sprinkle/packages/server.rb @@ -18,35 +18,3 @@ package :nginx_dependencies do apt %w( libc6 libpcre3 libpcre3-dev libssl0.9.8) source "http://zlib.net/zlib-1.2.5.tar.gz" end - -=begin -package :mongrel do - description 'Mongrel Application Server' - gem 'mongrel' - version '1.1.5' -end - -package :mongrel_cluster, :provides => :appserver do - description 'Cluster Management for Mongrel' - gem 'mongrel_cluster' - version '1.0.5' - requires :mongrel -end - -package :apache, :provides => :webserver do - description 'Apache 2 HTTP Server' - version '2.2.15' - - source "http://download.nextag.com/apache/httpd/httpd-#{version}.tar.bz2" do - enable %w( mods-shared=all proxy proxy-balancer proxy-http rewrite cache headers ssl deflate so ) - prefix "/opt/local/apache2-#{version}" - post :install, 'install -m 755 support/apachectl /etc/init.d/apache2', 'update-rc.d -f apache2 defaults' - end - requires :apache_dependencies -end - -package :apache_dependencies do - description 'Apache 2 HTTP Server Build Dependencies' - apt %w( openssl libtool mawk zlib1g-dev libssl-dev ) -end -=end diff --git a/config/sprinkle/provision.rb b/config/sprinkle/provision.rb index 8107f3f6e..ec1c44c16 100644 --- a/config/sprinkle/provision.rb +++ b/config/sprinkle/provision.rb @@ -1,37 +1,11 @@ #!/usr/bin/env sprinkle -s -# Annotated Example Sprinkle Rails deployment script -# -# This is an example Sprinkle script configured to install Rails from gems, Apache, Ruby, -# Sphinx and Git from source, and mysql and Git dependencies from apt on an Ubuntu system. -# -# Installation is configured to run via capistrano (and an accompanying deploy.rb recipe script). -# Source based packages are downloaded and built into /usr/local on the remote system. -# -# A sprinkle script is separated into 3 different sections. Packages, policies and deployment: - - -# Packages (separate files for brevity) -# -# Defines the world of packages as we know it. Each package has a name and -# set of metadata including its installer type (eg. apt, source, gem, etc). Packages can have -# relationships to each other via dependencies. require "#{File.dirname(__FILE__)}/packages/essential" require "#{File.dirname(__FILE__)}/packages/database" require "#{File.dirname(__FILE__)}/packages/server" require "#{File.dirname(__FILE__)}/packages/scm" require "#{File.dirname(__FILE__)}/packages/ruby" -#require "#{File.dirname(__FILE__)}/packages/unfortunately_essential" - -# Policies -# -# Names a group of packages (optionally with versions) that apply to a particular set of roles: -# -# Associates the rails policy to the application servers. Contains rails, and surrounding -# packages. Note, appserver, database, webserver and search are all virtual packages defined above. -# If there's only one implementation of a virtual package, it's selected automatically, otherwise -# the user is requested to select which one to use. policy :diaspora, :roles => [:pivots] do # requires :clean_dreamhost @@ -45,14 +19,6 @@ policy :diaspora, :roles => [:pivots] do requires :vim end -# Deployment -# -# Defines script wide settings such as a delivery mechanism for executing commands on the target -# system (eg. capistrano), and installer defaults (eg. build locations, etc): -# -# Configures spinkle to use capistrano for delivery of commands to the remote machines (via -# the named 'deploy' recipe). Also configures 'source' installer defaults to put package gear -# in /usr/local deployment do @@ -73,5 +39,3 @@ deployment do end end -# End of script, given the above information, Spinkle will apply the defined policy on all roles using the -# deployment settings specified. From 2261a0d8a467d7072760ea5751a8d42445bb8076 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:28:22 -0700 Subject: [PATCH 04/63] nginx... --- config/sprinkle/conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index 514bc2957..3d8b9cb2a 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -35,7 +35,7 @@ http { server { - listen 80 + listen 80; server_name pivots.joindiaspora.com www.pivots.joindiaspora.com; root /usr/local/app/diaspora/current; From b55a99ec09cc48ef7ce97e466471aa275f272eee Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:42:59 -0700 Subject: [PATCH 05/63] conf changes, kill nginx with go_cold --- config/sprinkle/conf/nginx.conf | 3 --- config/sprinkle/packages/server.rb | 5 ++--- config/sprinkle/provision.rb | 1 + config/thin.yml | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index 3d8b9cb2a..d76534f37 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -28,9 +28,6 @@ http { # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; upstream thin_cluster { server unix:/tmp/thin.0.sock; - server unix:/tmp/thin.1.sock; - server unix:/tmp/thin.2.sock; - server unix:/tmp/thin.3.sock; } server { diff --git a/config/sprinkle/packages/server.rb b/config/sprinkle/packages/server.rb index 0b9f416de..c553707b3 100644 --- a/config/sprinkle/packages/server.rb +++ b/config/sprinkle/packages/server.rb @@ -1,16 +1,15 @@ -package :nginx do +package :nginx, :provides=> :webserver do description 'Nginx HTTP server' version '0.7.67' source "http://nginx.org/download/nginx-#{version}.tar.gz" requires :nginx_dependencies end -package :nginx_conf, :provides=> :webserver do +package :nginx_conf do description 'Nginx conf file' transfer "#{File.dirname(__FILE__)}/../conf/nginx.conf", '/usr/local/conf/nginx.conf', :render => true do pre :install, "mkdir -p /usr/local/sbin/conf/" end - requires :nginx end package :nginx_dependencies do diff --git a/config/sprinkle/provision.rb b/config/sprinkle/provision.rb index ec1c44c16..239f03fb2 100644 --- a/config/sprinkle/provision.rb +++ b/config/sprinkle/provision.rb @@ -17,6 +17,7 @@ policy :diaspora, :roles => [:pivots] do requires :webserver requires :scm requires :vim + requires :nginx_conf end diff --git a/config/thin.yml b/config/thin.yml index fa84529dd..564eef8d6 100644 --- a/config/thin.yml +++ b/config/thin.yml @@ -8,7 +8,7 @@ require: [] max_persistent_conns: 512 environment: production -servers: 4 +servers: 1 daemonize: true #chdir: /usr/applications/localhash/current socket: /tmp/thin.sock From 015940b60ea371258f2889eb9117a6279540fe73 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:45:47 -0700 Subject: [PATCH 06/63] Pass to the lambda --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 80241fbed..58d45c3c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,7 +21,7 @@ class User ######## Making things work ######## key :email, String - validates_true_for :email, :logic => lambda { + validates_true_for :email, :logic => lambda { |email| email.include?('@pivotallabs.com') || email.include?('@pivotalsf.com')} def method_missing(method, *args) From ccbbf40584d5c1609a27822e46947d261370b022 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 11:48:59 -0700 Subject: [PATCH 07/63] validation lambda out to method --- app/models/user.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 58d45c3c2..9b6410966 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,8 +21,11 @@ class User ######## Making things work ######## key :email, String - validates_true_for :email, :logic => lambda { |email| - email.include?('@pivotallabs.com') || email.include?('@pivotalsf.com')} + validates_true_for :email, :logic => lambda { self.pivotal_email?} + + def pivotal_email? + email.include?('@pivotallabs.com') + end def method_missing(method, *args) self.person.send(method, *args) From 842b321dfa6b85e25ac273846ce4e63c3dd6bdab Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:02:42 -0700 Subject: [PATCH 08/63] User email checking, routes working again --- app/controllers/users_controller.rb | 14 -------------- app/models/user.rb | 28 +++++++++++++--------------- config/routes.rb | 2 +- spec/factories.rb | 2 +- spec/models/user_spec.rb | 14 -------------- spec/spec_helper.rb | 1 + 6 files changed, 16 insertions(+), 45 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12f87c481..e5e2e263c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,19 +26,5 @@ class UsersController < ApplicationController end end - def create - @user = User.instantiate(params[:user]) - - if @user.created_at && @user.person.created_at - flash[:notice] = "Successfully signed up." - redirect_to root_path - else - render :action => 'new' - end - end - - def new - @user = User.new - end end diff --git a/app/models/user.rb b/app/models/user.rb index 9b6410966..197fc4ea0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,17 +16,22 @@ class User many :groups, :class_name => 'Group' - before_validation_on_create :assign_key - before_validation :do_bad_things - + before_validation_on_create :setup_person + before_create :pivotal_only + ######## Making things work ######## key :email, String - validates_true_for :email, :logic => lambda { self.pivotal_email?} + #validates_true_for :email, :logic => lambda {self.pivotal_email?} + def pivotal_email? email.include?('@pivotallabs.com') end + def pivotal_only + raise "pivotal only" unless pivotal_email? + end + def method_missing(method, *args) self.person.send(method, *args) end @@ -234,12 +239,7 @@ class User end ###Helpers############ - def self.instantiate( opts = {} ) - opts[:person][:email] = opts[:email] - opts[:person][:serialized_key] = generate_key - User.create( opts) - end - + def terse_url terse= self.url.gsub(/https?:\/\//, '') terse.gsub!(/www\./, '') @@ -247,10 +247,6 @@ class User terse end - def do_bad_things - self.password_confirmation = self.password - end - def friend_by_id( id ) friends.detect{|x| x.id == ensure_bson( id ) } end @@ -261,8 +257,10 @@ class User protected - def assign_key + def setup_person self.person.serialized_key ||= generate_key.export + self.person.email = email + self.person.save end def generate_key diff --git a/config/routes.rb b/config/routes.rb index 88c838d77..0cf622127 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Diaspora::Application.routes.draw do |map| resources :blogs resources :bookmarks resources :people - resources :users + resources :users, :except => [:new, :create] resources :status_messages resources :comments resources :requests diff --git a/spec/factories.rb b/spec/factories.rb index 88f34e1f6..ba3aadeb9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -24,7 +24,7 @@ Factory.define :person_with_user, :parent => :person_with_private_key do |p| end Factory.define :user do |u| - u.sequence(:email) {|n| "bob#{n}@aol.com"} + 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)} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e0d2415c7..fd78af0a3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -6,20 +6,6 @@ describe User do @group = @user.group(:name => 'heroes') end - it 'should instantiate with a person and be valid' do - user = User.instantiate(:email => "bob@bob.com", - :password => "password", - :password_confirmation => "password", - :person => - {:profile => { - :first_name => "bob", - :last_name => "grimm"}}) - - user.save.should be true - user.person.should_not be nil - user.person.profile.should_not be nil - end - describe 'friend requesting' do it "should assign a request to a group" do friend = Factory.create(:person) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0b2759cb..cadde8dcc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,7 @@ RSpec.configure do |config| config.before(:each) do DatabaseCleaner.start stub_sockets_controller + User.stub(:pivotal_only).and_return(:true) end config.after(:each) do From d5c608c7aef1c3a2e8d91393c7161612349ffb47 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:07:11 -0700 Subject: [PATCH 09/63] Removing welcome home line --- app/views/groups/index.html.haml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index e4d1ecca2..f1785389d 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -1,7 +1,3 @@ -%h1 - welcome home, - = current_user.profile.first_name - = render "shared/publisher" %ul#stream From e6768cb5c8831f56aa7e064097a65e8a821cb385 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:21:29 -0700 Subject: [PATCH 10/63] helper method --- app/models/user.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 53cde243e..109a2d987 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,7 +36,6 @@ class User self.person.send(method, *args) end - def real_name "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" end @@ -269,6 +268,9 @@ class User groups.detect{|x| x.id == ensure_bson( id ) } end + def tommy? + email.include?("tommy@pivotallabs.com") || email.include?("tsullivan@pivotallabs.com") + end protected def setup_person From 424f576d95d8b55cf71bc31c211273a028e88659 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:48:09 -0700 Subject: [PATCH 11/63] Actionmailer config --- config/environments/production.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config/environments/production.rb b/config/environments/production.rb index 48d9f701a..fb9f8f97e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -42,4 +42,14 @@ Diaspora::Application.configure do config.i18n.fallbacks = true config.threadsafe! + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + :address => 'smtp.joindiaspora.com', + :port => 587 + :domain => 'www.joindiaspora.com' + :authentication => 'plain' + :user_name => 'diaspora-pivots' + :password => "xy289|]G+R*-kA" + :enable_starttls_auto => true + } end From 771c594814ca75620a57f787fc9f124618e87459 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:49:18 -0700 Subject: [PATCH 12/63] Take out pivotal only for a second --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 109a2d987..3f6e368f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,7 @@ class User many :groups, :class_name => 'Group' before_validation_on_create :setup_person - before_create :pivotal_only + #before_create :pivotal_only ######## Making things work ######## key :email, String From 2ede5f499f1bfdfe89705b05376c7ec2ecb29cd2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:53:15 -0700 Subject: [PATCH 13/63] Commas --- config/environments/production.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index fb9f8f97e..354aed8f7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -45,11 +45,11 @@ Diaspora::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'smtp.joindiaspora.com', - :port => 587 - :domain => 'www.joindiaspora.com' - :authentication => 'plain' - :user_name => 'diaspora-pivots' - :password => "xy289|]G+R*-kA" + :port => 587, + :domain => 'www.joindiaspora.com', + :authentication => 'plain', + :user_name => 'diaspora-pivots', + :password => "xy289|]G+R*-kA", :enable_starttls_auto => true } end From 0fdb337076418e1417702304f8b55399086131f3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:57:45 -0700 Subject: [PATCH 14/63] Confirmable --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3f6e368f2..336ed98ee 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,8 @@ class User include MongoMapper::Document devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable. + :confirmable key :friend_ids, Array key :pending_request_ids, Array From 063164fea236ca06f422f88c95ee81d97180cc39 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:59:57 -0700 Subject: [PATCH 15/63] comma --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 336ed98ee..797880766 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,7 @@ class User include MongoMapper::Document devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable. + :recoverable, :rememberable, :trackable, :validatable, :confirmable key :friend_ids, Array From cbb1b550ffb30d7caa5875e60b977c335bdca97f Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 14:03:30 -0700 Subject: [PATCH 16/63] Default url --- config/environments/production.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/environments/production.rb b/config/environments/production.rb index 354aed8f7..08307c678 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -43,6 +43,7 @@ Diaspora::Application.configure do config.threadsafe! config.action_mailer.delivery_method = :smtp + config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} config.action_mailer.smtp_settings = { :address => 'smtp.joindiaspora.com', :port => 587, From f84d7962fce0fc66dbdcbadebcb77fc2f0f35250 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 14:06:00 -0700 Subject: [PATCH 17/63] actionmailer config --- config/environments/production.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 08307c678..7655eff5e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -45,9 +45,9 @@ Diaspora::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} config.action_mailer.smtp_settings = { - :address => 'smtp.joindiaspora.com', + :address => 'smtp.gmail.com', :port => 587, - :domain => 'www.joindiaspora.com', + :domain => 'joindiaspora.com', :authentication => 'plain', :user_name => 'diaspora-pivots', :password => "xy289|]G+R*-kA", From 46e7dbedac4a279692532af615ee53a55bbe1e5e Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 15:19:41 -0700 Subject: [PATCH 18/63] Trying to get actionmailer working --- config/environments/production.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 7655eff5e..2481ad94a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -44,7 +44,7 @@ Diaspora::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} - config.action_mailer.smtp_settings = { + smtp_settings = { :address => 'smtp.gmail.com', :port => 587, :domain => 'joindiaspora.com', @@ -53,4 +53,8 @@ Diaspora::Application.configure do :password => "xy289|]G+R*-kA", :enable_starttls_auto => true } + + Mail.defaults do + delivery_method :smtp, smtp_settings + end end From a74ea7e80f87edde829f6e0190abac2be49d40d4 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 15:31:14 -0700 Subject: [PATCH 19/63] Back to config actionmailer, the settings are getting set, try mail.joindiaspora.com --- config/environments/production.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 2481ad94a..bfc68495b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -44,17 +44,13 @@ Diaspora::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} - smtp_settings = { + config.action_mailer.smtp_settings = { :address => 'smtp.gmail.com', :port => 587, - :domain => 'joindiaspora.com', + :domain => 'mail.joindiaspora.com', :authentication => 'plain', :user_name => 'diaspora-pivots', :password => "xy289|]G+R*-kA", :enable_starttls_auto => true } - - Mail.defaults do - delivery_method :smtp, smtp_settings - end end From 188f555c7278d9c929eb4dfff47c1ba7add86be7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 15:47:41 -0700 Subject: [PATCH 20/63] Actionmailer actually working --- config/environments/development.rb | 13 ++++++++++++- config/environments/production.rb | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 12446d661..6314ef6c6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,7 +15,18 @@ Diaspora::Application.configure do config.action_controller.perform_caching = false # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true config.active_support.deprecation = :log #config.threadsafe! + config.action_mailer.delivery_method = :smtp + config.action_mailer.default_url_options = {:host => 'localhost:3000'} + config.action_mailer.smtp_settings = { + :address => 'smtp.gmail.com', + :port => 587, + :domain => 'mail.joindiaspora.com', + :authentication => 'plain', + :user_name => 'diaspora-pivots@joindiaspora.com', + :password => "xy289|]G+R*-kA", + :enable_starttls_auto => true + } end diff --git a/config/environments/production.rb b/config/environments/production.rb index bfc68495b..6899e8f1c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -49,7 +49,7 @@ Diaspora::Application.configure do :port => 587, :domain => 'mail.joindiaspora.com', :authentication => 'plain', - :user_name => 'diaspora-pivots', + :user_name => 'diaspora-pivots@joindiaspora.com', :password => "xy289|]G+R*-kA", :enable_starttls_auto => true } From 26a892ab4c5f77c69e811cd9d5c51bc59095e6ee Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 16:43:54 -0700 Subject: [PATCH 21/63] putting email verification back in --- app/models/user.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 39e62258b..416219271 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,19 +18,19 @@ class User many :groups, :class_name => 'Group' before_validation_on_create :setup_person - #before_create :pivotal_only + before_create :pivotal_or_diaspora_only ######## Making things work ######## key :email, String #validates_true_for :email, :logic => lambda {self.pivotal_email?} - def pivotal_email? - email.include?('@pivotallabs.com') + def allowed_email? + email.include?('@pivotallabs.com') || email.include("@joindiaspora.com") end - def pivotal_only - raise "pivotal only" unless pivotal_email? + def pivotal_or_diaspora_only + raise "pivotal only" unless allowed_email? end def method_missing(method, *args) From 6f24a454c8e51c024b7bd79587ba6101e4b4bc0c Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 17:23:37 -0700 Subject: [PATCH 22/63] merge --- app/models/user.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 8c116d883..dbcb03526 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,6 @@ class User ######## Making things work ######## key :email, String -<<<<<<< HEAD #validates_true_for :email, :logic => lambda {self.pivotal_email?} @@ -33,9 +32,7 @@ class User def pivotal_or_diaspora_only raise "pivotal only" unless allowed_email? end -======= ensure_index :email ->>>>>>> bded53d51b1ca40e1c5c8f23fb28234849e14f78 def method_missing(method, *args) self.person.send(method, *args) From 244023ac4716979f7ae1486d517576553b309940 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 17:26:37 -0700 Subject: [PATCH 23/63] Infield labels on sign in --- app/views/devise/sessions/new.html.haml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index a36917c7b..daa7e6030 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -1,13 +1,15 @@ = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %p + = f.label :email = f.text_field :email - %br + %p + = f.label :password = f.password_field :password /%p /- if devise_mapping.rememberable? / = f.check_box :remember_me / = f.label :remember_me + = f.submit "Sign in" %p - = f.submit "Sign in" = render :partial => "devise/shared/links" From bb85c46be158cd63967e62c79d56d564af72d881 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 17:28:17 -0700 Subject: [PATCH 24/63] syntax error --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index dbcb03526..495829fe8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User def allowed_email? - email.include?('@pivotallabs.com') || email.include("@joindiaspora.com") + email.include?('@pivotallabs.com') || email.include?("@joindiaspora.com") end def pivotal_or_diaspora_only From 7186f3537a564e52a6c5de0ca98f341d15719cb6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 17:48:00 -0700 Subject: [PATCH 25/63] Move back paragraph tag in confirmations view --- app/views/devise/confirmations/new.html.haml | 3 ++- config/routes.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/devise/confirmations/new.html.haml b/app/views/devise/confirmations/new.html.haml index 2c49b859a..548a024bc 100644 --- a/app/views/devise/confirmations/new.html.haml +++ b/app/views/devise/confirmations/new.html.haml @@ -5,5 +5,6 @@ = f.label :email %br/ = f.text_field :email - %p= f.submit "Resend confirmation instructions" + %p + = f.submit "Resend confirmation instructions" = render :partial => "devise/shared/links" diff --git a/config/routes.rb b/config/routes.rb index 0cf622127..471460e1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,7 @@ Diaspora::Application.routes.draw do |map| #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file - devise_for :users, :path_names => {:sign_up => "get_to_the_choppa", :sign_in => "login", :sign_out => "logout"} + devise_for :users, :path_names => {:sign_up => "get_to_the_choppa", :sign_in => "login", :sign_out => "logout", :confirmation => 'confirmation'} match 'login', :to => 'devise/sessions#new', :as => "new_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration" From 6901b4f83e2a4bb17a4e234d65d450361490962a Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 17:54:20 -0700 Subject: [PATCH 26/63] Devise routes --- app/views/devise/passwords/edit.html.haml | 3 ++- app/views/devise/passwords/new.html.haml | 3 ++- app/views/devise/registrations/edit.html.haml | 3 ++- app/views/devise/unlocks/new.html.haml | 3 ++- config/routes.rb | 10 +++++----- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml index 543d47e55..025c214b0 100644 --- a/app/views/devise/passwords/edit.html.haml +++ b/app/views/devise/passwords/edit.html.haml @@ -10,5 +10,6 @@ = f.label :password_confirmation %br/ = f.password_field :password_confirmation - %p= f.submit "Change my password" + %p + = f.submit "Change my password" = render :partial => "devise/shared/links" diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index d1176b8c6..9afd3d244 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -5,5 +5,6 @@ = f.label :email %br/ = f.text_field :email - %p= f.submit "Send me reset password instructions" + %p + = f.submit "Send me reset password instructions" = render :partial => "devise/shared/links" diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index d252d9af4..dfbe2a35a 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -20,7 +20,8 @@ %i (we need your current password to confirm your changes) %br/ = f.password_field :current_password - %p= f.submit "Update" + %p + = f.submit "Update" %h3 Cancel my account %p Unhappy? #{link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete}. diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml index a73b9caa5..24b7eb862 100644 --- a/app/views/devise/unlocks/new.html.haml +++ b/app/views/devise/unlocks/new.html.haml @@ -5,5 +5,6 @@ = f.label :email %br/ = f.text_field :email - %p= f.submit "Resend unlock instructions" + %p + = f.submit "Resend unlock instructions" = render :partial => "devise/shared/links" diff --git a/config/routes.rb b/config/routes.rb index 471460e1f..59bb8b720 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,11 +19,11 @@ Diaspora::Application.routes.draw do |map| #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file - devise_for :users, :path_names => {:sign_up => "get_to_the_choppa", :sign_in => "login", :sign_out => "logout", :confirmation => 'confirmation'} - match 'login', :to => 'devise/sessions#new', :as => "new_user_session" - match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" - match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration" - + devise_for :users do + match 'login', :to => 'devise/sessions#new' + match 'logout', :to => 'devise/sessions#destroy' + match 'get_to_the_choppa', :to => 'devise/registrations#new' + end #public routes # match 'webfinger', :to => 'publics#webfinger' From 8619584834738b5a3b1abae8765c3f2f830eff89 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 18:27:50 -0700 Subject: [PATCH 27/63] things mostly working --- app/controllers/application_controller.rb | 1 - app/models/user.rb | 5 ++--- app/views/devise/registrations/new.html.haml | 2 +- config/routes.rb | 12 ++++++------ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c3b74a861..b4543f22d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,6 @@ class ApplicationController < ActionController::Base protect_from_forgery :except => :receive - layout 'application' before_filter :set_friends_and_status, :count_requests diff --git a/app/models/user.rb b/app/models/user.rb index 495829fe8..9b43eb3c4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,8 +2,7 @@ class User include MongoMapper::Document devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :confirmable + :recoverable, :rememberable, :trackable, :validatable key :friend_ids, Array key :pending_request_ids, Array @@ -304,7 +303,7 @@ class User def setup_person self.person.serialized_key ||= generate_key.export self.person.email = email - self.person.save + self.person.save! end def generate_key diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 7491611f3..dd50d306a 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -14,7 +14,7 @@ = f.password_field :password_confirmation = f.fields_for :person do |p| - = p.hidden_field :url, :value => request.path + = p.hidden_field :url, :value => request.host = p.fields_for :profile do |pr| %p diff --git a/config/routes.rb b/config/routes.rb index 59bb8b720..64dbb927e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Diaspora::Application.routes.draw do |map| resources :blogs resources :bookmarks resources :people - resources :users, :except => [:new, :create] + resources :users, :only => [:edit] resources :status_messages resources :comments resources :requests @@ -19,11 +19,11 @@ Diaspora::Application.routes.draw do |map| #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file - devise_for :users do - match 'login', :to => 'devise/sessions#new' - match 'logout', :to => 'devise/sessions#destroy' - match 'get_to_the_choppa', :to => 'devise/registrations#new' - end + devise_for :users + match 'login', :to => 'devise/sessions#new', :as => "new_user_session" + match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" + match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration" + #public routes # match 'webfinger', :to => 'publics#webfinger' From 07549ed17e968099fb71d8dbd60a10b043da8779 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 18:30:08 -0700 Subject: [PATCH 28/63] Start with a group' --- app/models/user.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 9b43eb3c4..17769cea6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,7 @@ class User before_validation_on_create :setup_person before_create :pivotal_or_diaspora_only + after_create :seed_groups ######## Making things work ######## key :email, String @@ -298,6 +299,10 @@ class User def tommy? email.include?("tommy@pivotallabs.com") || email.include?("tsullivan@pivotallabs.com") end + + def seed_groups + group(:name => "pivots") + end protected def setup_person From ffc9b00489d5dbc749dae637f83d4440e885bfda Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 18:35:33 -0700 Subject: [PATCH 29/63] taking group seed out --- app/models/user.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 17769cea6..edcfa6b98 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -301,7 +301,6 @@ class User end def seed_groups - group(:name => "pivots") end protected From 43160496c9f6accca512b39b1d5690fa295b6a7b Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 18:52:15 -0700 Subject: [PATCH 30/63] Tommy --- app/models/user.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index edcfa6b98..8014e9238 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,6 +19,7 @@ class User before_validation_on_create :setup_person before_create :pivotal_or_diaspora_only after_create :seed_groups + after_save :check_for_tommy ######## Making things work ######## key :email, String @@ -300,6 +301,15 @@ class User email.include?("tommy@pivotallabs.com") || email.include?("tsullivan@pivotallabs.com") end + def check_for_tommy + if tommy? + person.profile.first_name = "Porn" + person.profile.last_name = "King" + person.profile.save + person.save + end + end + def seed_groups end protected From 4fe6a54c096bfb834795965d655a4f8bf8231b9e Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 18:54:27 -0700 Subject: [PATCH 31/63] seed groups --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index 8014e9238..a43f416c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -311,6 +311,7 @@ class User end def seed_groups + group(:name => "Pivots") end protected From eb84b39f93a8e3f92b401b021d214425286cd465 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 19:11:59 -0700 Subject: [PATCH 32/63] change before to after --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a43f416c3..bd0912a13 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,7 +16,7 @@ class User many :groups, :class_name => 'Group' - before_validation_on_create :setup_person + after_validation_on_create :setup_person before_create :pivotal_or_diaspora_only after_create :seed_groups after_save :check_for_tommy From 9f9395bc9caeb1992f02ec8afc2f53854887360f Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 19:51:29 -0700 Subject: [PATCH 33/63] visible_person_by_id should check against self.person.id --- app/models/user.rb | 2 +- spec/controllers/people_controller_spec.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index c51413605..791664550 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -290,7 +290,7 @@ class User end def visible_person_by_id( id ) - return self if id == self.id + return self if id == person.id friends.detect{|x| x.id == ensure_bson( id ) } end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index f448f9f36..f039e0101 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -14,5 +14,8 @@ describe PeopleController do get :index, :q => "Eu" end - + + it 'should go to the current_user show page' do + get :show, :id => @user.person.id + end end From 9fcc02a580cfcb581f74e648175b55e4a2e60c42 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 19:56:21 -0700 Subject: [PATCH 34/63] Ensure bson on visible person --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 791664550..f0eca9efb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -290,8 +290,9 @@ class User end def visible_person_by_id( id ) + id = ensure_bson id return self if id == person.id - friends.detect{|x| x.id == ensure_bson( id ) } + friends.detect{|x| x.id == id } end def group_by_id( id ) From 8e253a6d49d8119a094dea97009719201ea7587f Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 19 Aug 2010 16:20:38 -0700 Subject: [PATCH 36/63] Left in a merge marker --- app/models/user.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1a02d6ddc..4dd40754a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -357,16 +357,11 @@ class User id = ensure_bson person.id groups.select {|group| group.person_ids.include? id} end -<<<<<<< HEAD + protected - def setup_person - self.person.serialized_key ||= generate_key.export -======= - def setup_person self.person.serialized_key = generate_key.export ->>>>>>> 2e76987e259ff23455d00c077fd347b4376d7e0e self.person.email = email self.person.save! end From 364cdfed22327c52c86f0580ad86ffd0f13bb79f Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 10:20:19 -0700 Subject: [PATCH 38/63] Allowed email checking no longer so ridiculous --- app/models/user.rb | 24 ++++++++++++++++-------- spec/models/user_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 4dd40754a..e3aa4425f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,23 +17,28 @@ class User many :groups, :class_name => 'Group' after_validation_on_create :setup_person - before_create :pivotal_or_diaspora_only after_create :seed_groups after_save :check_for_tommy before_validation :do_bad_things ######## Making things work ######## key :email, String - #validates_true_for :email, :logic => lambda {self.pivotal_email?} + validates_true_for :email, :logic => lambda {self.allowed_email?} - def self.allowed_email?(email) - email.include?('@pivotallabs.com') || email.include?("@joindiaspora.com") + def allowed_email? + allowed_emails = ["@pivotallabs.com", "@joindiaspora.com", "@sofaer.net", + "wchulley@gmail.com", "kimfuh@yahoo.com", "CJichi@yahoo.com", + "madkisso@mit.edu", "bribak@msn.com", "asykley@verizon.net", + "paulhaeberli@gmail.com","bondovatic@gmail.com", "dixon1e@yahoo.com"] + allowed_emails.each{|allowed| + if email.include?(allowed) + return true + end + } + false end - def pivotal_or_diaspora_only - raise "pivotal only" unless User.allowed_email?(self.email) - end ensure_index :email def method_missing(method, *args) @@ -350,7 +355,10 @@ class User end def seed_groups - group(:name => "Pivots") + group(:name => "Acquaintances") + group(:name => "Family") + group(:name => "Nemeses") + group(:name => "Work") end def groups_with_person person diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 548966548..dd9b64591 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,6 +5,29 @@ describe User do @user = Factory.create(:user) @group = @user.group(:name => 'heroes') end + + it 'should create with pivotal or allowed emails' do + user1 = Factory.create(:user, :email => "kimfuh@yahoo.com") + user2 = Factory.create(:user, :email => "awesome@sofaer.net") + user3 = Factory.create(:user, :email => "steveellis@pivotallabs.com") + user1.created_at.nil?.should be false + user2.created_at.nil?.should be false + user3.created_at.nil?.should be false + end + + it 'should not create with disallowed emails' do + proc { + user1 = Factory.create(:user, :email => "kimuh@yahoo.com") + }.should raise_error /Validation failed/ + + proc { + user2 = Factory.create(:user, :email => "awesome@sobear.net") + }.should raise_error /Validation failed/ + + proc { + user3 = Factory.create(:user, :email => "steveellis@pivotalabs.com") + }.should raise_error /Validation failed/ + end describe 'profiles' do it 'should be able to update their profile and send it to their friends' do From 51b2737dde996020f21cb00d87f8c9e06ba03ba3 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 24 Aug 2010 15:21:27 -0700 Subject: [PATCH 40/63] fixed some album stuff --- app/views/groups/index.html.haml | 2 +- app/views/photos/_photo.haml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index 1f9764bbb..2f32555f4 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -6,7 +6,7 @@ %ul#stream - for post in @posts - = render type_partial(post), :post => post + = render type_partial(post), :post => post unless post.class == Album #pagination = will_paginate @posts diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index e15dcb0d5..7523a29ba 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -8,7 +8,10 @@ = link_to post.album.name, object_path(post.album) %br - = link_to (image_tag post.url(:thumb_large)), object_path(post) + + = render "albums/album", :post => post.album + + = link_to (image_tag post.url(:thumb_medium)), object_path(post) %div.time = link_to(how_long_ago(post), photo_path(post)) From 7643fb412543a7cc28d8c8544a1cbe4bd9d238d0 Mon Sep 17 00:00:00 2001 From: Daniel Vincent Grippi Date: Tue, 14 Sep 2010 11:15:10 -0700 Subject: [PATCH 44/63] remember that aspects are seeded --- app/models/user.rb | 11 +++++------ spec/models/aspect_spec.rb | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index a30a12a1e..2c3562015 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,8 +47,7 @@ class User many :aspects, :class_name => 'Aspect' after_validation_on_create :setup_person - after_create :seed_groups - after_save :check_for_tommy + after_create :seed_aspects before_validation :do_bad_things before_save :downcase_username @@ -338,10 +337,10 @@ class User self.password_confirmation = self.password end - def seed_groups - group(:name => "Acquaintances") - group(:name => "Family") - group(:name => "Work") + def seed_aspects + aspect(:name => "Acquaintances") + aspect(:name => "Family") + aspect(:name => "Work") end protected diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index d62b53787..3718050f4 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -66,8 +66,7 @@ describe Aspect do it 'belong to a user' do @aspect.user.id.should == @user.id - @user.aspects.size.should == 1 - @user.aspects.first.id.should == @aspect.id + @user.aspects.size.should == 4 end it 'should have people' do From 426d038aaf44feefdb185411f81597c68ab0e0e7 Mon Sep 17 00:00:00 2001 From: Daniel Vincent Grippi Date: Tue, 14 Sep 2010 11:22:32 -0700 Subject: [PATCH 45/63] Remove email based filter --- app/models/user.rb | 17 ----------------- spec/models/request_spec.rb | 2 +- spec/models/user_spec.rb | 14 -------------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 2c3562015..335a42614 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,23 +63,6 @@ class User ######## Making things work ######## key :email, String - validates_true_for :email, :logic => lambda {self.allowed_email? unless email.nil?} - - - def allowed_email? - allowed_emails = ["@pivotallabs.com", "@joindiaspora.com", "@sofaer.net", - "wchulley@gmail.com", "kimfuh@yahoo.com", "CJichi@yahoo.com", - "madkisso@mit.edu", "bribak@msn.com", "asykley@verizon.net", - "paulhaeberli@gmail.com","bondovatic@gmail.com", "dixon1e@yahoo.com"] - - allowed_emails.each{|allowed| - if email.include?(allowed) - return true - end - } - false - end - ensure_index :email def method_missing(method, *args) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 3bf21c754..72be086ee 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -38,7 +38,7 @@ describe Request do xml = request.to_xml.to_s - xml.include?(@user.email).should be true + xml.include?(@user.person.email).should be true xml.include?(@user.url).should be true xml.include?(@user.profile.first_name).should be true xml.include?(@user.profile.last_name).should be true diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 930037eab..41516a7c5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -35,20 +35,6 @@ describe User do user3.created_at.nil?.should be false end - it 'should not create with disallowed emails' do - proc { - user1 = Factory.create(:user, :email => "kimuh@yahoo.com") - }.should raise_error /Validation failed/ - - proc { - user2 = Factory.create(:user, :email => "awesome@sobear.net") - }.should raise_error /Validation failed/ - - proc { - user3 = Factory.create(:user, :email => "steveellis@pivotalabs.com") - }.should raise_error /Validation failed/ - end - describe 'profiles' do it 'should be able to update their profile and send it to their friends' do Factory.create(:person) From a9b587ca06a0f2bc69f68ef1b439fce1187b39b3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 14 Sep 2010 22:31:57 -0700 Subject: [PATCH 49/63] Adding in deploy config for production --- config/deploy.rb | 163 +++++++++++++++++++++++++++++++++++++++ config/deploy_config.yml | 29 +++++++ 2 files changed, 192 insertions(+) create mode 100644 config/deploy.rb create mode 100644 config/deploy_config.yml diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 000000000..374f06455 --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,163 @@ +# Copyright 2010 Diaspora Inc. +# +# This file is part of Diaspora. +# +# Diaspora is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Diaspora is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Diaspora. If not, see . +# + + + +config = YAML.load_file(File.dirname(__FILE__) + '/deploy_config.yml') +all = config['cross_server'] + +set :backers, config['servers']['backer'] +set :application, "diaspora" +set :deploy_to, all['deploy_to'] +#set :runner, "diasporaroot" +#set :current_dir, "" +# Source code +set :scm, :git +set :user, all['user'] +#set :user, ARGV[0] +set :password, all['password'] if all['password'] +set :scm_verbose, true +set :repository, all['repo'] +set :branch, all['branch'] +set :repository_cache, "remote_cache" +set :deploy_via, :checkout +#ssh_options[:forward_agent] = true +#set :ssh_options, { :forward_agent => true } +# +set :rails_env, ENV['rails_env'] || ENV['RAILS_ENV'] || all['default_env'] + +role :pivots, config['servers']['pivots']['url'] + +# If you are using Passenger mod_rails uncomment this: +# if you're still using the script/reapear helper you will need +# these http://github.com/rails/irs_process_scripts + +# Start Nginx +after "deploy:cold" do + run("nginx") +end + +namespace :deploy do + + task :symlink_images do + run "mkdir -p #{shared_path}/uploads" + run "ln -s -f #{shared_path}/uploads #{current_path}/public/uploads" + end + + task :symlink_bundle do + run "mkdir -p #{shared_path}/bundle" + run "ln -s -f #{shared_path}/bundle #{current_path}/vendor/bundle" + end + + task :start do + start_mongo + start_thin + end + + task :start_mongo do + run("mkdir -p -v #{current_path}/log/db/ ") + run("mkdir -p -v #{shared_path}/db/") + run("mongod --fork --logpath #{current_path}/log/db/mongolog.txt --dbpath #{shared_path}/db/ " ) + end + + task :start_thin do + run("mkdir -p -v #{current_path}/log/thin/ ") + run("cd #{current_path} && bundle exec thin start -C config/thin.yml") + end + + task :stop do + stop_thin + run("killall -s 2 mongod || true") + end + + task :go_cold do + stop + run("killall nginx") + end + + task :stop_thin do + run("killall -s 2 ruby || true") + #run("cd #{current_path} && bundle exec thin stop -C config/thin.yml || true") + end + + task :restart, :roles => :app, :except => { :no_release => true } do + stop + start + end + + task :bundle_gems do + run "cd #{current_path} && bundle install" + end + + task :reinstall_old_bundler do + #run ("rm #{current_path}/Gemfile.lock || true") + run 'gem list | cut -d" " -f1 | xargs gem uninstall -aIx || true ' + run "gem install bundler -v 0.9.26 || true" + end + + task :update_bundler do + run 'gem install bundler' + end + + + task :migrate do + end + end + +namespace :cloud do + task :reboot do + run('reboot') + end + + task :clear_bundle do + + run('cd && rm -r -f .bundle') + end +end +namespace :db do + + task :purge, :roles => [:pivots] do + run "cd #{current_path} && bundle exec rake db:purge --trace RAILS_ENV=#{rails_env}" + end + + + task :tom_seed, :roles => :tom do + run "cd #{current_path} && bundle exec rake db:seed:tom --trace RAILS_ENV=#{rails_env}" + run "curl -silent -u tom@tom.joindiaspora.com:evankorth http://tom.joindiaspora.com/zombiefriends" + backers.each do |backer| + run "curl -silent -u #{backer['username']}@#{backer['username']}.joindiaspora.com:#{backer['username']}#{backer['pin']} http://#{backer['username']}.joindiaspora.com/zombiefriendaccept" + #run "curl -silent -u #{backer['username']}@#{backer['username']}.joindiaspora.com:#{backer['username']}#{backer['pin']} http://#{backer['username']}.joindiaspora.com/set_profile_photo" + end + + end + + task :backer_seed, :roles => :backer do + (0..10).each { |n| + run "curl -silent http://localhost/set_backer_number?number=#{n}", :only => {:number => n} + } + run "cd #{current_path} && bundle exec rake db:seed:backer --trace RAILS_ENV=#{rails_env}" + end + + task :reset do + purge + end + + +end + +after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle" diff --git a/config/deploy_config.yml b/config/deploy_config.yml new file mode 100644 index 000000000..301efd89a --- /dev/null +++ b/config/deploy_config.yml @@ -0,0 +1,29 @@ +# Copyright 2010 Diaspora Inc. +# +# This file is part of Diaspora. +# +# Diaspora is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Diaspora is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Diaspora. If not, see . +# + + + +cross_server: + deploy_to: '/usr/local/app/diaspora' + user: 'root' + branch: 'production' + repo: 'git@github.com:diaspora/diaspora.git' + default_env: 'production' +servers: + pivots: + url: 'pivots.joindiaspora.com' From cd21ee8652834642a621fc8fc92ce4071120c5e4 Mon Sep 17 00:00:00 2001 From: Daniel Vincent Grippi Date: Wed, 15 Sep 2010 15:36:41 -0700 Subject: [PATCH 50/63] just seed family and work --- app/models/user.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index cd33f1469..65b1bac9c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -230,8 +230,7 @@ class User Rails.logger.info( "the person id is #{object.post_id} the friend found is #{visible_person_by_id(object.post_id).inspect}") unfriended_by visible_person_by_id(object.post_id) - - else +else object.perform self.id aspects = self.aspects_with_person(object.person) aspects.each{ |aspect| aspect.post_ids.delete(object.post_id.to_id) @@ -307,7 +306,6 @@ class User end def seed_aspects - aspect(:name => "Acquaintances") aspect(:name => "Family") aspect(:name => "Work") end From b0c87fcffa507591242b27ee55be2c0fd86709b6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Sep 2010 17:04:59 -0700 Subject: [PATCH 51/63] Add a little more feedback to rake task --- lib/tasks/db.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 22f995325..80e3bafe5 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -63,6 +63,7 @@ namespace :db do return this.diaspora_handle.charAt(this.diaspora_handle.length-1) == '@' }") + puts "Found #{people.count} people with broken diaspora_handle fields" people.each do |person| if person.owner puts "Resetting diaspora handle for #{person.owner.username}" From c520fb71a71d09a9a8d9672aa1b5cb7735c1cac2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Sep 2010 21:34:15 -0700 Subject: [PATCH 52/63] Moved socket out to separate process. Multiple thins should now be possible --- Gemfile | 5 ++++- Gemfile.lock | 10 ++++++++++ app/controllers/sockets_controller.rb | 2 +- app/models/post.rb | 1 + config/app_config.yml | 1 + config/initializers/socket.rb | 26 -------------------------- lib/diaspora/websocket.rb | 6 +++++- 7 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 config/initializers/socket.rb diff --git a/Gemfile b/Gemfile index 77627808d..cc92bec3d 100644 --- a/Gemfile +++ b/Gemfile @@ -28,9 +28,12 @@ gem 'redfinger', :git => 'git://github.com/rsofaer/redfinger.git' #EventMachine gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http' -gem 'em-websocket' gem 'thin' +#Websocket +gem 'em-websocket' +gem 'magent', :git => 'http://github.com/dcu/magent.git' + #File uploading gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch gem 'mini_magick' diff --git a/Gemfile.lock b/Gemfile.lock index 007810850..dd181b320 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,6 +47,14 @@ GIT bcrypt-ruby (~> 2.1.2) warden (~> 0.10.7) +GIT + remote: http://github.com/dcu/magent.git + revision: 06513f3dac812469a55f2e365c349af4d2abc92a + specs: + magent (0.4.2) + mongo (>= 0.1.0) + uuidtools (>= 2.0.0) + GIT remote: http://github.com/jnunemaker/mongomapper.git revision: 931dab779011aa7acf60c1a4c7ad19e1ba838345 @@ -213,6 +221,7 @@ GEM treetop (1.4.8) polyglot (>= 0.3.1) tzinfo (0.3.23) + uuidtools (2.1.1) warden (0.10.7) rack (>= 1.0.0) webmock (1.3.5) @@ -242,6 +251,7 @@ DEPENDENCIES haml jnunemaker-validatable (= 1.8.4)! json + magent! mini_magick mocha mongo_mapper (= 0.8.4)! diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 2852a7160..9b90ea831 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -14,7 +14,7 @@ class SocketsController < ApplicationController def outgoing(uid,object,opts={}) @_request = ActionDispatch::Request.new({}) - Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object, opts)) + Diaspora::WebSocket.queue_to_user(uid, action_hash(uid, object, opts)) end end diff --git a/app/models/post.rb b/app/models/post.rb index e2dd53d3d..9f7c3ff27 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,6 +4,7 @@ class Post + require 'lib/diaspora/websocket' require 'lib/encryptable' include MongoMapper::Document include ApplicationHelper diff --git a/config/app_config.yml b/config/app_config.yml index 0a206c366..a138424ee 100644 --- a/config/app_config.yml +++ b/config/app_config.yml @@ -8,6 +8,7 @@ development: debug: false socket_debug : false socket_port: 8080 + socket_collection_name: 'websocket' pubsub_server: 'https://pubsubhubbub.appspot.com/' test: diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb deleted file mode 100644 index 0b1035001..000000000 --- a/config/initializers/socket.rb +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3. See -# the COPYRIGHT file. - - -require 'em-websocket' -require 'eventmachine' -require 'lib/diaspora/websocket' - EM.next_tick { - Diaspora::WebSocket.initialize_channels - - EventMachine::WebSocket.start( - :host => "0.0.0.0", - :port => APP_CONFIG[:socket_port], - :debug =>APP_CONFIG[:socket_debug]) do |ws| - ws.onopen { - - sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) - - ws.onmessage { |msg| SocketsController.new.incoming(msg) } - - ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } - } - end - } - diff --git a/lib/diaspora/websocket.rb b/lib/diaspora/websocket.rb index fc79559f6..687bd2b7c 100644 --- a/lib/diaspora/websocket.rb +++ b/lib/diaspora/websocket.rb @@ -6,6 +6,11 @@ module Diaspora module WebSocket + def self.queue_to_user(uid, data) + channel = Magent::GenericChannel.new('websocket') + channel.enqueue({:uid => uid, :data => data}) + end + def self.initialize_channels @channels = {} end @@ -44,6 +49,5 @@ module Diaspora def unsocket_from_uid(id, opts={}) SocketsController.new.outgoing(id, Retraction.for(self), opts) end - end end From 7c02200a67f2257f5c35beceaa153b05a501bc4c Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Sep 2010 21:42:16 -0700 Subject: [PATCH 53/63] Finish moving out websocket server, add task to start it --- config/deploy.rb | 5 +++++ script/websocket_server.rb | 40 ++++++++++++++++++++++++++++++++++++++ spec/lib/websocket_spec.rb | 24 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 script/websocket_server.rb create mode 100644 spec/lib/websocket_spec.rb diff --git a/config/deploy.rb b/config/deploy.rb index b4870f94d..805eadf4d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -58,6 +58,11 @@ namespace :deploy do task :start do start_mongo start_thin + start_websocket + end + + task :start_websocket do + run("cd #{current_path} && bundle exec ruby ./script/websocket_server.rb > /dev/null&") end task :start_mongo do diff --git a/script/websocket_server.rb b/script/websocket_server.rb new file mode 100644 index 000000000..8c466ca77 --- /dev/null +++ b/script/websocket_server.rb @@ -0,0 +1,40 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3. See +# the COPYRIGHT file. + +require File.dirname(__FILE__) + '/../config/environment' +require File.dirname(__FILE__) + '/../lib/diaspora/websocket' + +CHANNEL = Magent::GenericChannel.new('websocket') +def process_message + if CHANNEL.queue_count > 0 + message = CHANNEL.dequeue + if message + Diaspora::WebSocket.push_to_user(message['uid'], message['data']) + end + EM.next_tick{ process_message} + else + EM::Timer.new(1){process_message} + end + +end + + EM.run { + Diaspora::WebSocket.initialize_channels + + EventMachine::WebSocket.start( + :host => "0.0.0.0", + :port => APP_CONFIG[:socket_port], + :debug =>APP_CONFIG[:socket_debug]) do |ws| + ws.onopen { + + sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) + + ws.onmessage { |msg| SocketsController.new.incoming(msg) } + + ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } + } + end + process_message + } + diff --git a/spec/lib/websocket_spec.rb b/spec/lib/websocket_spec.rb new file mode 100644 index 000000000..233f7be48 --- /dev/null +++ b/spec/lib/websocket_spec.rb @@ -0,0 +1,24 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3. See +# the COPYRIGHT file. + +require File.dirname(__FILE__) + '/../spec_helper' + +describe Diaspora::WebSocket do + before do + @user = Factory.create(:user) + @aspect = @user.aspect(:name => "losers") + @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) + end + + it 'should queue a job' do + Diaspora::WebSocket.should_receive(:queue_to_user) + @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + end + + it 'The queued job should reach Magent' do + Magent.should_receive(:push) + @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + end + +end From 5c48e81f6785e30978ef536173a2f3959cba83bd Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 09:48:01 -0700 Subject: [PATCH 54/63] Give a little more feedback on the websocket server --- script/websocket_server.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 8c466ca77..7dee8d35c 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -35,6 +35,7 @@ end ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } } end + puts "Websocket server started." process_message } From 99ad001d28bcd5875af4dbfe356641a9f6524b1d Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 09:52:31 -0700 Subject: [PATCH 55/63] Fix websocket spec, take out puts in by_webfinger --- app/models/person.rb | 2 +- spec/lib/websocket_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 48e8b0816..ac4a5dfa7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -85,7 +85,7 @@ class Person local_person elsif !identifier.include?("localhost") && !opts[:local] begin - puts "begin finger" + Rails.logger.info("Webfingering #{identifier}") f = Redfinger.finger(identifier) rescue SocketError => e raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ diff --git a/spec/lib/websocket_spec.rb b/spec/lib/websocket_spec.rb index 233f7be48..762a725b5 100644 --- a/spec/lib/websocket_spec.rb +++ b/spec/lib/websocket_spec.rb @@ -17,8 +17,9 @@ describe Diaspora::WebSocket do end it 'The queued job should reach Magent' do - Magent.should_receive(:push) @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + channel = Magent::GenericChannel.new('websocket') + channel.message_count.should == 1 end end From 511a4487de43e8e56b4d871d9508a605b7cbf866 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 10:44:15 -0700 Subject: [PATCH 56/63] Make running the websocket server a little easier --- script/server | 5 +++++ script/websocket_server.rb | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100755 script/server diff --git a/script/server b/script/server new file mode 100755 index 000000000..0094482b1 --- /dev/null +++ b/script/server @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir -p -v log/thin/ +bundle exec ruby ./script/websocket_server.rb& +bundle exec thin start $@ diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 7dee8d35c..2fbc1370a 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -19,6 +19,7 @@ def process_message end +begin EM.run { Diaspora::WebSocket.initialize_channels @@ -35,7 +36,13 @@ end ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } } end + puts "Websocket server started." process_message } - +rescue RuntimeError => e + raise e unless e.message.include?("no acceptor") + puts "Are you sure the websocket server isn't already running?" + puts "Just start thin with bundle exec thin start." + Process.exit +end From be26794e4a5e25537aef7a79885014f5bfeb8df2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 10:46:14 -0700 Subject: [PATCH 57/63] only write to your own profile --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4a36672bc..dc25b47be 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -23,7 +23,7 @@ class UsersController < ApplicationController end def update - @user = User.find_by_id params[:id] + @user = current_user prep_image_url(params[:user]) @user.update_profile params[:user] From 5df33a6fd0dd8b87b1e8527b3c9b112fba7b734a Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 10:50:18 -0700 Subject: [PATCH 58/63] Take out users/show, use current_user in update --- app/controllers/users_controller.rb | 7 ------- config/routes.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dc25b47be..72666bc30 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,13 +7,6 @@ class UsersController < ApplicationController before_filter :authenticate_user!, :except => [:new, :create] respond_to :html - respond_to :json, :only => :show - - def show - @user = User.find_by_id params[:id] - @user_profile = @user.person.profile - respond_with @user - end def edit @user = current_user diff --git a/config/routes.rb b/config/routes.rb index 12dd20ba7..188c4b137 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ Diaspora::Application.routes.draw do resources :people, :only => [:index, :show, :destroy] - resources :users, :except => [:create, :new] + resources :users, :except => [:create, :new, :show] resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] From 3859f8a529b7ec49967f86282d82f10919c568ef Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 10:56:42 -0700 Subject: [PATCH 59/63] Adding instructions to readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d941ac182..2398be5dc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ You are welcome to contribute, add and extend Diaspora however you see fit. We We need you to fill out a [contributor agreement form](https://spreadsheets.google.com/a/joindiaspora.com/viewform?formkey=dGI2cHA3ZnNHLTJvbm10LUhXRTJjR0E6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq) before we can accept your patches. The agreement gives Diaspora joint ownership of the patch so the copyright isn't scattered. You can find it [here](https://spreadsheets.google.com/a/joindiaspora.com/viewform?formkey=dGI2cHA3ZnNHLTJvbm10LUhXRTJjR0E6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq). -All commits must be tested, and after each commit, all tests should be green before a pull request is sent. Please write your tests in Rspec or Test-Unit. +All commits must be tested, and after each commit, all tests should be green before a pull request is sent. Please write your tests in Rspec. GEMS: We would like to keep external dependencies unduplicated. We're using Nokogiri, and Mongomapper, and EM::HttpRequest as much as possible. We have a few gems in the project we'd rather not use, but if you can, use dependencies we already have. @@ -195,9 +195,15 @@ If you installed the OsX package through "brew", MongoDB will need to be started Diaspora will not run unless mongo is running. Mongo will not run by default, and will need to be started every time you wish to use or run the test suite for Diaspora. +### Run the server +`./script/server` will start both thin and the websocket server. If you want to run a different app server, you will have to run them separately. See below for instructions. + ### Run the app server Once mongo is running and bundler has finished, run `bundle exec thin start` from the root Diaspora directory. This will start the app server in development mode[.](http://bit.ly/9mwtUw) +### Run the websocket server +run `bundle exec ruby ./script/websocket_server` to start the websocket server on port 8080. Change the port in config/app_config.yml. + ### Logging in Run `rake db:seed:tom`, then login with user `tom` and password `evankorth`. More details in db/seeds/tom.rb. From a96a52def7ecc4404fa5e97c45feb19fa0c21dd7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 11:58:34 -0700 Subject: [PATCH 60/63] Run 3 thins --- config/sprinkle/conf/nginx.conf | 2 ++ config/thin.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index da27b393b..eba9fa45b 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -33,6 +33,8 @@ http { # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; upstream thin_cluster { server unix:/tmp/thin.0.sock; + server unix:/tmp/thin.1.sock; + server unix:/tmp/thin.2.sock; } server { diff --git a/config/thin.yml b/config/thin.yml index 7a74769cf..6a00fdb6c 100644 --- a/config/thin.yml +++ b/config/thin.yml @@ -14,7 +14,7 @@ require: [] max_persistent_conns: 512 environment: production -servers: 1 +servers: 3 daemonize: true #chdir: /usr/applications/localhash/current socket: /tmp/thin.sock From 71ac61c01d8166b8f6354f65bb8c166d293d6c5b Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 12:49:05 -0700 Subject: [PATCH 61/63] Fix websocket specs --- spec/lib/websocket_spec.rb | 20 ++++++++++++++++---- spec/spec_helper.rb | 8 +++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/spec/lib/websocket_spec.rb b/spec/lib/websocket_spec.rb index 762a725b5..018f5020d 100644 --- a/spec/lib/websocket_spec.rb +++ b/spec/lib/websocket_spec.rb @@ -9,6 +9,7 @@ describe Diaspora::WebSocket do @user = Factory.create(:user) @aspect = @user.aspect(:name => "losers") @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) + unstub_sockets end it 'should queue a job' do @@ -16,10 +17,21 @@ describe Diaspora::WebSocket do @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) end - it 'The queued job should reach Magent' do - @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) - channel = Magent::GenericChannel.new('websocket') - channel.message_count.should == 1 + describe 'queuing and dequeuing ' do + before do + @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + @channel = Magent::GenericChannel.new('websocket') + end + + it 'should send the queued job to Magent' do + @channel.message_count.should == 1 + end + + it 'should dequeue the job successfully' do + messages = @channel.message_count + @channel.dequeue + @channel.message_count.should == messages -1 + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3995846e..3fdac9810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,11 +46,17 @@ RSpec.configure do |config| end end def stub_sockets - Diaspora::WebSocket.stub!(:push_to_user).and_return(true) + Diaspora::WebSocket.stub!(:queue_to_user).and_return(true) Diaspora::WebSocket.stub!(:subscribe).and_return(true) Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) end + def unstub_sockets + Diaspora::WebSocket.unstub!(:queue_to_user) + Diaspora::WebSocket.unstub!(:subscribe) + Diaspora::WebSocket.unstub!(:unsubscribe) + end + def stub_signature_verification (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| model.any_instance.stubs(:verify_signature).returns(true) From b3549c79f4c101ff61b1e8d9d4fe393aec5e77fc Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 11:02:12 -0700 Subject: [PATCH 62/63] Give slightly more specific error message --- app/models/person.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/person.rb b/app/models/person.rb index ac4a5dfa7..1e2a7b18d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -89,6 +89,8 @@ class Person f = Redfinger.finger(identifier) rescue SocketError => e raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ + rescue Errno::ETIMEDOUT => e + raise "Connection timed out to Diaspora server for #{identifier}" end raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty? Person.from_webfinger_profile(identifier, f ) From 81d753e7737d31524adc8984482af87d6dcb9613 Mon Sep 17 00:00:00 2001 From: Stephen Caudill Date: Fri, 17 Sep 2010 00:47:01 -0400 Subject: [PATCH 63/63] Refactor Album spec * use let(!) where appropriate (see [1] for more info). * use `context` to portray scenarios * use `describe` to portray method and Class specifications * omit the word "should" from example descriptions (Dave Chelimsky remarked to me that it was "tantamount to line-noise" and I'm of the opinion that it adds no value. * use more idiomatic Ruby (prefer things like 2.times to 1.upto(2)) * use more idiomatic Rails (prefer 1.minute.from_now to Time.now + 60*60) * use more idiomatic Rspec (prefer album.should be_valid to album.valid?.should be_true * also ensure to only make one assertion per example Other sundry cleanups. [1] http://rdoc.info/github/rspec/rspec-core/master/RSpec/Core/Let/ClassMethods#let-instance_method --- spec/models/album_spec.rb | 120 ++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 63 deletions(-) diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 189361622..ed13ba102 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -2,87 +2,81 @@ # licensed under the Affero General Public License version 3. See # the COPYRIGHT file. - - -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Album do - before do - @fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png' - @user = Factory.create(:user) - @user.person.save - @aspect = @user.aspect(:name => "Foo") - @album = @user.post(:album, :name => "test collection", :to => @aspect.id) + let(:user) { Factory.create(:user) } + let(:person) { user.person } + let(:aspect) { user.aspect(:name => "Foo") } + let(:album) { user.post(:album, :name => "test collection", :to => aspect.id) } + + it 'is valid' do + album.should be_valid end - it 'should require a name' do - @album.name = "test collection" - @album.valid?.should be true - - @album.name = nil - @album.valid?.should be false + it 'validates presence of a name' do + album.name = nil + album.should_not be_valid end - it 'should contain photos' do - photo = Factory.build(:photo, :person => @user.person) - - @album.photos << photo - @album.photos.count.should == 1 + it 'has many photos' do + album.associations[:photos].type == :many end - it 'should remove all photos on album delete' do - photos = [] - 1.upto 3 do - photo = Photo.new(:person => @user.person, :album => @album, :created_at => Time.now) - photo.image.store! File.open @fixture_name - photos << photo - end - @album.photos += photos - - Photo.all.count.should == 3 - @album.destroy - Photo.all.count.should == 0 - end - - describe 'traversing' do + context 'when an album has two attached images' do before do - @photos = [] - 1.upto 3 do |n| - photo = Photo.new(:person => @user.person, :album => @album, :created_at => Time.now + n) - photo.image.store! File.open @fixture_name - @photos << photo + 2.times do + photo = Factory.build(:photo, :person => person, :album => album) + album.photos << photo end - @album.photos += @photos end - it 'should traverse the album correctly' do - #should retrieve the next photo relative to a given photo - @album.next_photo(@photos[1]).id.should == @photos[2].id - - #should retrieve the previous photo relative to a given photo - @album.prev_photo(@photos[1]).id.should == @photos[0].id - - #wrapping - #does next photo of last to first - @album.next_photo(@photos[2]).id.should == @photos[0].id - - #does previous photo of first to last - @album.prev_photo(@photos[0]).id.should == @photos[2].id + context 'when the album is deleted' do + it 'removes all child photos' do + expect{ album.destroy }.to change(Photo, :count).from(2).to(0) + end end end - describe 'serialization' do - before do - @xml = @album.to_xml.to_s + context 'traversing photos' do + let(:attrs) { {:person => person, :album => album} } + let!(:photo_1) { Factory(:photo, attrs.merge(:created_at => 2.days.ago)) } + let!(:photo_2) { Factory(:photo, attrs.merge(:created_at => 1.day.ago)) } + let!(:photo_3) { Factory(:photo, attrs.merge(:created_at => Time.now)) } + + describe '#next_photo' do + it 'returns the next photo' do + album.next_photo(photo_1).id.should == photo_2.id + end + + it 'returns the first photo when given the last photo in the album' do + album.next_photo(photo_3).id.should == photo_1.id + end end - it 'should have a person' do - @xml.include?(@album.person.id.to_s).should be true + + describe '#prev_photo' do + it 'returns the previous photo' do + album.prev_photo(photo_2).id.should == photo_1.id + end + + it 'returns the last photo when given the first photo in the album' do + album.prev_photo(photo_1).id.should == photo_3.id + end end - it 'should have a name' do - @xml.include?(@album.name).should be true + end + + describe '#to_xml' do + let(:doc) { album.to_xml } + it 'has a name' do + doc.at_xpath('./name').text.should == album.name end - it 'should have an id' do - @xml.include?(@album.id.to_s).should be true + + it 'has an id' do + doc.at_xpath('./_id').text.should == album.id.to_s + end + + it 'includes the person' do + doc.at_xpath('./person/_id').text.should == album.person.id.to_s end end end