From e4eb7a9a793e1127edfe51b75b86c3202bb14a35 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 21 Oct 2010 19:35:35 -0700 Subject: [PATCH 01/39] started the new invitation email --- app/mailers/notifier.rb | 14 ++++++ app/views/notifier/new_request.html.haml | 61 ++++++++++++++++++++++++ lib/diaspora/user/friending.rb | 1 + spec/mailers/notifier_spec.rb | 19 ++++++++ spec/models/user/user_friending_spec.rb | 14 +++++- 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 app/mailers/notifier.rb create mode 100644 app/views/notifier/new_request.html.haml create mode 100644 spec/mailers/notifier_spec.rb diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb new file mode 100644 index 000000000..56f0f3555 --- /dev/null +++ b/app/mailers/notifier.rb @@ -0,0 +1,14 @@ +class Notifier < ActionMailer::Base + default :from => "no-reply@joindiaspora.com" + + def new_request(recipient, sender) + @receiver = recipient + @sender = sender + mail(:to => recipient.email) do |format| + format.text { render :text => "This is text!" } + format.html { render :text => "

#{@receiver.person.profile.first_name}This is HTML

" } + end + end + + +end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml new file mode 100644 index 000000000..daa54c0eb --- /dev/null +++ b/app/views/notifier/new_request.html.haml @@ -0,0 +1,61 @@ +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Hello #{@receiver.first_name}! + %p + #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. + - @resource.inviters.each do |inv| + - if @resource.invite_messages[inv.id.to_s] + = "#{inv.real_name}:" + = @resource.invite_messages[inv.id.to_s] + %p + %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" + %p.small + If you don't want to accept the invitation, please ignore this email. + %br/ + Your account won't be created until you access the link above and sign up. diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 6946910f2..570ce3544 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -74,6 +74,7 @@ module Diaspora else self.pending_requests << friend_request self.save + Notifier.new_request(self, friend_request.person) Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb new file mode 100644 index 000000000..97316890d --- /dev/null +++ b/spec/mailers/notifier_spec.rb @@ -0,0 +1,19 @@ + +require 'spec_helper' + +describe Notifier do + + let(:user) {Factory.create :user} + let(:person) {Factory.create :person} + let(:request_mail) {Notifier.new_request(user, person)} + + describe "#new_request" do + it 'goes to the right person' do + request_mail.to.should == [user.email] + end + + it 'has the receivers name in the body' do + request_mail.body.encoded.includes?(user.first_name).should be true + end + end +end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 2fde487b3..83c1f456a 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -93,6 +93,16 @@ describe User do }.should_not change(Person, :count) user2.friends.include?(user.person).should be false end + + it 'sends an email to the receiving user' do + Notifier.should_receive(:new_request) + user.receive @req_xml, person_one + end + + + it 'should send a an email saying your friend request was confirmed' do + pending + end end context 'Two users receiving requests from one person' do before do @@ -107,7 +117,7 @@ describe User do user2.accept_friend_request @request_two.id, aspect2.id user2.friends.include?(person_one).should be true end - + it 'should keep the person around if one of the users rejects him' do user.accept_friend_request @request.id, aspect.id user.friends.include?(person_one).should be true @@ -124,6 +134,8 @@ describe User do user2.friends.include?(person_one).should be false end end + + end describe 'a user accepting rejecting multiple people' do From d2e3be7262ac9da9888689058f08dfdf279c864d Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 00:13:18 -0700 Subject: [PATCH 02/39] should send the email when a new request is received. emails in dev should be intercepted to email@joindiaspora.com for now --- app/mailers/notifier.rb | 8 ++------ app/views/notifier/new_request.html.haml | 21 +++++++++------------ app/views/notifier/new_request.text.haml | 9 +++++++++ config/initializers/setup_mail.rb | 1 + lib/development_mail_interceptor.rb | 7 +++++++ lib/diaspora/user/friending.rb | 2 +- spec/factories.rb | 9 +++++---- spec/mailers/notifier_spec.rb | 13 +++++++++---- spec/models/user/attack_vectors_spec.rb | 7 ++++--- 9 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 app/views/notifier/new_request.text.haml create mode 100644 config/initializers/setup_mail.rb create mode 100644 lib/development_mail_interceptor.rb diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 56f0f3555..8ce7995b4 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -4,11 +4,7 @@ class Notifier < ActionMailer::Base def new_request(recipient, sender) @receiver = recipient @sender = sender - mail(:to => recipient.email) do |format| - format.text { render :text => "This is text!" } - format.html { render :text => "

#{@receiver.person.profile.first_name}This is HTML

" } - end + mail(:to => "#{recipient.real_name} <#{recipient.email}>", + :subject => "new friend request from #{@sender.inspect}") end - - end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index daa54c0eb..54cee3ddd 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -46,16 +46,13 @@ = image_tag '/images/diaspora_white.png' #container %p - Hello #{@receiver.first_name}! + Hello #{@receiver.profile.first_name}! %p - #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. - - @resource.inviters.each do |inv| - - if @resource.invite_messages[inv.id.to_s] - = "#{inv.real_name}:" - = @resource.invite_messages[inv.id.to_s] - %p - %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" - %p.small - If you don't want to accept the invitation, please ignore this email. - %br/ - Your account won't be created until you access the link above and sign up. + = "#{@sender.real_name} (#{@sender.diaspora_handle})" + just sent you a friend request on Diaspora* + You should really think about checking it out. + + = link_to "sign in here", new_user_session_path + + love, + the diaspora email robot diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml new file mode 100644 index 000000000..1c1505f74 --- /dev/null +++ b/app/views/notifier/new_request.text.haml @@ -0,0 +1,9 @@ += "hey #{@receiver.profile.first_name}," += "#{@sender.real_name} (#{@sender.diaspora_handle})" +just sent you a friend request on Diaspora* +You should really think about checking it out. + += "sign in here: #{new_user_session_path}" + +love, +the diaspora email robot diff --git a/config/initializers/setup_mail.rb b/config/initializers/setup_mail.rb new file mode 100644 index 000000000..e94ea5133 --- /dev/null +++ b/config/initializers/setup_mail.rb @@ -0,0 +1 @@ +ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? diff --git a/lib/development_mail_interceptor.rb b/lib/development_mail_interceptor.rb new file mode 100644 index 000000000..efc89596f --- /dev/null +++ b/lib/development_mail_interceptor.rb @@ -0,0 +1,7 @@ +class DevelopmentMailInterceptor + def self.delivering_email(message) + message.subject = "[#{message.to}] #{message.subject}" + message.to = "email@joindiaspora.com" + end +end + diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 570ce3544..c7809b39d 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -74,7 +74,7 @@ module Diaspora else self.pending_requests << friend_request self.save - Notifier.new_request(self, friend_request.person) + Notifier.new_request(self, friend_request.person).deliver Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save end diff --git a/spec/factories.rb b/spec/factories.rb index c66fa4f86..8d0b76aee 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -8,14 +8,15 @@ #This inclsion, because gpg-agent(not needed) is never run and hence never sets any env. variables on a MAC Factory.define :profile do |p| - p.first_name "Robert" - p.last_name "Grimm" + p.sequence(:first_name){|n| "Robert#{n}"} + p.sequence(:last_name){|n| "Grimm#{n}"} end + Factory.define :person do |p| p.sequence(:diaspora_handle) {|n| "bob-person-#{n}@aol.com"} p.sequence(:url) {|n| "http://google-#{n}.com/"} - p.profile Factory.create(:profile) + p.profile Factory.create(:profile, :first_name => "eugene", :last_name => "weinstien") p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export end @@ -32,7 +33,7 @@ Factory.define :user do |u| u.password_confirmation "bluepin7" u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export u.after_build do |user| - user.person = Factory.build(:person, :owner_id => user._id, + user.person = Factory.build(:person, :profile => Factory.create(:profile), :owner_id => user._id, :serialized_public_key => user.encryption_key.public_key.export, :diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 97316890d..394733cea 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Notifier do - let(:user) {Factory.create :user} - let(:person) {Factory.create :person} - let(:request_mail) {Notifier.new_request(user, person)} + let!(:user) {Factory.create :user} + let!(:person) {Factory.create :person} + let!(:request_mail) {Notifier.new_request(user, person)} describe "#new_request" do it 'goes to the right person' do @@ -13,7 +13,12 @@ describe Notifier do end it 'has the receivers name in the body' do - request_mail.body.encoded.includes?(user.first_name).should be true + request_mail.body.encoded.include?(user.person.profile.first_name).should be true + end + + + it 'has the name of person sending the request' do + request_mail.body.encoded.include?(person.real_name).should be true end end end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index 67235f447..36a586647 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe User do +describe "attack vectors" do let(:user) { Factory(:user) } let(:aspect) { user.aspect(:name => 'heroes') } @@ -73,10 +73,11 @@ describe User do profile.first_name = "Not BOB" user2.reload - user2.profile.first_name.should == "Robert" + + first_name = user2.profile.first_name proc{user.receive_salmon(user3.salmon(profile).xml_for(user.person))}.should raise_error /Malicious Post/ user2.reload - user2.profile.first_name.should == "Robert" + user2.profile.first_name.should == first_name end it 'should not overwrite another persons profile through comment' do From 93ba0730097f38522565c8232df2d6ec0eb4fcc9 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 00:40:01 -0700 Subject: [PATCH 03/39] small bugfixes for the mailer --- app/mailers/notifier.rb | 2 +- app/views/notifier/new_request.html.haml | 7 ++++--- app/views/notifier/new_request.text.haml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 8ce7995b4..40a94a1f3 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -5,6 +5,6 @@ class Notifier < ActionMailer::Base @receiver = recipient @sender = sender mail(:to => "#{recipient.real_name} <#{recipient.email}>", - :subject => "new friend request from #{@sender.inspect}") + :subject => "new Diaspora* friend request from #{@sender.real_name}") end end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index 54cee3ddd..71932dc44 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -51,8 +51,9 @@ = "#{@sender.real_name} (#{@sender.diaspora_handle})" just sent you a friend request on Diaspora* You should really think about checking it out. - - = link_to "sign in here", new_user_session_path - + %br + = link_to "sign in here", new_user_session_url + %br love, + %br the diaspora email robot diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml index 1c1505f74..8ab5bc570 100644 --- a/app/views/notifier/new_request.text.haml +++ b/app/views/notifier/new_request.text.haml @@ -3,7 +3,7 @@ just sent you a friend request on Diaspora* You should really think about checking it out. -= "sign in here: #{new_user_session_path}" += "sign in here: #{new_user_session_url}" love, the diaspora email robot From 80cd4761f374355896b9b2f8a75f95cdfbc4c752 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 21 Oct 2010 19:35:35 -0700 Subject: [PATCH 04/39] started the new invitation email --- app/mailers/notifier.rb | 14 ++++++ app/views/notifier/new_request.html.haml | 61 ++++++++++++++++++++++++ lib/diaspora/user/friending.rb | 1 + spec/mailers/notifier_spec.rb | 19 ++++++++ spec/models/user/user_friending_spec.rb | 14 +++++- 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 app/mailers/notifier.rb create mode 100644 app/views/notifier/new_request.html.haml create mode 100644 spec/mailers/notifier_spec.rb diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb new file mode 100644 index 000000000..56f0f3555 --- /dev/null +++ b/app/mailers/notifier.rb @@ -0,0 +1,14 @@ +class Notifier < ActionMailer::Base + default :from => "no-reply@joindiaspora.com" + + def new_request(recipient, sender) + @receiver = recipient + @sender = sender + mail(:to => recipient.email) do |format| + format.text { render :text => "This is text!" } + format.html { render :text => "

#{@receiver.person.profile.first_name}This is HTML

" } + end + end + + +end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml new file mode 100644 index 000000000..daa54c0eb --- /dev/null +++ b/app/views/notifier/new_request.html.haml @@ -0,0 +1,61 @@ +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Hello #{@receiver.first_name}! + %p + #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. + - @resource.inviters.each do |inv| + - if @resource.invite_messages[inv.id.to_s] + = "#{inv.real_name}:" + = @resource.invite_messages[inv.id.to_s] + %p + %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" + %p.small + If you don't want to accept the invitation, please ignore this email. + %br/ + Your account won't be created until you access the link above and sign up. diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 6946910f2..570ce3544 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -74,6 +74,7 @@ module Diaspora else self.pending_requests << friend_request self.save + Notifier.new_request(self, friend_request.person) Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb new file mode 100644 index 000000000..97316890d --- /dev/null +++ b/spec/mailers/notifier_spec.rb @@ -0,0 +1,19 @@ + +require 'spec_helper' + +describe Notifier do + + let(:user) {Factory.create :user} + let(:person) {Factory.create :person} + let(:request_mail) {Notifier.new_request(user, person)} + + describe "#new_request" do + it 'goes to the right person' do + request_mail.to.should == [user.email] + end + + it 'has the receivers name in the body' do + request_mail.body.encoded.includes?(user.first_name).should be true + end + end +end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 2fde487b3..83c1f456a 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -93,6 +93,16 @@ describe User do }.should_not change(Person, :count) user2.friends.include?(user.person).should be false end + + it 'sends an email to the receiving user' do + Notifier.should_receive(:new_request) + user.receive @req_xml, person_one + end + + + it 'should send a an email saying your friend request was confirmed' do + pending + end end context 'Two users receiving requests from one person' do before do @@ -107,7 +117,7 @@ describe User do user2.accept_friend_request @request_two.id, aspect2.id user2.friends.include?(person_one).should be true end - + it 'should keep the person around if one of the users rejects him' do user.accept_friend_request @request.id, aspect.id user.friends.include?(person_one).should be true @@ -124,6 +134,8 @@ describe User do user2.friends.include?(person_one).should be false end end + + end describe 'a user accepting rejecting multiple people' do From 5701c3a8732f535fff400b72db78bfdfb1589198 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 00:13:18 -0700 Subject: [PATCH 05/39] should send the email when a new request is received. emails in dev should be intercepted to email@joindiaspora.com for now --- app/mailers/notifier.rb | 8 ++------ app/views/notifier/new_request.html.haml | 21 +++++++++------------ app/views/notifier/new_request.text.haml | 9 +++++++++ config/initializers/setup_mail.rb | 1 + lib/development_mail_interceptor.rb | 7 +++++++ lib/diaspora/user/friending.rb | 2 +- spec/factories.rb | 9 +++++---- spec/mailers/notifier_spec.rb | 13 +++++++++---- spec/models/user/attack_vectors_spec.rb | 7 ++++--- 9 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 app/views/notifier/new_request.text.haml create mode 100644 config/initializers/setup_mail.rb create mode 100644 lib/development_mail_interceptor.rb diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 56f0f3555..8ce7995b4 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -4,11 +4,7 @@ class Notifier < ActionMailer::Base def new_request(recipient, sender) @receiver = recipient @sender = sender - mail(:to => recipient.email) do |format| - format.text { render :text => "This is text!" } - format.html { render :text => "

#{@receiver.person.profile.first_name}This is HTML

" } - end + mail(:to => "#{recipient.real_name} <#{recipient.email}>", + :subject => "new friend request from #{@sender.inspect}") end - - end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index daa54c0eb..54cee3ddd 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -46,16 +46,13 @@ = image_tag '/images/diaspora_white.png' #container %p - Hello #{@receiver.first_name}! + Hello #{@receiver.profile.first_name}! %p - #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. - - @resource.inviters.each do |inv| - - if @resource.invite_messages[inv.id.to_s] - = "#{inv.real_name}:" - = @resource.invite_messages[inv.id.to_s] - %p - %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" - %p.small - If you don't want to accept the invitation, please ignore this email. - %br/ - Your account won't be created until you access the link above and sign up. + = "#{@sender.real_name} (#{@sender.diaspora_handle})" + just sent you a friend request on Diaspora* + You should really think about checking it out. + + = link_to "sign in here", new_user_session_path + + love, + the diaspora email robot diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml new file mode 100644 index 000000000..1c1505f74 --- /dev/null +++ b/app/views/notifier/new_request.text.haml @@ -0,0 +1,9 @@ += "hey #{@receiver.profile.first_name}," += "#{@sender.real_name} (#{@sender.diaspora_handle})" +just sent you a friend request on Diaspora* +You should really think about checking it out. + += "sign in here: #{new_user_session_path}" + +love, +the diaspora email robot diff --git a/config/initializers/setup_mail.rb b/config/initializers/setup_mail.rb new file mode 100644 index 000000000..e94ea5133 --- /dev/null +++ b/config/initializers/setup_mail.rb @@ -0,0 +1 @@ +ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? diff --git a/lib/development_mail_interceptor.rb b/lib/development_mail_interceptor.rb new file mode 100644 index 000000000..efc89596f --- /dev/null +++ b/lib/development_mail_interceptor.rb @@ -0,0 +1,7 @@ +class DevelopmentMailInterceptor + def self.delivering_email(message) + message.subject = "[#{message.to}] #{message.subject}" + message.to = "email@joindiaspora.com" + end +end + diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 570ce3544..c7809b39d 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -74,7 +74,7 @@ module Diaspora else self.pending_requests << friend_request self.save - Notifier.new_request(self, friend_request.person) + Notifier.new_request(self, friend_request.person).deliver Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save end diff --git a/spec/factories.rb b/spec/factories.rb index c66fa4f86..8d0b76aee 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -8,14 +8,15 @@ #This inclsion, because gpg-agent(not needed) is never run and hence never sets any env. variables on a MAC Factory.define :profile do |p| - p.first_name "Robert" - p.last_name "Grimm" + p.sequence(:first_name){|n| "Robert#{n}"} + p.sequence(:last_name){|n| "Grimm#{n}"} end + Factory.define :person do |p| p.sequence(:diaspora_handle) {|n| "bob-person-#{n}@aol.com"} p.sequence(:url) {|n| "http://google-#{n}.com/"} - p.profile Factory.create(:profile) + p.profile Factory.create(:profile, :first_name => "eugene", :last_name => "weinstien") p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export end @@ -32,7 +33,7 @@ Factory.define :user do |u| u.password_confirmation "bluepin7" u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export u.after_build do |user| - user.person = Factory.build(:person, :owner_id => user._id, + user.person = Factory.build(:person, :profile => Factory.create(:profile), :owner_id => user._id, :serialized_public_key => user.encryption_key.public_key.export, :diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 97316890d..394733cea 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Notifier do - let(:user) {Factory.create :user} - let(:person) {Factory.create :person} - let(:request_mail) {Notifier.new_request(user, person)} + let!(:user) {Factory.create :user} + let!(:person) {Factory.create :person} + let!(:request_mail) {Notifier.new_request(user, person)} describe "#new_request" do it 'goes to the right person' do @@ -13,7 +13,12 @@ describe Notifier do end it 'has the receivers name in the body' do - request_mail.body.encoded.includes?(user.first_name).should be true + request_mail.body.encoded.include?(user.person.profile.first_name).should be true + end + + + it 'has the name of person sending the request' do + request_mail.body.encoded.include?(person.real_name).should be true end end end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index 67235f447..36a586647 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe User do +describe "attack vectors" do let(:user) { Factory(:user) } let(:aspect) { user.aspect(:name => 'heroes') } @@ -73,10 +73,11 @@ describe User do profile.first_name = "Not BOB" user2.reload - user2.profile.first_name.should == "Robert" + + first_name = user2.profile.first_name proc{user.receive_salmon(user3.salmon(profile).xml_for(user.person))}.should raise_error /Malicious Post/ user2.reload - user2.profile.first_name.should == "Robert" + user2.profile.first_name.should == first_name end it 'should not overwrite another persons profile through comment' do From 20a5ec863f9822d4701c4b05a90af4356b4e98fb Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 00:40:01 -0700 Subject: [PATCH 06/39] small bugfixes for the mailer --- app/mailers/notifier.rb | 2 +- app/views/notifier/new_request.html.haml | 7 ++++--- app/views/notifier/new_request.text.haml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 8ce7995b4..40a94a1f3 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -5,6 +5,6 @@ class Notifier < ActionMailer::Base @receiver = recipient @sender = sender mail(:to => "#{recipient.real_name} <#{recipient.email}>", - :subject => "new friend request from #{@sender.inspect}") + :subject => "new Diaspora* friend request from #{@sender.real_name}") end end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index 54cee3ddd..71932dc44 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -51,8 +51,9 @@ = "#{@sender.real_name} (#{@sender.diaspora_handle})" just sent you a friend request on Diaspora* You should really think about checking it out. - - = link_to "sign in here", new_user_session_path - + %br + = link_to "sign in here", new_user_session_url + %br love, + %br the diaspora email robot diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml index 1c1505f74..8ab5bc570 100644 --- a/app/views/notifier/new_request.text.haml +++ b/app/views/notifier/new_request.text.haml @@ -3,7 +3,7 @@ just sent you a friend request on Diaspora* You should really think about checking it out. -= "sign in here: #{new_user_session_path}" += "sign in here: #{new_user_session_url}" love, the diaspora email robot From 6620f33ae2ff77afbff78a305767d4d663ed76fa Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 01:07:57 -0700 Subject: [PATCH 07/39] fixing spec with a mock on mailer --- spec/models/user/user_friending_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 83c1f456a..23444e2d5 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -95,7 +95,9 @@ describe User do end it 'sends an email to the receiving user' do - Notifier.should_receive(:new_request) + mail_obj = mock("mailer") + mail_obj.should_receive(:deliver) + Notifier.should_receive(:new_request).and_return(mail_obj) user.receive @req_xml, person_one end From 7e4529f2bdacccd1adc7f972ab02263ff155bce6 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 22 Oct 2010 06:22:47 -0700 Subject: [PATCH 08/39] im in ur test stubbin ur mailers --- spec/controllers/publics_controller_spec.rb | 19 +++-- spec/lib/diaspora_parser_spec.rb | 82 +++++++++++---------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index cf1a71d88..11a35da95 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -6,10 +6,10 @@ require 'spec_helper' describe PublicsController do render_views - let(:user) {Factory.create :user} - let(:user2){Factory.create :user} - let(:aspect1){user.aspect(:name => "foo")} - let(:aspect2){user2.aspect(:name => "far")} + let(:user) { Factory.create :user } + let(:user2) { Factory.create :user } + let(:aspect1) { user.aspect(:name => "foo") } + let(:aspect2) { user2.aspect(:name => "far") } before do sign_in :user, user end @@ -23,7 +23,7 @@ describe PublicsController do it 'should accept a post from another node and save the information' do message = user2.build_post(:status_message, :message => "hi") friend_users(user, aspect1, user2, aspect2) - + user.reload user.visible_post_ids.include?(message.id).should be false @@ -77,10 +77,13 @@ describe PublicsController do end describe 'friend requests' do - let(:aspect2) {user2.aspect(:name => 'disciples')} - let!(:req) {user2.send_friend_request_to(user.person, aspect2)} - let!(:xml) {user2.salmon(req).xml_for(user.person)} + let(:aspect2) { user2.aspect(:name => 'disciples') } + let!(:req) { user2.send_friend_request_to(user.person, aspect2) } + let!(:xml) { user2.salmon(req).xml_for(user.person) } before do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) req.delete user2.reload user2.pending_requests.count.should be 1 diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 72b3d96e0..f97a514c3 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -5,15 +5,15 @@ require 'spec_helper' describe Diaspora::Parser do - let(:user) {Factory.create(:user)} - let(:aspect) {user.aspect(:name => 'spies')} - let(:user2) {Factory.create(:user)} - let(:aspect2){user2.aspect(:name => "pandas")} - let(:user3) {Factory.create :user} - let(:person) {user3.person} + let(:user) { Factory.create(:user) } + let(:aspect) { user.aspect(:name => 'spies') } + let(:user2) { Factory.create(:user) } + let(:aspect2) { user2.aspect(:name => "pandas") } + let(:user3) { Factory.create :user } + let(:person) { user3.person } describe "parsing compliant XML object" do - it 'should be able to correctly handle comments with person in db' do + it 'should be able to correctly handle comments with person in db' do post = user.post :status_message, :message => "hello", :to => aspect.id comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!") xml = comment.to_diaspora_xml @@ -25,7 +25,7 @@ describe Diaspora::Parser do end it 'should be able to correctly handle person on a comment with person not in db' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) post = user.post :status_message, :message => "hello", :to => aspect.id comment = user2.comment "Fool!", :on => post @@ -40,42 +40,50 @@ describe Diaspora::Parser do end it 'should accept retractions' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) message = Factory.create(:status_message, :person => user2.person) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml - proc {user.receive xml, user2.person}.should change(StatusMessage, :count).by(-1) + proc { user.receive xml, user2.person }.should change(StatusMessage, :count).by(-1) end - it "should create a new person upon getting a person request" do - request = Request.instantiate(:to =>"http://www.google.com/", :from => person) + context "friending" do + before do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) + end - xml = request.to_diaspora_xml + it "should create a new person upon getting a person request" do + request = Request.instantiate(:to =>"http://www.google.com/", :from => person) - user3.destroy - person.destroy - user - lambda {user.receive xml, person}.should change(Person, :count).by(1) - end + xml = request.to_diaspora_xml - it "should not create a new person if the person is already here" do - request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person) - original_person_id = user2.person.id - xml = request.to_diaspora_xml - user - lambda {user.receive xml, user2.person}.should_not change(Person, :count) + user3.destroy + person.destroy + user + lambda { user.receive xml, person }.should change(Person, :count).by(1) + end - user2.reload - user2.person.reload - user2.serialized_private_key.include?("PRIVATE").should be true + it "should not create a new person if the person is already here" do + request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person) + original_person_id = user2.person.id + xml = request.to_diaspora_xml + user + lambda { user.receive xml, user2.person }.should_not change(Person, :count) - url = "http://" + request.callback_url.split("/")[2] + "/" - Person.where(:url => url).first.id.should == original_person_id + user2.reload + user2.person.reload + user2.serialized_private_key.include?("PRIVATE").should be true + + url = "http://" + request.callback_url.split("/")[2] + "/" + Person.where(:url => url).first.id.should == original_person_id + end end it "should activate the Person if I initiated a request to that url" do - request = user.send_friend_request_to( user3.person, aspect) + request = user.send_friend_request_to(user3.person, aspect) user.reload request.reverse_for user3 @@ -95,16 +103,16 @@ describe Diaspora::Parser do end it 'should process retraction for a person' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) retraction = Retraction.for(user2) retraction_xml = retraction.to_diaspora_xml - lambda {user.receive retraction_xml, user2.person}.should change{ - aspect.reload.people.size}.by(-1) + lambda { user.receive retraction_xml, user2.person }.should change { + aspect.reload.people.size }.by(-1) end it 'should marshal a profile for a person' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) #Create person person = user2.person id = person.id @@ -132,9 +140,9 @@ describe Diaspora::Parser do person = Person.first(:id => person.id) person.profile.should_not be nil person.profile.first_name.should == old_profile.first_name - person.profile.last_name.should == old_profile.last_name - person.profile.image_url.should == old_profile.image_url - end + person.profile.last_name.should == old_profile.last_name + person.profile.image_url.should == old_profile.image_url + end end end From ffa467b795503d145aa0efe5a511ddd0448ee9b6 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 22 Oct 2010 06:38:46 -0700 Subject: [PATCH 09/39] more stubbing! yay? --- spec/models/request_spec.rb | 8 ++++ spec/models/user/user_friending_spec.rb | 64 ++++++++++++++----------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index a7d242ee7..c75b52317 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -56,6 +56,10 @@ describe Request do end it 'recognized when a request is not from me' do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) + user2.receive_salmon(user.salmon(request).xml_for(user2.person)) user2.reload user2.request_from_me?(request).should == false @@ -64,6 +68,10 @@ describe Request do context 'quering request through user' do it 'finds requests for that user' do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) + user2.receive_salmon(user.salmon(request).xml_for(user2.person)) user2.reload user2.requests_for_me.include?(request).should == true diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 23444e2d5..6bcdeb824 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -1,3 +1,4 @@ + # Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. @@ -5,16 +6,22 @@ require 'spec_helper' describe User do - let(:user) {Factory.create :user} - let(:aspect) {user.aspect(:name => 'heroes')} - let(:aspect1) {user.aspect(:name => 'other')} + let(:user) { Factory.create :user } + let(:aspect) { user.aspect(:name => 'heroes') } + let(:aspect1) { user.aspect(:name => 'other') } let(:friend) { Factory.create(:person) } - let(:person_one) {Factory.create :person} - let(:person_two) {Factory.create :person} - - let(:user2) { Factory.create :user} - let(:aspect2) { user2.aspect(:name => "aspect two")} + let(:person_one) { Factory.create :person } + let(:person_two) { Factory.create :person } + + let(:user2) { Factory.create :user } + let(:aspect2) { user2.aspect(:name => "aspect two") } + + before do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) + end context 'friend requesting' do it "should assign a request to a aspect" do @@ -29,9 +36,9 @@ describe User do it "should be able to accept a pending friend request" do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - - proc {user.accept_friend_request(r.id, aspect.id)}.should change{ - Request.for_user(user).all.count}.by(-1) + + proc { user.accept_friend_request(r.id, aspect.id) }.should change { + Request.for_user(user).all.count }.by(-1) end it 'should be able to ignore a pending friend request' do @@ -39,8 +46,8 @@ describe User do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - proc{user.ignore_friend_request(r.id)}.should change{ - Request.for_user(user).count}.by(-1) + proc { user.ignore_friend_request(r.id) }.should change { + Request.for_user(user).count }.by(-1) end it 'should not be able to friend request an existing friend' do @@ -81,14 +88,14 @@ describe User do user2.receive @req_three_xml, user.person end it 'should befriend the user other user on the same pod' do - proc{ + proc { user2.accept_friend_request @request_three.id, aspect2.id }.should_not change(Person, :count) user2.friends.include?(user.person).should be true end it 'should not delete the ignored user on the same pod' do - proc{ + proc { user2.ignore_friend_request @request_three.id }.should_not change(Person, :count) user2.friends.include?(user.person).should be false @@ -101,17 +108,16 @@ describe User do user.receive @req_xml, person_one end - it 'should send a an email saying your friend request was confirmed' do - pending + pending end end context 'Two users receiving requests from one person' do before do user.receive @req_xml, person_one - user2.receive @req_two_xml, person_one end + it 'should both users should befriend the same person' do user.accept_friend_request @request.id, aspect.id user.friends.include?(person_one).should be true @@ -119,7 +125,7 @@ describe User do user2.accept_friend_request @request_two.id, aspect2.id user2.friends.include?(person_one).should be true end - + it 'should keep the person around if one of the users rejects him' do user.accept_friend_request @request.id, aspect.id user.friends.include?(person_one).should be true @@ -174,25 +180,25 @@ describe User do describe 'unfriending' do before do - friend_users(user,aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) end it 'should unfriend the other user on the same seed' do - lambda {user2.unfriend user.person}.should change{ - user2.friends.count}.by(-1) + lambda { user2.unfriend user.person }.should change { + user2.friends.count }.by(-1) aspect2.reload.people.count.should == 0 end it 'is unfriended by another user' do - lambda {user.unfriended_by user2.person}.should change{ - user.friends.count}.by(-1) + lambda { user.unfriended_by user2.person }.should change { + user.friends.count }.by(-1) aspect.reload.people.count.should == 0 end it 'should remove the friend from all aspects they are in' do user.add_person_to_aspect(user2.person.id, aspect1.id) - lambda {user.unfriended_by user2.person}.should change{ - user.friends.count}.by(-1) + lambda { user.unfriended_by user2.person }.should change { + user.friends.count }.by(-1) aspect.reload.people.count.should == 0 aspect1.reload.people.count.should == 0 end @@ -200,9 +206,9 @@ describe User do context 'with a post' do before do @message = user.post(:status_message, :message => "hi", :to => aspect.id) - user2.receive @message.to_diaspora_xml.to_s, user.person - user2.unfriend user.person - user.unfriended_by user2.person + user2.receive @message.to_diaspora_xml.to_s, user.person + user2.unfriend user.person + user.unfriended_by user2.person end it "deletes the unfriended user's posts from visible_posts" do user.reload.raw_visible_posts.include?(@message.id).should be_false From 47b03c45b231ca507d8aa3c3432df7870abf3301 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 10:37:04 -0700 Subject: [PATCH 10/39] commented out the email interceptor --- config/initializers/setup_mail.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/setup_mail.rb b/config/initializers/setup_mail.rb index e94ea5133..0d3f958a7 100644 --- a/config/initializers/setup_mail.rb +++ b/config/initializers/setup_mail.rb @@ -1 +1,2 @@ -ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? +# if you wish to intercept emails to go to a particuar email address +#ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? From b404346c40383c65c373704aed23349446538b8c Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:01:58 -0700 Subject: [PATCH 11/39] Stop stubbing signature verification unless it's necessary --- spec/models/comment_spec.rb | 8 ++++++++ spec/models/user/receive_spec.rb | 1 + spec/spec_helper.rb | 15 +++++---------- spec/user_encryption_spec.rb | 14 ++++---------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 1cd8e9b9d..9ebebab15 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -97,6 +97,10 @@ describe Comment do user.receive comment.to_diaspora_xml, user2.person end + context 'posts from a remote person' do + before(:all) do + stub_comment_signature_verification + end it 'should not send a comment a person made on his own post to anyone' do User::QUEUE.should_not_receive(:add_post_request) comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status) @@ -108,6 +112,10 @@ describe Comment do comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status) user.receive comment.to_diaspora_xml, @person end + after(:all) do + unstub_mocha_stubs + end + end it 'should not clear the aspect post array on receiving a comment' do aspect.post_ids.include?(@user_status.id).should be true diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 07b481b17..ab83b8c5d 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -115,6 +115,7 @@ describe User do comment_id = comment.id comment.delete + comment.post_creator_signature = comment.sign_with_key(user.encryption_key) user3.receive comment.to_diaspora_xml, user.person user3.reload diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 218def68b..80c863c67 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,10 +25,6 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation DatabaseCleaner.orm = "mongo_mapper" - config.before(:suite) do - stub_signature_verification - end - config.before(:each) do stub_sockets DatabaseCleaner.clean @@ -49,10 +45,8 @@ ImageUploader.enable_processing = false 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) - end + def stub_comment_signature_verification + Comment.any_instance.stubs(:verify_signature).returns(true) end def unstub_mocha_stubs @@ -82,11 +76,12 @@ ImageUploader.enable_processing = false aspect2.reload end - def stub_success(address = 'abc@example.com') + def stub_success(address = 'abc@example.com', opts = {}) host = address.split('@')[1] stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - if host.include?("joindiaspora.com") + if opts[:diaspora] || host.include?("diaspora") + puts address stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) else diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 645563b9a..581e4f414 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -6,7 +6,6 @@ require 'spec_helper' describe 'user encryption' do before do - unstub_mocha_stubs @user = Factory.create(:user) @aspect = @user.aspect(:name => 'dudes') @@ -14,13 +13,6 @@ describe 'user encryption' do @aspect2 = @user2.aspect(:name => 'dudes') end - after do - stub_signature_verification - #gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) - #ctx = GPGME::Ctx.new - #keys = ctx.keys - #keys.each{|k| ctx.delete_key(k, true)} - end it 'should have a key' do @user.encryption_key.should_not be nil end @@ -34,6 +26,8 @@ describe 'user encryption' do it 'should receive and marshal a public key from a request' do remote_user = Factory.build(:user) remote_user.encryption_key.nil?.should== false + + Person.should_receive(:by_webfinger).and_return(remote_user.person) #should move this to friend request, but i found it here id = remote_user.person.id original_key = remote_user.exported_key @@ -41,13 +35,13 @@ describe 'user encryption' do request = remote_user.send_friend_request_to( @user.person, remote_user.aspect(:name => "temp")) - xml = request.to_diaspora_xml + xml = remote_user.salmon(request).xml_for(@user) remote_user.person.delete remote_user.delete person_count = Person.all.count - @user.receive xml, remote_user.person + @user.receive_salmon xml Person.all.count.should == person_count + 1 new_person = Person.first(:id => id) From 6993f3e2b59d30b1fbcce972ae870ac201bd455b Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:05:37 -0700 Subject: [PATCH 12/39] Fix spec in user_encryption --- spec/user_encryption_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 581e4f414..709968278 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -27,6 +27,9 @@ describe 'user encryption' do remote_user = Factory.build(:user) remote_user.encryption_key.nil?.should== false + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) Person.should_receive(:by_webfinger).and_return(remote_user.person) #should move this to friend request, but i found it here id = remote_user.person.id From 61d539e555ad9fe40ad491948c67183e73b4a4a6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:06:31 -0700 Subject: [PATCH 13/39] Moving user_encryption_spec to lib --- spec/{user_encryption_spec.rb => lib/encryptor_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/{user_encryption_spec.rb => lib/encryptor_spec.rb} (100%) diff --git a/spec/user_encryption_spec.rb b/spec/lib/encryptor_spec.rb similarity index 100% rename from spec/user_encryption_spec.rb rename to spec/lib/encryptor_spec.rb From b67cee9af0c956db13a427f472ecc3ff04e61c95 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:09:20 -0700 Subject: [PATCH 14/39] Trying to make spec directory structure the same as the lib and app structures --- spec/lib/{ => diaspora}/exporter_spec.rb | 0 spec/lib/{ => diaspora}/importer_spec.rb | 0 spec/lib/{ostatus_builder_spec.rb => diaspora/ostatus_builder.rb} | 0 spec/lib/{diaspora_parser_spec.rb => diaspora/parser_spec.rb} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename spec/lib/{ => diaspora}/exporter_spec.rb (100%) rename spec/lib/{ => diaspora}/importer_spec.rb (100%) rename spec/lib/{ostatus_builder_spec.rb => diaspora/ostatus_builder.rb} (100%) rename spec/lib/{diaspora_parser_spec.rb => diaspora/parser_spec.rb} (100%) diff --git a/spec/lib/exporter_spec.rb b/spec/lib/diaspora/exporter_spec.rb similarity index 100% rename from spec/lib/exporter_spec.rb rename to spec/lib/diaspora/exporter_spec.rb diff --git a/spec/lib/importer_spec.rb b/spec/lib/diaspora/importer_spec.rb similarity index 100% rename from spec/lib/importer_spec.rb rename to spec/lib/diaspora/importer_spec.rb diff --git a/spec/lib/ostatus_builder_spec.rb b/spec/lib/diaspora/ostatus_builder.rb similarity index 100% rename from spec/lib/ostatus_builder_spec.rb rename to spec/lib/diaspora/ostatus_builder.rb diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora/parser_spec.rb similarity index 100% rename from spec/lib/diaspora_parser_spec.rb rename to spec/lib/diaspora/parser_spec.rb From 1a19c2819989c19198610ecb695f8e2fb68cd6ba Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:10:35 -0700 Subject: [PATCH 15/39] Move spec to user_spec --- spec/lib/encryptor_spec.rb | 3 --- spec/models/user_spec.rb | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb index 709968278..0059bc308 100644 --- a/spec/lib/encryptor_spec.rb +++ b/spec/lib/encryptor_spec.rb @@ -13,9 +13,6 @@ describe 'user encryption' do @aspect2 = @user2.aspect(:name => 'dudes') end - it 'should have a key' do - @user.encryption_key.should_not be nil - end describe 'key exchange on friending' do it 'should send over a public key' do message_queue.stub!(:add_post_request) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4b2a4d02d..ed3008b84 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -10,6 +10,10 @@ describe User do let(:user2) { Factory(:user) } let(:aspect2) { user2.aspect(:name => 'stuff') } + it 'should have a key' do + user.encryption_key.should_not be nil + end + describe "validation" do describe "of associated person" do it "fails if person is not valid" do From d8bbe38019162fcff3919fba490cc074716445ab Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:11:51 -0700 Subject: [PATCH 16/39] Move spec to request_spec --- spec/lib/encryptor_spec.rb | 5 ----- spec/models/request_spec.rb | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb index 0059bc308..d9bc82ff0 100644 --- a/spec/lib/encryptor_spec.rb +++ b/spec/lib/encryptor_spec.rb @@ -14,11 +14,6 @@ describe 'user encryption' do end describe 'key exchange on friending' do - it 'should send over a public key' do - message_queue.stub!(:add_post_request) - request = @user.send_friend_request_to(Factory.create(:person), @aspect) - request.to_diaspora_xml.include?( @user.exported_key).should be true - end it 'should receive and marshal a public key from a request' do remote_user = Factory.build(:user) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index c75b52317..6483c45fa 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -28,6 +28,7 @@ describe Request do xml.should include user.person.url xml.should include user.profile.first_name xml.should include user.profile.last_name + xml.should include user.exported_key end it 'should allow me to see only friend requests sent to me' do From 7dd86b3c875e45383da7cf26ef795ec5f4c29021 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Oct 2010 11:18:43 -0700 Subject: [PATCH 17/39] Move comment signing spec to comment spec, make encryption spec not depend on message building --- spec/lib/encryptor_spec.rb | 58 ++++--------------------------------- spec/models/comment_spec.rb | 46 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb index d9bc82ff0..e993dac45 100644 --- a/spec/lib/encryptor_spec.rb +++ b/spec/lib/encryptor_spec.rb @@ -8,9 +8,6 @@ describe 'user encryption' do before do @user = Factory.create(:user) @aspect = @user.aspect(:name => 'dudes') - - @user2 = Factory.create(:user) - @aspect2 = @user2.aspect(:name => 'dudes') end describe 'key exchange on friending' do @@ -46,57 +43,12 @@ describe 'user encryption' do describe 'encryption' do before do - @message = @user.post :status_message, :message => "hi", :to => @aspect.id + @string = File.open(File.dirname(__FILE__) + '/../fixtures/fb_status').read end - it 'should encrypt large messages' do - ciphertext = @user.encrypt @message.to_diaspora_xml - ciphertext.include?(@message.to_diaspora_xml).should be false - @user.decrypt(ciphertext).include?(@message.to_diaspora_xml).should be true + it 'should encrypt a string' do + ciphertext = @user.encrypt @string + ciphertext.include?(@string).should be false + @user.decrypt(ciphertext).should == @string end end - - describe 'comments' do - before do - friend_users(@user, @aspect, @user2, @aspect2) - @remote_message = @user2.post :status_message, :message => "hello", :to => @aspect2.id - - - @message = @user.post :status_message, :message => "hi", :to => @aspect.id - end - it 'should attach the creator signature if the user is commenting' do - @user.comment "Yeah, it was great", :on => @remote_message - @remote_message.comments.first.signature_valid?.should be true - end - - it 'should sign the comment if the user is the post creator' do - message = @user.post :status_message, :message => "hi", :to => @aspect.id - @user.comment "Yeah, it was great", :on => message - message.comments.first.signature_valid?.should be true - message.comments.first.verify_post_creator_signature.should be true - end - - it 'should verify a comment made on a remote post by a different friend' do - comment = Comment.new(:person => @user2.person, :text => "cats", :post => @remote_message) - comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key) - comment.signature_valid?.should be true - comment.verify_post_creator_signature.should be false - comment.post_creator_signature = comment.send(:sign_with_key,@user.encryption_key) - comment.verify_post_creator_signature.should be true - end - - it 'should reject comments on a remote post with only a creator sig' do - comment = Comment.new(:person => @user2.person, :text => "cats", :post => @remote_message) - comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key) - comment.signature_valid?.should be true - comment.verify_post_creator_signature.should be false - end - - it 'should receive remote comments on a user post with a creator sig' do - comment = Comment.new(:person => @user2.person, :text => "cats", :post => @message) - comment.creator_signature = comment.send(:sign_with_key,@user2.encryption_key) - comment.signature_valid?.should be true - comment.verify_post_creator_signature.should be false - end - - end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 9ebebab15..66056789d 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -138,4 +138,50 @@ describe Comment do comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true end end + + describe 'comments' do + before do + friend_users(user, aspect, user2, aspect2) + @remote_message = user2.post :status_message, :message => "hello", :to => aspect2.id + + + @message = user.post :status_message, :message => "hi", :to => aspect.id + end + it 'should attach the creator signature if the user is commenting' do + user.comment "Yeah, it was great", :on => @remote_message + @remote_message.comments.first.signature_valid?.should be true + end + + it 'should sign the comment if the user is the post creator' do + message = user.post :status_message, :message => "hi", :to => aspect.id + user.comment "Yeah, it was great", :on => message + message.comments.first.signature_valid?.should be true + message.comments.first.verify_post_creator_signature.should be true + end + + it 'should verify a comment made on a remote post by a different friend' do + comment = Comment.new(:person => user2.person, :text => "cats", :post => @remote_message) + comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key) + comment.signature_valid?.should be true + comment.verify_post_creator_signature.should be false + comment.post_creator_signature = comment.send(:sign_with_key,user.encryption_key) + comment.verify_post_creator_signature.should be true + end + + it 'should reject comments on a remote post with only a creator sig' do + comment = Comment.new(:person => user2.person, :text => "cats", :post => @remote_message) + comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key) + comment.signature_valid?.should be true + comment.verify_post_creator_signature.should be false + end + + it 'should receive remote comments on a user post with a creator sig' do + comment = Comment.new(:person => user2.person, :text => "cats", :post => @message) + comment.creator_signature = comment.send(:sign_with_key,user2.encryption_key) + comment.signature_valid?.should be true + comment.verify_post_creator_signature.should be false + end + + end + end From 9a217d1fa8386792c54d3417ae2e013a4e8bf25a Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 11:55:50 -0700 Subject: [PATCH 18/39] MS IZ request acceptance email --- app/mailers/notifier.rb | 13 +++- app/views/notifier/new_request.html.haml | 2 +- app/views/notifier/request_accepted.html.haml | 59 +++++++++++++++++++ app/views/notifier/request_accepted.text.haml | 9 +++ lib/diaspora/user/friending.rb | 5 +- spec/mailers/notifier_spec.rb | 22 +++++++ spec/models/user/user_friending_spec.rb | 41 ++++++++----- 7 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 app/views/notifier/request_accepted.html.haml create mode 100644 app/views/notifier/request_accepted.text.haml diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 40a94a1f3..f360f2a6f 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -4,7 +4,18 @@ class Notifier < ActionMailer::Base def new_request(recipient, sender) @receiver = recipient @sender = sender + attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png") + mail(:to => "#{recipient.real_name} <#{recipient.email}>", - :subject => "new Diaspora* friend request from #{@sender.real_name}") + :subject => "new Diaspora* friend request from #{@sender.real_name}", :host => APP_CONFIG[:terse_pod_url]) + end + + def request_accepted(recipient, sender, aspect) + @receiver = recipient + @sender = sender + @aspect = aspect + attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png") + mail(:to => "#{recipient.real_name} <#{recipient.email}>", + :subject => "#{@sender.real_name} has accepted your friend request on Diaspora*", :host => APP_CONFIG[:terse_pod_url]) end end diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index 71932dc44..66bb56f1a 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -43,7 +43,7 @@ } %body %header - = image_tag '/images/diaspora_white.png' + = image_tag 'diaspora_white.png' #container %p Hello #{@receiver.profile.first_name}! diff --git a/app/views/notifier/request_accepted.html.haml b/app/views/notifier/request_accepted.html.haml new file mode 100644 index 000000000..191f8f42c --- /dev/null +++ b/app/views/notifier/request_accepted.html.haml @@ -0,0 +1,59 @@ +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag 'diaspora_white.png' + #container + %p + Hello #{@receiver.profile.first_name}! + %p + = "#{@sender.real_name} (#{@sender.diaspora_handle})" + has accepted your friend request. They are now in your + = link_to @aspect.name, aspect_url(@aspect) + aspect. + + %br + love, + %br + the diaspora email robot diff --git a/app/views/notifier/request_accepted.text.haml b/app/views/notifier/request_accepted.text.haml new file mode 100644 index 000000000..e10623f16 --- /dev/null +++ b/app/views/notifier/request_accepted.text.haml @@ -0,0 +1,9 @@ += "hey #{@receiver.profile.first_name}," += "#{@sender.real_name} (#{@sender.diaspora_handle})" +has accepted your friend request. They are now in your += "#{@aspect.name} asepct.\n" += "#{aspect_url(@aspect)}" + + +love, \n +the diaspora email robot diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index c7809b39d..3e0f6b3c5 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -63,14 +63,17 @@ module Diaspora def receive_friend_request(friend_request) Rails.logger.info("receiving friend request #{friend_request.to_json}") + + #response from a friend request you sent if request_from_me?(friend_request) && self.aspect_by_id(friend_request.aspect_id) aspect = self.aspect_by_id(friend_request.aspect_id) activate_friend(friend_request.person, aspect) Rails.logger.info("#{self.real_name}'s friend request has been accepted") - + Notifier.request_accepted(self, friend_request.person, aspect).deliver friend_request.destroy + #this is a new friend request else self.pending_requests << friend_request self.save diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 394733cea..88550680f 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -4,8 +4,11 @@ require 'spec_helper' describe Notifier do let!(:user) {Factory.create :user} + let!(:aspect) {user.aspect(:name => "science")} let!(:person) {Factory.create :person} let!(:request_mail) {Notifier.new_request(user, person)} + let!(:request_accepted_mail) {Notifier.request_accepted(user, person, aspect)} + describe "#new_request" do it 'goes to the right person' do @@ -21,4 +24,23 @@ describe Notifier do request_mail.body.encoded.include?(person.real_name).should be true end end + + describe "#request_accpeted" do + it 'goes to the right person' do + request_accepted_mail.to.should == [user.email] + end + + it 'has the receivers name in the body' do + request_accepted_mail.body.encoded.include?(user.person.profile.first_name).should be true + end + + + it 'has the name of person sending the request' do + request_accepted_mail.body.encoded.include?(person.real_name).should be true + end + + it 'has the name of the aspect in the body' do + request_accepted_mail.body.encoded.include?(aspect.name).should be true + end + end end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 6bcdeb824..63a472031 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' -describe User do +describe Diaspora::UserModules::Friending do let(:user) { Factory.create :user } let(:aspect) { user.aspect(:name => 'heroes') } let(:aspect1) { user.aspect(:name => 'other') } @@ -21,6 +21,7 @@ describe User do deliverable = Object.new deliverable.stub!(:deliver) Notifier.stub!(:new_request).and_return(deliverable) + Notifier.stub!(:request_accepted).and_return(deliverable) end context 'friend requesting' do @@ -61,6 +62,13 @@ describe User do proc { user.send_friend_request_to(nil, aspect) }.should raise_error(RuntimeError, /befriend yourself/) end + it 'should send an email on acceptance if a friend request' do + Notifier.should_receive(:request_accepted) + request = user.send_friend_request_to(user2.person, aspect) + request.reverse_for(user2) + user.receive_friend_request(request) + end + describe 'multiple users accepting/rejecting the same person' do @@ -108,9 +116,7 @@ describe User do user.receive @req_xml, person_one end - it 'should send a an email saying your friend request was confirmed' do - pending - end + end context 'Two users receiving requests from one person' do before do @@ -118,21 +124,24 @@ describe User do user2.receive @req_two_xml, person_one end - it 'should both users should befriend the same person' do - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + describe '#accept_friend_request' do + it 'should both users should befriend the same person' do + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true - user2.accept_friend_request @request_two.id, aspect2.id - user2.friends.include?(person_one).should be true + user2.accept_friend_request @request_two.id, aspect2.id + user2.friends.include?(person_one).should be true + end + + it 'should keep the person around if one of the users rejects him' do + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true + + user2.ignore_friend_request @request_two.id + user2.friends.include?(person_one).should be false + end end - it 'should keep the person around if one of the users rejects him' do - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true - - user2.ignore_friend_request @request_two.id - user2.friends.include?(person_one).should be false - end it 'should keep the person around if the users ignores them' do user.ignore_friend_request user.pending_requests.first.id From cbd3487705ab2208549dbdf890d66b03620247d6 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 12:00:14 -0700 Subject: [PATCH 19/39] moved the nailer to the end so setup of mailer doesnt mess with the communitcation --- lib/diaspora/user/friending.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 3e0f6b3c5..4a19ffd68 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -71,15 +71,15 @@ module Diaspora activate_friend(friend_request.person, aspect) Rails.logger.info("#{self.real_name}'s friend request has been accepted") - Notifier.request_accepted(self, friend_request.person, aspect).deliver friend_request.destroy + Notifier.request_accepted(self, friend_request.person, aspect).deliver #this is a new friend request else self.pending_requests << friend_request self.save - Notifier.new_request(self, friend_request.person).deliver Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save + Notifier.new_request(self, friend_request.person).deliver end end From 637d35d673ee47ade781566c01d4a0559d5378e8 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 12:27:28 -0700 Subject: [PATCH 20/39] Remove puts --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 80c863c67..29d731b29 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -81,7 +81,6 @@ ImageUploader.enable_processing = false stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) if opts[:diaspora] || host.include?("diaspora") - puts address stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) else From ebfdaea38f18c4470f33235ea1ba4ca91c0f6fae Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 15:24:46 -0700 Subject: [PATCH 21/39] do not pass in the diaspora handle query as a regex, we want to search on the string literal. also use dynamic finder --- app/models/person.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 1e063a743..bb94b36d9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -97,8 +97,8 @@ class Person # Raise an error if identifier is not a valid email (generous regexp) raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/) - query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i - local_person = Person.first(:diaspora_handle => query) + query = Regexp.escape(identifier.gsub('acct:', '').to_s + local_person = Person.find_by_diaspora_handle(:diaspora_handle => query) if local_person Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") From bcec2d04e6ba9915b985b4b85537a242952dfed5 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 15:24:46 -0700 Subject: [PATCH 22/39] do not pass in the diaspora handle query as a regex, we want to search on the string literal. also use dynamic finder --- app/models/person.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 1e063a743..e7745c3b9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -97,8 +97,8 @@ class Person # Raise an error if identifier is not a valid email (generous regexp) raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/) - query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i - local_person = Person.first(:diaspora_handle => query) + query = identifier.gsub('acct:', '').to_s + local_person = Person.find_by_diaspora_handle(:diaspora_handle => query) if local_person Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") From ed4c253ea8e7daf703bccb68259894c91b0fed71 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 15:32:41 -0700 Subject: [PATCH 23/39] show pages now identify content with content creator. publisher now takes a local --- app/views/albums/_new_album.haml | 17 ++- app/views/albums/index.html.haml | 19 +--- app/views/albums/show.html.haml | 13 +-- app/views/aspects/index.html.haml | 2 +- app/views/aspects/show.html.haml | 2 +- app/views/photos/show.html.haml | 13 +-- app/views/shared/_author_info.html.haml | 15 +++ app/views/shared/_publisher.haml | 55 ++++++---- app/views/status_messages/show.html.haml | 8 +- public/stylesheets/sass/application.sass | 132 ++++++++++++++++------- 10 files changed, 166 insertions(+), 110 deletions(-) create mode 100644 app/views/shared/_author_info.html.haml diff --git a/app/views/albums/_new_album.haml b/app/views/albums/_new_album.haml index d7bd2d997..e8cd3e778 100644 --- a/app/views/albums/_new_album.haml +++ b/app/views/albums/_new_album.haml @@ -2,14 +2,11 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4= t('.add_a_new_album') - = form_for Album.new do |f| - = f.error_messages - %p - = f.label :name - = f.text_field :name - = f.hidden_field :to, :value => aspect - = f.submit t('.create'), :class => 'button' += form_for Album.new do |album| + = album.error_messages + %p + = album.label :name + = album.hidden_field :to, :value => aspect + = album.text_field :name + = album.submit t('.create'), :class => 'button' diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml index b9e62113f..ea046d7aa 100644 --- a/app/views/albums/index.html.haml +++ b/app/views/albums/index.html.haml @@ -8,22 +8,11 @@ $("#add_album_button").fancybox(); }); -%h2 - = @aspect - .friend_pictures.horizontal - = owner_image_link - - for friend in @friends - = person_image_link(friend) +.span-4.append-1.last + = render "shared/aspect_friends" -.span-24.last - %h3 - = @aspect - Albums - = link_to t('.new_album'), '#new_album_pane', {:class => "button", :id => "add_album_button"} - - .fancybox_content - #new_album_pane - = render "albums/new_album", :aspect => params[:aspect] +.span-15.last + = render "shared/publisher", :type => :album, :aspect => @aspect.id %div - for album in @albums diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index d6f834c82..6ab43e69d 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -9,15 +9,12 @@ }); }); -%h2 - = @aspect - .friend_pictures.horizontal - = owner_image_link - - for friend in @friends - = person_image_link(friend) -%h3 - = link_to "#{@aspect} Albums", albums_path(:aspect => @aspect) += render 'shared/author_info', :post => @album + +%ul#breadcrumb + %li= link_to "Photos", '#' + %li= @album.name .span-19.appends-1.last diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 8ffe1a519..dbc8ec95e 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -7,7 +7,7 @@ .span-15.last = render 'aspects/no_friends_message' - = render 'shared/publisher' + = render 'shared/publisher', :type => :status_message, :aspect => @aspect = render 'aspects/no_posts_message' %ul#stream - for post in @posts diff --git a/app/views/aspects/show.html.haml b/app/views/aspects/show.html.haml index 8ffe1a519..dbc8ec95e 100644 --- a/app/views/aspects/show.html.haml +++ b/app/views/aspects/show.html.haml @@ -7,7 +7,7 @@ .span-15.last = render 'aspects/no_friends_message' - = render 'shared/publisher' + = render 'shared/publisher', :type => :status_message, :aspect => @aspect = render 'aspects/no_posts_message' %ul#stream - for post in @posts diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index e4ae23170..40fbc119c 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -55,15 +55,12 @@ });//end document ready -%h2 - = @aspect - .friend_pictures.horizontal - = owner_image_link - - for friend in @friends - = person_image_link(friend) += render 'shared/author_info', :post => @photo -%h3 - = link_to @photo.album.name, @photo.album +%ul#breadcrumb + %li= link_to "Photos", '#' + %li= link_to @album.name, album_path(@album) + %li= @photo.caption = link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch' | diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml new file mode 100644 index 000000000..6a619c44b --- /dev/null +++ b/app/views/shared/_author_info.html.haml @@ -0,0 +1,15 @@ +#author_info + = owner_image_link + .from + %h2 + = post.person.real_name + .aspect + ➔ + %ul + - if post.public? + the world + - else + - for aspect in current_user.aspects_with_post( post.id ) + %li= link_to aspect.name, aspect + + = link_to "view profile", person_path(post.person) diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 3a5a9f468..832c07916 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -9,7 +9,7 @@ }; }); - $("#publisher textarea").live("focus", function(evt){ + $("#publisher textarea, #publisher input").live("focus", function(evt){ $("#publisher .options_and_submit").fadeIn(50); }); @@ -20,28 +20,41 @@ #publisher = owner_image_tag - = form_for StatusMessage.new, :remote => true do |status| - = status.error_messages - %p - = status.label :message, "Post a message to #{@aspect}" - = status.text_area :message, :rows => 2, :value => params[:prefill] + - if( !defined?(type) || type == :status_message ) + = form_for StatusMessage.new, :remote => true do |status| + = status.error_messages + %p + = status.label :message, "Post a message to #{aspect}" + = status.text_area :message, :rows => 2, :value => params[:prefill] - = status.hidden_field :to, :value => (@aspect == :all ? @aspect : @aspect.id) + = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) - .options_and_submit - - - if @aspect == :all - .public_toggle - = status.check_box( :public, :value => false ) - make public - = link_to '(?)', "#question_mark_pane", :class => 'question_mark' + .options_and_submit + + - if aspect == :all + .public_toggle + = status.check_box( :public, :value => false ) + make public + = link_to '(?)', "#question_mark_pane", :class => 'question_mark' - .fancybox_content - #question_mark_pane - = render 'shared/public_explain' + .fancybox_content + #question_mark_pane + = render 'shared/public_explain' - - if @aspect == :all - = status.submit t('.share'), :title => "Share with all aspects" - - else - = status.submit t('.share'), :title => "Share with #{@aspect}" + - if aspect == :all + = status.submit t('.share'), :title => "Share with all aspects" + - else + = status.submit t('.share'), :title => "Share with #{aspect}" + + - else + = form_for Album.new do |album| + = album.error_messages + %p + = album.label :name + = album.text_field :name + + = album.hidden_field :to, :value => aspect + + .options_and_submit + = album.submit "Create", :class => 'button' diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 398b3a536..1e0f15438 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -3,17 +3,11 @@ -# the COPYRIGHT file. -%h2 - = @aspect - .friend_pictures.horizontal - - for friend in @friends - = person_image_link(friend) += render 'shared/author_info', :post => @status_message .span-14.append-1.last #stream %h1.show_text - = person_image_link(@status_message.person) - = link_to @status_message.person.real_name, @status_message.person = make_links(@status_message.message) = "Posted #{how_long_ago(@status_message)} to" diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index bffe9e526..a33b547dd 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -202,6 +202,71 @@ header .avatar :border-radius 5px + +.from + :font + :family 'Helvetica neue', Arial, Helvetica, sans-serif + :text + :shadow 0 1px #fff + + .aspect + :cursor default + :display inline + :color #bbb + :font + :size 85% + a + :font + :weight normal + :color #bbb + + &:hover + :text + :decoration underline + &:active + :color #999 + ul + :display inline + :margin 0 + :padding 0 + :list + :style none + li + :display inline + &:after + :content "," + &:last-child:after + :content "" + + a + :font + :weight bold + +#author_info + :position relative + :padding + :left 65px + :height 70px + + img + :position absolute + :top 8px + :left 0 + + h2 + :margin + :bottom -2px + a + :font + :weight normal + + .from + :font + :size 14px + + .avatar + :border-radius 5px + li.message :position relative :line-height 19px @@ -220,44 +285,6 @@ li.message :padding :left 65px - .from - :font - :family 'Helvetica neue', Arial, Helvetica, sans-serif - :text - :shadow 0 1px #fff - - .aspect - :cursor default - :display inline - :color #bbb - :font - :size 12px - a - :font - :weight normal - :color #bbb - - &:hover - :text - :decoration underline - &:active - :color #999 - ul - :display inline - :margin 0 - :padding 0 - :list - :style none - li - :display inline - &:after - :content "," - &:last-child:after - :content "" - - a - :font - :weight bold :color #444 :font @@ -639,8 +666,11 @@ label :position relative textarea - :width 515px :height 42px + + input[type='text'], + textarea + :width 515px :margin 0 .options_and_submit @@ -1136,3 +1166,27 @@ header .controls :display inline +ul#breadcrumb + :list + :style none + :margin 0 + :padding 0 + :font + :size 14px + :weight bold + :line + :height 3em + + a + :font + :weight bold + + > li + :display inline + + &:after + :content ' ››' + + &:last-child + &:after + :content '' From 837b41820127cd81fd10b4f6a9d318b5188b43f3 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 15:37:22 -0700 Subject: [PATCH 24/39] reverting, going to write a test --- app/models/person.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index e7745c3b9..211d3fcf0 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -97,9 +97,9 @@ class Person # Raise an error if identifier is not a valid email (generous regexp) raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/) - query = identifier.gsub('acct:', '').to_s - local_person = Person.find_by_diaspora_handle(:diaspora_handle => query) - + query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i + local_person = Person.first(:diaspora_handle => query) + if local_person Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") local_person From f2cfa3c378210d90fbd641b92bd7530688f701ad Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 15:38:22 -0700 Subject: [PATCH 25/39] user name in breadcrumb --- app/views/albums/show.html.haml | 2 +- app/views/photos/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index 6ab43e69d..4941a2bee 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -13,7 +13,7 @@ = render 'shared/author_info', :post => @album %ul#breadcrumb - %li= link_to "Photos", '#' + %li= link_to "#{@album.person.profile.first_name}'s Photos", '#' %li= @album.name diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 40fbc119c..9b48538e5 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -58,7 +58,7 @@ = render 'shared/author_info', :post => @photo %ul#breadcrumb - %li= link_to "Photos", '#' + %li= link_to "#{@album.person.profile.first_name}'s Photos", '#' %li= link_to @album.name, album_path(@album) %li= @photo.caption From b5976753ea11e0679147de8d2aa2497215d80e06 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 15:47:22 -0700 Subject: [PATCH 26/39] removed unused view --- app/views/shared/_sub_header.haml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 app/views/shared/_sub_header.haml diff --git a/app/views/shared/_sub_header.haml b/app/views/shared/_sub_header.haml deleted file mode 100644 index 6f4032c1e..000000000 --- a/app/views/shared/_sub_header.haml +++ /dev/null @@ -1,20 +0,0 @@ -#aspect_header - .container - .span-4.last - - if @person - %h2 - = @person.real_name - - else - %h2 - - if @aspect == :all - = link_to "Everyone", root_path - - elsif @aspect == :manage - = link_to t('.manage_aspects'), root_path - - else - = link_to @aspect.name, @aspect - - .page_title - = yield :page_title - - .span-15.last{ :style => "position:relative;" } - = yield :publish From 69528b95a388b543d30c05b0988c3eb794fc35be Mon Sep 17 00:00:00 2001 From: danielvincent Date: Thu, 21 Oct 2010 19:07:35 -0700 Subject: [PATCH 27/39] removed ignore bucket. people now have x's to delete them --- app/views/aspects/manage.html.haml | 11 ++-- public/javascripts/aspect-edit.js | 75 +++++++++++----------- public/stylesheets/sass/application.sass | 80 +++++++++++++++++------- 3 files changed, 98 insertions(+), 68 deletions(-) diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 3fdedbad9..6f6c267fb 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -31,11 +31,6 @@ %ul.dropzone %li.grey Drag to remove person from aspect - %h3=t('.ignore_remove') - .remove - %ul.dropzone - %li.grey Drag to ignore/remove - = render 'shared/invitations', :invites => @invites .span-19.last @@ -61,9 +56,11 @@ -for person in aspect.people %li.person{:id => person.id, :class => person.id, :from_aspect_id => aspect.id} + .delete + .x + X + .circle = person_image_tag(person) - .name - = link_to person.real_name, person .fancybox_content %div{:id => "add_request_pane_#{aspect.id}"} diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 825433e0e..e8f8d4352 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -47,9 +47,9 @@ $(function() { var dropzone = $(this)[0]; if ($(this)[0].id == ui.draggable[0].getAttribute('from_aspect_id')){ - ui.draggable.css('background-color','#333'); + ui.draggable.css('background','none'); } else { - ui.draggable.css('background-color','orange'); + ui.draggable.css('background','none'); $.ajax({ url: "/aspects/move_friend/", data: {"friend_id" : ui.draggable[0].id, @@ -57,7 +57,7 @@ $(function() { "to" : { "to" : dropzone.id }}, success: function(data){ ui.draggable.attr('from_aspect_id', dropzone.id); - ui.draggable.css('background-color','#333'); + ui.draggable.css('background','none'); }}); } @@ -65,35 +65,6 @@ $(function() { } }); - $(".remove ul").droppable({ - hoverClass: 'active', - drop: function(event, ui) { - - if ($(ui.draggable[0]).hasClass('requested_person')){ - $.ajax({ - type: "DELETE", - url: "/requests/" + ui.draggable.attr('request_id'), - success: function () { - decrementRequestsCounter(); - } - }); - - } else { - $.ajax({ - type: "DELETE", - url: "/people/" + ui.draggable.attr('id'), - success: function () { - alert("Removed Friend, proably want an undo countdown.") - } - }); - - } - - $(ui.draggable[0]).fadeOut('slow'); - $(ui.draggable[0]).remove(); - } - }); - $(".aspect_remove ul").droppable({ hoverClass: 'active', drop: function(event, ui) { @@ -114,11 +85,7 @@ $(function() { } $(ui.draggable[0]).fadeOut('slow'); $(ui.draggable[0]).remove(); - - } - - } }); @@ -147,5 +114,39 @@ $(function() { }); }); }); - }); + + +//deletion +$(".delete").live("click", function() { + + var person = $(this).closest("li.person"); + request_id = person.attr("request_id"); + + if (request_id){ + if( confirm("Remove this person from all aspects?") ){ + $.ajax({ + type: "DELETE", + url: "/requests/" + request_id, + success: function () { + decrementRequestsCounter(); + } + }); + } + + } else { + if( confirm("Remove this person from all aspects?") ){ + + var person_id = $(this).closest("li.person").attr('id'); + + $.ajax({ + type: "DELETE", + url: "/people/" + person_id, + success: function() { + person.fadeOut(200); + } + }); + } + } +}); + diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index a33b547dd..e0b89a23e 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -968,39 +968,71 @@ h1.big_text .person, .requested_person :display inline-block - :padding 5px :cursor move - :margin 5px :z-index 10 + :position relative + :padding 0 + :margin 0 - :width 110px - - :background - :color #333 - - :border-radius 5px - :color #ccc - - a - :color #ccc + :color #eee img - :height 40px - :width 40px - :display inline + :height 70px + :width 70px + :border-radius 5px - .name - :display inline - :top 0 - :margin - :left 5px + &:hover + .delete + :display inline &:active :z-index 20 - :color #666 - :-webkit-box-shadow 0 1px 3px #000 - :-moz-box-shadow 0 2px 4px #000 - :opacity 0.9 + img + :-webkit-box-shadow 0 1px 3px #000 + :-moz-box-shadow 0 2px 4px #000 + :opacity 0.9 + + .delete + :display none + + .delete + :display none + + :position absolute + :top -8px + :left -8px + + .circle + :z-index 1 + :position absolute + :background + :color #333 + + :width 20px + :max-width 20px + :height 20px + :max-height 20px + + :border 1px solid #fff + + :-webkit-border-radius 20px + :-moz-border-radius 20px + :border-radius 20px + + :-webkit-box-shadow 0 1px 3px #000 + + .x + :z-index 2 + :position absolute + :top 2px + :left 7px + + &:hover + :cursor default + .circle + :background + :color rgba(208,49,43,1) + ul#settings_nav :display inline From e1f4e12b8f8806c812578da4d2553d4b67b7ef60 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 00:15:46 -0700 Subject: [PATCH 28/39] style. also, made sense of aspect-edit.js --- app/views/aspects/manage.html.haml | 18 +-- public/javascripts/aspect-edit.js | 140 +++++++++++------------ public/stylesheets/sass/application.sass | 39 ++++--- 3 files changed, 102 insertions(+), 95 deletions(-) diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 6f6c267fb..c0fdacc89 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -10,7 +10,7 @@ %h2 Manage aspects .right - = link_to(t('.add_a_new_aspect'), "#add_aspect_pane", :class => "new_aspect add_aspect_button button", :title => t('.add_a_new_aspect')) + = link_to("+ #{t('.add_a_new_aspect')}", "#add_aspect_pane", :class => "new_aspect add_aspect_button button", :title => t('.add_a_new_aspect')) .span-4.append-1.last %h3=t('.requests') @@ -21,10 +21,8 @@ %li.grey No new requests - else - for request in @remote_requests - %li.requested_person{:id => request.person.id, :request_id => request.id} + %li.person.request{:data=>{:guid=>request.id, :person_id=>request.person.id}} = person_image_tag(request.person) - .name - = request.person.real_name %h3 Remove from Aspect .aspect_remove @@ -36,32 +34,34 @@ .span-19.last %ul#aspect_list - for aspect in @aspects - %li.aspect + %li.aspect{:data=>{:guid=>aspect.id}} .aspect_name %span.edit_name_field - %h3{:contenteditable => true}= aspect.name + %h3{:contenteditable=>true} + = aspect.name %span.tip click to edit %ul.tools %li= link_to t('.add_a_new_friend'), "#add_request_pane_#{aspect.id}", :class => 'add_request_button' %li!= remove_link(aspect) - %ul.dropzone{:id => aspect.id} + %ul.dropzone{:data=>{:aspect_id=>aspect.id}} -if aspect.people.size < 1 %li.grey Drag to add people -else -for person in aspect.people - - %li.person{:id => person.id, :class => person.id, :from_aspect_id => aspect.id} + %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} .delete .x X .circle = person_image_tag(person) + + .fancybox_content %div{:id => "add_request_pane_#{aspect.id}"} = render "requests/new_request", :aspect => aspect diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index e8f8d4352..177701ed3 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -4,9 +4,9 @@ */ function decrementRequestsCounter() { - var $new_requests = $(".new_requests"), - request_html = $new_requests.html(), - old_request_count = request_html.match(/\d+/); + var $new_requests = $(".new_requests"); + var request_html = $new_requests.html(); + var old_request_count = request_html.match(/\d+/); if( old_request_count == 1 ) { $new_requests.html( @@ -19,112 +19,84 @@ function decrementRequestsCounter() { } } +// Dragging person between aspects $(function() { - // Multiple classes here won't work - $("ul .person").draggable({ - revert: true - }); + $("ul .person").draggable({ revert: true }); + $("ul .requested_person").draggable({ revert: true }); - $("ul .requested_person").draggable({ - revert: true - }); - - $(".aspect ul").droppable({ + $(".aspect ul.dropzone").droppable({ hoverClass: 'active', drop: function(event, ui) { - if ($(ui.draggable[0]).hasClass('requested_person')){ + var dropzone = $(this); + var person = ui.draggable; + + if( person.hasClass('request') ){ $.ajax({ type: "DELETE", - url: "/requests/" + ui.draggable[0].getAttribute('request_id') , - data: {"accept" : true , "aspect_id" : $(this)[0].id }, + url: "/requests/" + person.attr('data-guid'), + data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') }, success: function(data){ decrementRequestsCounter(); } }); - }; - var dropzone = $(this)[0]; - - if ($(this)[0].id == ui.draggable[0].getAttribute('from_aspect_id')){ - ui.draggable.css('background','none'); - } else { - ui.draggable.css('background','none'); - $.ajax({ - url: "/aspects/move_friend/", - data: {"friend_id" : ui.draggable[0].id, - "from" : ui.draggable[0].getAttribute('from_aspect_id'), - "to" : { "to" : dropzone.id }}, - success: function(data){ - ui.draggable.attr('from_aspect_id', dropzone.id); - ui.draggable.css('background','none'); - }}); + if( dropzone.attr('data-aspect_id') != person.attr('data-aspect_id' )){ + $.ajax({ + url: "/aspects/move_friend/", + data: {"friend_id" : person.attr('data-guid'), + "from" : person.attr('data-aspect_id'), + "to" : { "to" : dropzone.attr('data-aspect_id') }}, + success: function(data){ + person.attr('data-aspect_id', dropzone.attr('data-aspect_id')); + }}); } - $(this).closest("ul").append(ui.draggable); + + $(this).closest("ul").append(person); } }); + $(".aspect_remove ul").droppable({ hoverClass: 'active', drop: function(event, ui) { - if ($( "." + ui.draggable[0].id).length == 1) { + + var person = ui.draggable; + + if ( person.attr('data-guid').length == 1 ) { alert("You can not remove the person from the last aspect"); + } else { - if (!$(ui.draggable[0]).hasClass('requested_person')){ - var aspect = ui.draggable[0].getAttribute('from_aspect_id') - var person_id = ui.draggable[0].id + if( !person.hasClass('request') ){ + $.ajax({ type: "POST", url: "/aspects/remove_from_aspect", data:{ - 'friend_id' : person_id, - 'aspect_id' : aspect - } + 'friend_id' : person.attr('data-guid'), + 'aspect_id' : person.attr('data-aspect_id') } }); } - $(ui.draggable[0]).fadeOut('slow'); - $(ui.draggable[0]).remove(); + person.fadeOut('slow', $(this).remove()); } } }); - $(".aspect h3").live( 'focus', function() { - - var $this = $(this), - id = $this.closest("li").children("ul").attr("id"), - link = "/aspects/"+ id; - - $this.keypress(function(e) { - if (e.which == 13) { - e.preventDefault(); - $this.blur(); - - //save changes - $.ajax({ - type: "PUT", - url: link, - data: {"aspect" : {"name" : $this.text() }} - }); - } - //update all other aspect links - $this.keyup(function(e) { - $("#aspect_nav a[href='"+link+"']").text($this.text()); - }); - }); - }); }); -//deletion +// Person deletion $(".delete").live("click", function() { var person = $(this).closest("li.person"); - request_id = person.attr("request_id"); - if (request_id){ - if( confirm("Remove this person from all aspects?") ){ + if (person.hasClass('request')){ + + if( confirm("Ignore request?") ){ + var request_id = person.attr("data-guid"); + $.ajax({ type: "DELETE", url: "/requests/" + request_id, @@ -135,9 +107,9 @@ $(".delete").live("click", function() { } } else { - if( confirm("Remove this person from all aspects?") ){ - var person_id = $(this).closest("li.person").attr('id'); + if( confirm("Remove this person from all aspects?") ){ + var person_id = $(this).closest("li.person").attr('data-guid'); $.ajax({ type: "DELETE", @@ -150,3 +122,29 @@ $(".delete").live("click", function() { } }); + +// Editing aspect name +$(".aspect h3").live('focus', function() { + + var $this = $(this); + var id = $this.closest("li.aspect").attr("data-guid"); + var link = "/aspects/"+ id; + + $this.keypress(function(e) { + if (e.which == 13) { + e.preventDefault(); + $this.blur(); + + //save changes + $.ajax({ + type: "PUT", + url: link, + data: {"aspect" : {"name" : $this.text() }} + }); + } + //update all other aspect links + $this.keyup(function(e) { + $("#aspect_nav a[href='"+link+"']").text($this.text()); + }); + }); +}); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index e0b89a23e..b6d6516d1 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -903,13 +903,7 @@ h1.big_text :padding 2px -.aspect, -.requests, -.remove, -.aspect_remove - :list - :style none - +.aspect h3 :display inline-block @@ -944,7 +938,11 @@ h1.big_text &:last-child :margin :right 0 - +.aspect, +.requests, +.aspect_remove + :list + :style none .grey :color #999 :cursor default @@ -954,25 +952,27 @@ h1.big_text :min-height 20px :margin 0 :bottom 25px - :background - :color #efefef - :border 1px solid #ccc + + :-webkit-border-radius 10px + :-moz-border-radius 10px + :border-radius 10px + :list :style none :padding 15px + :border 2px dashed #ccc &.active :background - :color #fafafa + :color rgba(255,252,127,0.2) - .person, - .requested_person + .person :display inline-block :cursor move :z-index 10 :position relative :padding 0 - :margin 0 + :margin 5px :color #eee @@ -980,6 +980,7 @@ h1.big_text :height 70px :width 70px :border-radius 5px + :-webkit-box-shadow 0 1px 2px #999 &:hover .delete @@ -1034,6 +1035,10 @@ h1.big_text :color rgba(208,49,43,1) +.requests + ul.dropzone + :border 2px solid #ccc + ul#settings_nav :display inline :list @@ -1152,6 +1157,10 @@ header h2 :display inline + + .right + :margin + :top 10px .modal_title_bar :width 100% From a52870b21cb160ddd7d1c666f07ef000b8e04013 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 10:37:27 -0700 Subject: [PATCH 29/39] improved animations --- app/views/aspects/manage.html.haml | 26 +++++++++++------------- public/javascripts/aspect-edit.js | 13 ++++++++++-- public/stylesheets/sass/application.sass | 19 ++++++++++++----- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index c0fdacc89..06f55724a 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -18,7 +18,7 @@ .requests %ul.dropzone - if @remote_requests.size < 1 - %li.grey No new requests + %li No new requests - else - for request in @remote_requests %li.person.request{:data=>{:guid=>request.id, :person_id=>request.person.id}} @@ -27,7 +27,8 @@ %h3 Remove from Aspect .aspect_remove %ul.dropzone - %li.grey Drag to remove person from aspect + .draggable_info + Drag to remove person from aspect = render 'shared/invitations', :invites => @invites @@ -47,18 +48,15 @@ %li!= remove_link(aspect) %ul.dropzone{:data=>{:aspect_id=>aspect.id}} - - -if aspect.people.size < 1 - %li.grey Drag to add people - - -else - -for person in aspect.people - %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} - .delete - .x - X - .circle - = person_image_tag(person) + -for person in aspect.people + %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} + .delete + .x + X + .circle + = person_image_tag(person) + .draggable_info + Drag to add people diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 177701ed3..8d3268d58 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -21,8 +21,17 @@ function decrementRequestsCounter() { // Dragging person between aspects $(function() { - $("ul .person").draggable({ revert: true }); - $("ul .requested_person").draggable({ revert: true }); + $("ul .person").draggable({ + revert: true, + start: function(event,ui){ + $(this).children("img").animate({'height':80, 'width':80, 'opacity':0.8},200); + $(".draggable_info").fadeIn(100); + }, + stop: function(event,ui){ + $(this).children("img").animate({'height':70, 'width':70, 'opacity':1},200); + $(".draggable_info").fadeOut(100); + } + }); $(".aspect ul.dropzone").droppable({ hoverClass: 'active', diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index b6d6516d1..db0b32edc 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -943,12 +943,12 @@ h1.big_text .aspect_remove :list :style none - .grey - :color #999 - :cursor default - :text-shadow 0 1px #fff + :color #999 + :cursor default + :text-shadow 0 1px #fff ul.dropzone + :position relative :min-height 20px :margin 0 :bottom 25px @@ -966,6 +966,16 @@ h1.big_text :background :color rgba(255,252,127,0.2) + .draggable_info + :position absolute + :display none + :right 15px + :bottom 10px + :font + :style italic + :size 14px + :color #aaa + .person :display inline-block :cursor move @@ -991,7 +1001,6 @@ h1.big_text img :-webkit-box-shadow 0 1px 3px #000 :-moz-box-shadow 0 2px 4px #000 - :opacity 0.9 .delete :display none From 829ad6360a508a7841f5b736b203749e6bf5d037 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 12:34:01 -0700 Subject: [PATCH 30/39] multiple dropzones function. person image does not copy, delete is disabled. --- app/views/aspects/manage.html.haml | 24 ++++++-- public/javascripts/aspect-edit.js | 71 +++++++++++++++--------- public/javascripts/view.js | 1 + public/stylesheets/sass/application.sass | 71 +++++++++++++++++------- 4 files changed, 113 insertions(+), 54 deletions(-) diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 06f55724a..e067888e0 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -16,7 +16,7 @@ %h3=t('.requests') .requests - %ul.dropzone + %ul - if @remote_requests.size < 1 %li No new requests - else @@ -44,23 +44,35 @@ %span.tip click to edit %ul.tools - %li= link_to t('.add_a_new_friend'), "#add_request_pane_#{aspect.id}", :class => 'add_request_button' %li!= remove_link(aspect) - %ul.dropzone{:data=>{:aspect_id=>aspect.id}} + + %ul.people{:data=>{:aspect_id=>aspect.id}} -for person in aspect.people %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} .delete .x - X + = link_to "X", "#remove_person_pane", :class => "remove_person_button" .circle = person_image_tag(person) - .draggable_info - Drag to add people + %li.dropzone_targets + %span.dropzone.add_person + = link_to "Add person", "#add_request_pane_#{aspect.id}", :class => 'add_request_button' + %span.dropzone.move_person + = link_to "Move person", '#' .fancybox_content %div{:id => "add_request_pane_#{aspect.id}"} = render "requests/new_request", :aspect => aspect + + .fancybox_content + #remove_person_pane + .span-12.last + .modal_title_bar + %h4 Remove from aspect + + .person + diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 8d3268d58..d31d82114 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -21,48 +21,62 @@ function decrementRequestsCounter() { // Dragging person between aspects $(function() { - $("ul .person").draggable({ + $(".person").draggable({ revert: true, start: function(event,ui){ $(this).children("img").animate({'height':80, 'width':80, 'opacity':0.8},200); - $(".draggable_info").fadeIn(100); + $(".dropzone").fadeIn(100); }, stop: function(event,ui){ $(this).children("img").animate({'height':70, 'width':70, 'opacity':1},200); - $(".draggable_info").fadeOut(100); } }); - $(".aspect ul.dropzone").droppable({ + $(".dropzone", ".aspect").droppable({ hoverClass: 'active', drop: function(event, ui) { var dropzone = $(this); var person = ui.draggable; + var aspect = dropzone.closest(".aspect"); if( person.hasClass('request') ){ $.ajax({ type: "DELETE", url: "/requests/" + person.attr('data-guid'), - data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') }, + data: {"accept" : true, "aspect_id" : aspect.attr('data-guid') }, success: function(data){ decrementRequestsCounter(); } }); }; - if( dropzone.attr('data-aspect_id') != person.attr('data-aspect_id' )){ - $.ajax({ - url: "/aspects/move_friend/", - data: {"friend_id" : person.attr('data-guid'), - "from" : person.attr('data-aspect_id'), - "to" : { "to" : dropzone.attr('data-aspect_id') }}, - success: function(data){ - person.attr('data-aspect_id', dropzone.attr('data-aspect_id')); - }}); - } + if( aspect.attr('data-guid') != person.attr('data-aspect_id' )){ - $(this).closest("ul").append(person); + if( dropzone.hasClass("move_person") ){ + $.ajax({ + url: "/aspects/move_friend/", + data: {"friend_id" : person.attr('data-guid'), + "from" : person.attr('data-aspect_id'), + "to" : { "to" : aspect.attr('data-guid') }}, + success: function(data){ + person.attr('data-aspect_id', aspect.attr('data-guid')); + }}); + + $("ul.people li:last", aspect).before(person); + + } else { + $.ajax({ + url: "/aspects/add_to_aspect/", + data: {"friend_id" : person.attr('data-guid'), + "aspect_id" : aspect.attr('data-guid') }, + success: function(data){ + person.attr('data-aspect_id', aspect.attr('data-guid')); + }}); + + $("ul.people li:last", aspect).before(person); + } + } } }); @@ -87,7 +101,7 @@ $(function() { 'aspect_id' : person.attr('data-aspect_id') } }); } - person.fadeOut('slow', $(this).remove()); + person.fadeOut('slow', function(){person.remove()}); } } }); @@ -97,6 +111,7 @@ $(function() { // Person deletion + $(".delete").live("click", function() { var person = $(this).closest("li.person"); @@ -117,17 +132,19 @@ $(".delete").live("click", function() { } else { - if( confirm("Remove this person from all aspects?") ){ - var person_id = $(this).closest("li.person").attr('data-guid'); + var person_id = $(this).closest("li.person").attr('data-guid'); - $.ajax({ - type: "DELETE", - url: "/people/" + person_id, - success: function() { - person.fadeOut(200); - } - }); - } + + /* + $.ajax({ + type: "DELETE", + url: "/people/" + person_id, + success: function() { + person.fadeOut(200); + } + }); + + */ } }); diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 7e809f978..71fefc347 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -30,6 +30,7 @@ $(document).ready(function(){ $("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); + $(".remove_person_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $("input[type='submit']").addClass("button"); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index db0b32edc..4f7a48430 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -938,49 +938,71 @@ h1.big_text &:last-child :margin :right 0 + +ul#aspect_list + :list + :style none + :padding 0 + :margin 0 + .aspect, .requests, .aspect_remove - :list - :style none + :position relative :color #999 :cursor default :text-shadow 0 1px #fff - ul.dropzone - :position relative - :min-height 20px - :margin 0 - :bottom 25px + .dropzone + :display inline-block + :-webkit-border-radius 10px :-moz-border-radius 10px :border-radius 10px - :list - :style none - :padding 15px + :margin 5px :border 2px dashed #ccc + :height 70px + :max-height 70px + :width 70px + :max-width 70px + &.active :background :color rgba(255,252,127,0.2) - .draggable_info - :position absolute - :display none - :right 15px - :bottom 10px + a + :display block + :height 100% + :padding + :top 12px + :text + :align center :font - :style italic :size 14px - :color #aaa + + :color #999 + + &:hover + :color #666 + + ul + :list + :style none + :min-height 20px + :margin 0 + :bottom 25px + :padding 0 + + li + :display inline-block .person - :display inline-block :cursor move :z-index 10 - :position relative + :top 0 :padding 0 :margin 5px @@ -1034,8 +1056,15 @@ h1.big_text .x :z-index 2 :position absolute - :top 2px - :left 7px + :padding + :top 2px + :left 7px + a + :cursor default + :display block + :height 100% + :text-shadow none + :color #eee &:hover :cursor default From c0423e5e564b978073aeb1eab6981094b7439d28 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 22 Oct 2010 15:56:19 -0700 Subject: [PATCH 31/39] reverting commit manually --- app/views/aspects/manage.html.haml | 23 ++------ public/javascripts/aspect-edit.js | 70 +++++++++-------------- public/stylesheets/sass/application.sass | 71 +++++++----------------- 3 files changed, 54 insertions(+), 110 deletions(-) diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index e067888e0..8ac04b893 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -16,7 +16,7 @@ %h3=t('.requests') .requests - %ul + %ul.dropzone - if @remote_requests.size < 1 %li No new requests - else @@ -44,23 +44,20 @@ %span.tip click to edit %ul.tools + %li= link_to t('.add_a_new_friend'), "#add_request_pane_#{aspect.id}", :class => 'add_request_button' %li!= remove_link(aspect) - - %ul.people{:data=>{:aspect_id=>aspect.id}} + %ul.dropzone{:data=>{:aspect_id=>aspect.id}} -for person in aspect.people %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} .delete .x - = link_to "X", "#remove_person_pane", :class => "remove_person_button" + X .circle = person_image_tag(person) + .draggable_info + Drag to add people - %li.dropzone_targets - %span.dropzone.add_person - = link_to "Add person", "#add_request_pane_#{aspect.id}", :class => 'add_request_button' - %span.dropzone.move_person - = link_to "Move person", '#' .fancybox_content @@ -68,11 +65,3 @@ = render "requests/new_request", :aspect => aspect - .fancybox_content - #remove_person_pane - .span-12.last - .modal_title_bar - %h4 Remove from aspect - - .person - diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index d31d82114..9e565e4b2 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -21,62 +21,49 @@ function decrementRequestsCounter() { // Dragging person between aspects $(function() { - $(".person").draggable({ + $("ul .person").draggable({ revert: true, start: function(event,ui){ $(this).children("img").animate({'height':80, 'width':80, 'opacity':0.8},200); - $(".dropzone").fadeIn(100); + $(".draggable_info").fadeIn(100); }, stop: function(event,ui){ $(this).children("img").animate({'height':70, 'width':70, 'opacity':1},200); + $(".draggable_info").fadeOut(100); } }); - $(".dropzone", ".aspect").droppable({ + $(".aspect ul.dropzone").droppable({ hoverClass: 'active', drop: function(event, ui) { var dropzone = $(this); var person = ui.draggable; - var aspect = dropzone.closest(".aspect"); if( person.hasClass('request') ){ $.ajax({ type: "DELETE", url: "/requests/" + person.attr('data-guid'), - data: {"accept" : true, "aspect_id" : aspect.attr('data-guid') }, + data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') }, success: function(data){ decrementRequestsCounter(); } }); }; - if( aspect.attr('data-guid') != person.attr('data-aspect_id' )){ - if( dropzone.hasClass("move_person") ){ - $.ajax({ - url: "/aspects/move_friend/", - data: {"friend_id" : person.attr('data-guid'), - "from" : person.attr('data-aspect_id'), - "to" : { "to" : aspect.attr('data-guid') }}, - success: function(data){ - person.attr('data-aspect_id', aspect.attr('data-guid')); - }}); - - $("ul.people li:last", aspect).before(person); - - } else { - $.ajax({ - url: "/aspects/add_to_aspect/", - data: {"friend_id" : person.attr('data-guid'), - "aspect_id" : aspect.attr('data-guid') }, - success: function(data){ - person.attr('data-aspect_id', aspect.attr('data-guid')); - }}); - - $("ul.people li:last", aspect).before(person); + if( dropzone.attr('data-aspect_id') != person.attr('data-aspect_id' )){ + $.ajax({ + url: "/aspects/move_friend/", + data: {"friend_id" : person.attr('data-guid'), + "from" : person.attr('data-aspect_id'), + "to" : { "to" : dropzone.attr('data-aspect_id') }}, + success: function(data){ + person.attr('data-aspect_id', dropzone.attr('data-aspect_id')); + }}); } - } + + $(this).closest("ul").append(person); } }); @@ -101,7 +88,7 @@ $(function() { 'aspect_id' : person.attr('data-aspect_id') } }); } - person.fadeOut('slow', function(){person.remove()}); + person.fadeOut('slow', $(this).remove()); } } }); @@ -111,7 +98,6 @@ $(function() { // Person deletion - $(".delete").live("click", function() { var person = $(this).closest("li.person"); @@ -132,19 +118,17 @@ $(".delete").live("click", function() { } else { - var person_id = $(this).closest("li.person").attr('data-guid'); + if( confirm("Remove this person from all aspects?") ){ + var person_id = $(this).closest("li.person").attr('data-guid'); - - /* - $.ajax({ - type: "DELETE", - url: "/people/" + person_id, - success: function() { - person.fadeOut(200); - } - }); - - */ + $.ajax({ + type: "DELETE", + url: "/people/" + person_id, + success: function() { + person.fadeOut(200); + } + }); + } } }); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 4f7a48430..db0b32edc 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -938,71 +938,49 @@ h1.big_text &:last-child :margin :right 0 - -ul#aspect_list - :list - :style none - :padding 0 - :margin 0 - .aspect, .requests, .aspect_remove - :position relative + :list + :style none :color #999 :cursor default :text-shadow 0 1px #fff + ul.dropzone + :position relative + :min-height 20px + :margin 0 + :bottom 25px - .dropzone - :display inline-block - :-webkit-border-radius 10px :-moz-border-radius 10px :border-radius 10px - :margin 5px + :list + :style none + :padding 15px :border 2px dashed #ccc - :height 70px - :max-height 70px - :width 70px - :max-width 70px - &.active :background :color rgba(255,252,127,0.2) - a - :display block - :height 100% - :padding - :top 12px - :text - :align center + .draggable_info + :position absolute + :display none + :right 15px + :bottom 10px :font + :style italic :size 14px - - :color #999 - - &:hover - :color #666 - - ul - :list - :style none - :min-height 20px - :margin 0 - :bottom 25px - :padding 0 - - li - :display inline-block + :color #aaa .person + :display inline-block :cursor move :z-index 10 - :top 0 + :position relative :padding 0 :margin 5px @@ -1056,15 +1034,8 @@ ul#aspect_list .x :z-index 2 :position absolute - :padding - :top 2px - :left 7px - a - :cursor default - :display block - :height 100% - :text-shadow none - :color #eee + :top 2px + :left 7px &:hover :cursor default From 6720fa2c598f26932fc62a607259f4e79175e262 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 16:28:03 -0700 Subject: [PATCH 32/39] added tests to make sure Person.by_webfinger only returns exact matches --- app/models/person.rb | 2 +- spec/models/person_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/person.rb b/app/models/person.rb index 211d3fcf0..5a1486653 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -97,7 +97,7 @@ class Person # Raise an error if identifier is not a valid email (generous regexp) raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/) - query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i + query = /\A^#{Regexp.escape(identifier.gsub('acct:', '').to_s)}\z/i local_person = Person.first(:diaspora_handle => query) if local_person diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 4aae4daad..6bfff0788 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -187,6 +187,25 @@ describe Person do end end + + it 'should only find people who are exact matches' do + user = Factory(:user, :username => "SaMaNtHa") + person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") + user.person.diaspora_handle = "tom@tom.joindiaspora.com" + user.person.save + Person.by_webfinger("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com" + end + + it 'should return nil if there is not an exact match' do + Redfinger.stub!(:finger).and_return(nil) + Person.stub!(:from_webfinger_profile).and_return(false) + + person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") + #Person.by_webfinger("tom@tom.joindiaspora.com").should_be false + proc{ Person.by_webfinger("tom@tom.joindiaspora.com")}.should raise_error + end + + it 'identifier should be a valid email' do stub_success("joe.valid+email@my-address.com") Proc.new { From 5af3d5fa820a9e2dc17ffae03f1fd78068cb7485 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 16:34:08 -0700 Subject: [PATCH 33/39] double checking that matches are in front or back --- spec/models/person_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 6bfff0788..fa89610af 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -198,9 +198,9 @@ describe Person do it 'should return nil if there is not an exact match' do Redfinger.stub!(:finger).and_return(nil) - Person.stub!(:from_webfinger_profile).and_return(false) person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") + person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm") #Person.by_webfinger("tom@tom.joindiaspora.com").should_be false proc{ Person.by_webfinger("tom@tom.joindiaspora.com")}.should raise_error end From b337d5acc9ab28d921ad31c23058a65994c27835 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 16:36:43 -0700 Subject: [PATCH 34/39] delivery method test in tests --- config/initializers/mailer_config.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb index 73928f740..cbc5f7330 100644 --- a/config/initializers/mailer_config.rb +++ b/config/initializers/mailer_config.rb @@ -3,15 +3,17 @@ # the COPYRIGHT file. Diaspora::Application.configure do - config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = {:host => APP_CONFIG[:terse_pod_url]} - config.action_mailer.smtp_settings = { - :address => APP_CONFIG[:smtp_address], - :port => APP_CONFIG[:smtp_port], - :domain => APP_CONFIG[:smtp_domain], - :authentication => APP_CONFIG[:smtp_authentication], - :user_name => APP_CONFIG[:smtp_username], - :password => APP_CONFIG[:smtp_password], - :enable_starttls_auto => true - } + unless Rails.env == 'test' + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + :address => APP_CONFIG[:smtp_address], + :port => APP_CONFIG[:smtp_port], + :domain => APP_CONFIG[:smtp_domain], + :authentication => APP_CONFIG[:smtp_authentication], + :user_name => APP_CONFIG[:smtp_username], + :password => APP_CONFIG[:smtp_password], + :enable_starttls_auto => true + } + end end From de04e717c0cb1ac536bbfaa160eff758c3c9aa64 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 16:57:01 -0700 Subject: [PATCH 35/39] made image or default to help with hcard parsing, deleted old default user picture --- app/helpers/application_helper.rb | 8 ++++++-- app/views/publics/hcard.erb | 6 +----- public/images/user/default.jpg | Bin 7418 -> 0 bytes 3 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 public/images/user/default.jpg diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4e9f94c24..8851f3c8e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -57,11 +57,15 @@ module ApplicationHelper end def person_image_tag(person) + image_tag image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id + end + + def image_or_default(person) image_location = person.profile.image_url image_location ||= "/images/user/default.png" - - image_tag image_location, :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id + image_location end + def person_image_link(person) link_to person_image_tag(person), object_path(person) diff --git a/app/views/publics/hcard.erb b/app/views/publics/hcard.erb index 6b8ab3209..5102897a5 100644 --- a/app/views/publics/hcard.erb +++ b/app/views/publics/hcard.erb @@ -36,13 +36,9 @@
Photo
- +
-
-
Note
-
Diaspora is awesome! vi is better than emacs!
-
diff --git a/public/images/user/default.jpg b/public/images/user/default.jpg deleted file mode 100644 index b242c1e1c3ce1c06b7452a2fc93f74c05dea1950..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7418 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 From 096a0308e1270f22cbde4a77b1468fd4b534f012 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 17:12:28 -0700 Subject: [PATCH 36/39] update attachment with emails --- app/mailers/notifier.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index f360f2a6f..95cdff86f 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -1,10 +1,11 @@ class Notifier < ActionMailer::Base default :from => "no-reply@joindiaspora.com" - + ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_caps.png") + def new_request(recipient, sender) @receiver = recipient @sender = sender - attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png") + attachments["diaspora_white.png"] = ATTACHMENT mail(:to => "#{recipient.real_name} <#{recipient.email}>", :subject => "new Diaspora* friend request from #{@sender.real_name}", :host => APP_CONFIG[:terse_pod_url]) @@ -14,7 +15,7 @@ class Notifier < ActionMailer::Base @receiver = recipient @sender = sender @aspect = aspect - attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png") + attachments["diaspora_white.png"] = ATTACHMENT mail(:to => "#{recipient.real_name} <#{recipient.email}>", :subject => "#{@sender.real_name} has accepted your friend request on Diaspora*", :host => APP_CONFIG[:terse_pod_url]) end From 6913381781fd9b27e63129e728e8ff6defd537f0 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 17:26:10 -0700 Subject: [PATCH 37/39] username now can only contain letters numbers, periods, and underscores --- app/models/user.rb | 3 +-- spec/models/user_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 273cc209b..343cc2d76 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,8 +43,7 @@ class User before_validation :strip_username, :on => :create validates_presence_of :username validates_uniqueness_of :username, :case_sensitive => false - validates_format_of :username, :without => /\s/ - + validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/ validates_with InvitedUserValidator one :person, :class_name => 'Person', :foreign_key => :owner_id diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ed3008b84..351d5347c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -73,6 +73,11 @@ describe User do user = Factory.build(:user, :username => "bobby tables") user.should_not be_valid end + + it 'can not contain non url safe characters' do + user = Factory.build(:user, :username => "kittens;") + user.should_not be_valid + end end describe "of email" do From 606a6bb43a07394227e96e9460d8001bd4c63587 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 17:42:59 -0700 Subject: [PATCH 38/39] status message length is limited to 1000 chars. --- app/models/status_message.rb | 3 ++- spec/models/status_message_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 1c167706e..093316659 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -3,7 +3,8 @@ # the COPYRIGHT file. class StatusMessage < Post - + + validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters" xml_name :status_message xml_accessor :message diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 8449b964c..086d66e80 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -21,6 +21,15 @@ describe StatusMessage do status = @user.post(:status_message, :message => "Users do things", :to => @aspect.id) end + it 'should require status messages to be less than 1000 characters' do + message = '' + 1001.times do message = message +'1';end + status = Factory.build(:status_message, :message => message) + + status.should_not be_valid + + end + describe "XML" do it 'should serialize to XML' do message = Factory.create(:status_message, :message => "I hate WALRUSES!", :person => @user.person) From a60287348d265400cff2a93dbd0d74d62521be7c Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 19:13:35 -0700 Subject: [PATCH 39/39] not overwriting app config if it already exists --- db/seeds/backer.rb | 3 ++- db/seeds/dev.rb | 4 +++- db/seeds/tom.rb | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/db/seeds/backer.rb b/db/seeds/backer.rb index 877ffc13f..269772f51 100644 --- a/db/seeds/backer.rb +++ b/db/seeds/backer.rb @@ -13,7 +13,8 @@ def create #set pod url username = backer_info[backer_number]['username'].gsub(/ /,'').downcase - set_app_config username + set_app_config username unless File.exists?(Rails.root.join('config', 'app_config.yml')) + require File.join(File.dirname(__FILE__), "..", "..", "config", "initializers", "_load_app_config.rb") # Create seed user diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index 33f773613..324cf47bd 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -15,7 +15,9 @@ def set_app_config username end username = "tom" -set_app_config username +set_app_config username unless File.exists?(Rails.root.join('config', 'app_config.yml')) + +require Rails.root.join('config', "initializers", "_load_app_config.rb") # Create seed user user = User.build( :email => "tom@tom.joindiaspora.com", diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index f4c453d81..fe45e2dd0 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -14,7 +14,8 @@ def set_app_config username file.close end -set_app_config "tom" +set_app_config "tom" unless File.exists?(Rails.root.join('config', 'app_config.yml')) + require 'config/initializers/_load_app_config.rb' # Create seed user