From 36f82895226c6c2c0d8e6dad6c3e5ace0cf03afc Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 10:03:37 -0700 Subject: [PATCH 1/8] Fixing retractions on albums, adding back remove_from_view --- app/models/album.rb | 2 +- app/models/person.rb | 3 ++- app/models/user.rb | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/album.rb b/app/models/album.rb index 7b9a746aa..b6daabb47 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -67,6 +67,6 @@ class Album end def propagate_retraction - Retraction.for(self).notify_people + self.person.owner.retract(self) end end diff --git a/app/models/person.rb b/app/models/person.rb index f966a4070..26236a5b8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -25,7 +25,7 @@ class Person timestamps! - after_destroy :remove_all_traces + before_destroy :remove_all_traces before_validation :clean_url validates_presence_of :email, :url, :profile, :serialized_key validates_format_of :url, :with => @@ -92,5 +92,6 @@ class Person private def remove_all_traces Post.all(:person_id => id).each{|p| p.delete} + Album.all(:person_id => id).each{|p| p.delete} end end diff --git a/app/models/user.rb b/app/models/user.rb index 12067eee7..d65114f42 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,7 @@ class User ######### Posts and Such ############### def retract( post ) + post.socket_to_uid(self.id) retraction = Retraction.for(post) retraction.creator_signature = retraction.sign_with_key( encryption_key ) retraction.notify_people @@ -258,7 +259,7 @@ class User self.save groups = groups_with_person(object.person) - object.socket_to_uid(id, :group_id => groups.first.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) + object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) end end From 9a188fd9f085cc59e93975d8dbea99da1d446540 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 10:08:38 -0700 Subject: [PATCH 2/8] Don't try to unsocket albums --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index d65114f42..0cebe4748 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,7 +91,7 @@ class User ######### Posts and Such ############### def retract( post ) - post.socket_to_uid(self.id) + post.unsocket_from_uid(self.id) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) retraction.creator_signature = retraction.sign_with_key( encryption_key ) retraction.notify_people From 045878de64b9f609f241a8e710ef6f437f7f25e3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 10:12:22 -0700 Subject: [PATCH 3/8] call ensure_bson once in visible_person_by_id and group_by_id --- app/models/user.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0cebe4748..aa2973acb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,12 +282,14 @@ class User end def visible_person_by_id( id ) - return self.person if ensure_bson(id) == self.person.id - friends.detect{|x| x.id == ensure_bson( id ) } + id = ensure_bson id + return self.person if id == self.person.id + friends.detect{|x| x.id == id } end def group_by_id( id ) - groups.detect{|x| x.id == ensure_bson( id ) } + id = ensure_bson id + groups.detect{|x| x.id == id } end def groups_with_person person From d640c0672f8c333ce913862e8a3097516c739b57 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 10:56:09 -0700 Subject: [PATCH 4/8] switch deploy branch to actually be one we are working on --- app/models/album.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/album.rb b/app/models/album.rb index b6daabb47..b30cb5c45 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -27,6 +27,7 @@ class Album def self.mine_or_friends(friend_param, current_user) if friend_param + puts "i am working" Album.find_all_by_person_id(current_user.friend_ids) else current_user.person.albums From 10aef7a0a3fabcd6cf21bf833dfa77cb97e59338 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 11:46:28 -0700 Subject: [PATCH 5/8] Begin rescue on publics controller to make the post for nonexistent user error more readable --- app/controllers/publics_controller.rb | 6 +++++- spec/models/album_spec.rb | 3 --- spec/models/user/receive_spec.rb | 12 ++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 91edf995d..e7ab1ea1b 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -22,7 +22,11 @@ class PublicsController < ApplicationController end def receive - @user = Person.first(:id => params[:id]).owner + begin + @user = Person.first(:id => params[:id]).owner + rescue NoMethodError => e + Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id}") + end Rails.logger.debug "PublicsController has received: #{params[:xml]}" @user.receive params[:xml] if params[:xml] render :nothing => true diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index f5038ec1c..e31dc5e4a 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -88,8 +88,5 @@ describe Album do it 'should have an id' do @xml.include?(@album.id.to_s).should be true end - end - - end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 4919e66f4..a657f41e8 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -25,6 +25,18 @@ describe User do Post.all(:person_id => person.id).first.message.should == 'store this!' StatusMessage.all.size.should == 1 end + + it 'should not create new groups on message receive' do + num_groups = @user.groups.size + + (0..5).each{ |n| + status_message = @user2.post :status_message, :message => "store this #{n}!" + xml = status_message.to_diaspora_xml + @user.receive( xml ) + } + + @user.groups.size.should == num_groups + end describe 'post refs' do before do From 4cd46abaac8eb436f0db5df08a8c5f9f46a6791c Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 11:48:32 -0700 Subject: [PATCH 6/8] render nothing at the top --- app/controllers/publics_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index e7ab1ea1b..0d6df2933 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -22,14 +22,15 @@ class PublicsController < ApplicationController end def receive + render :nothing => true begin @user = Person.first(:id => params[:id]).owner rescue NoMethodError => e Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id}") + return end Rails.logger.debug "PublicsController has received: #{params[:xml]}" @user.receive params[:xml] if params[:xml] - render :nothing => true end end From b7d648e1731d76029f2693e562ea9c07d456e97b Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 11:54:44 -0700 Subject: [PATCH 7/8] Validate presence of name on group --- app/controllers/publics_controller.rb | 2 +- app/models/group.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 0d6df2933..e7b994ff5 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -26,7 +26,7 @@ class PublicsController < ApplicationController begin @user = Person.first(:id => params[:id]).owner rescue NoMethodError => e - Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id}") + Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id]}") return end Rails.logger.debug "PublicsController has received: #{params[:xml]}" diff --git a/app/models/group.rb b/app/models/group.rb index 0f40d6d9b..0ff534bea 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,6 +2,7 @@ class Group include MongoMapper::Document key :name, String + validates_presence_of :name key :person_ids, Array key :request_ids, Array From 5e439bdb28abe3cd8248beca9e6cedeff0c8dd0e Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Aug 2010 11:56:11 -0700 Subject: [PATCH 8/8] Ensure_bson on groups_with_person --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index aa2973acb..e59000732 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -293,7 +293,8 @@ class User end def groups_with_person person - groups.select {|group| group.person_ids.include? person.id} + id = ensure_bson person.id + groups.select {|group| group.person_ids.include? id} end protected