diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 91edf995d..e7b994ff5 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -22,10 +22,15 @@ class PublicsController < ApplicationController end def receive - @user = Person.first(:id => params[:id]).owner + 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 diff --git a/app/models/album.rb b/app/models/album.rb index 7b9a746aa..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 @@ -67,6 +68,6 @@ class Album end def propagate_retraction - Retraction.for(self).notify_people + self.person.owner.retract(self) end end diff --git a/app/models/group.rb b/app/models/group.rb index 6b8f18921..275bbf3a5 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 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 210714fcd..012e6c923 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -101,6 +101,7 @@ class User ######### Posts and Such ############### def retract( post ) + 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 @@ -273,7 +274,7 @@ class User } 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 @@ -296,16 +297,19 @@ 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 - groups.select {|group| group.person_ids.include? person.id} + id = ensure_bson person.id + groups.select {|group| group.person_ids.include? id} end protected 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