DG IZ; post user refs started (permissions)
This commit is contained in:
parent
b3d8f59c77
commit
b5594ad6bc
4 changed files with 67 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ class Post
|
|||
xml_accessor :person, :as => Person
|
||||
|
||||
key :person_id, ObjectId
|
||||
key :user_refs, Integer, :default => 0
|
||||
|
||||
many :comments, :class_name => 'Comment', :foreign_key => :post_id
|
||||
belongs_to :person, :class_name => 'Person'
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ class User
|
|||
|
||||
key :friend_ids, Array
|
||||
key :pending_request_ids, Array
|
||||
key :post_ids, Array
|
||||
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
|
||||
many :friends, :in => :friend_ids, :class_name => 'Person'
|
||||
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
|
||||
many :posts, :in => :post_ids, :class_name => 'Post'
|
||||
|
||||
many :groups, :class_name => 'Group'
|
||||
|
||||
|
|
@ -110,9 +112,25 @@ class User
|
|||
end
|
||||
|
||||
def remove_friend(bad_friend)
|
||||
puts "YEAHH!!"
|
||||
raise "Friend not deleted" unless self.friend_ids.delete( bad_friend.id )
|
||||
groups.each{|g| g.person_ids.delete( bad_friend.id )}
|
||||
self.save
|
||||
|
||||
puts self.posts.find_all_by_person_id( bad_friend.id ).inspect
|
||||
self.posts.find_all_by_person_id( bad_friend.id ).each{|post|
|
||||
puts "HEYYYYYYYY"
|
||||
|
||||
self.post_ids.delete( post.id )
|
||||
puts self.posts
|
||||
post.user_refs =- 1
|
||||
|
||||
puts "ASODIJ"
|
||||
(post.user_refs > 0 || post.person.owner.nil? == false) ? post.save : post.destroy
|
||||
}
|
||||
puts self.inspect
|
||||
self.save
|
||||
|
||||
bad_friend.user_refs -= 1
|
||||
(bad_friend.user_refs > 0 || bad_friend.owner.nil? == false) ? bad_friend.save : bad_friend.destroy
|
||||
end
|
||||
|
|
@ -170,6 +188,19 @@ class User
|
|||
person = Diaspora::Parser.owner_id_from_xml xml
|
||||
person.profile = object
|
||||
person.save
|
||||
|
||||
|
||||
elsif object.is_a?(Post) && object.verify_creator_signature == true
|
||||
Rails.logger.debug("Saving post: #{object}")
|
||||
object.save
|
||||
self.posts << object
|
||||
self.save
|
||||
object.socket_to_uid(id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
|
||||
dispatch_comment object if object.is_a?(Comment) && !owns?(object)
|
||||
|
||||
|
||||
|
||||
|
||||
elsif object.verify_creator_signature == true
|
||||
Rails.logger.debug("Saving object: #{object}")
|
||||
object.save
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ describe Diaspora::Parser do
|
|||
|
||||
status_message = Factory.build(:status_message, :message => "hey!", :person => @person)
|
||||
@user.receive status_message.to_diaspora_xml
|
||||
|
||||
@user.posts.count.should == 1
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,7 @@ describe User do
|
|||
Request.count.should == 0
|
||||
end
|
||||
|
||||
it 'should not be able to friend request an existing friend' do
|
||||
friend = Factory.create(:person)
|
||||
it 'should not be able to friend request an existing friend' do friend = Factory.create(:person)
|
||||
|
||||
@user.friends << friend
|
||||
@user.save
|
||||
|
|
@ -272,4 +271,37 @@ describe User do
|
|||
@group2.people.count.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'post refs' do
|
||||
before do
|
||||
@user2 = Factory.create(:user)
|
||||
end
|
||||
|
||||
it 'should be removed on unfriending' do
|
||||
@user.activate_friend( @user2.person, @group)
|
||||
|
||||
@user.posts.count.should == 0
|
||||
|
||||
status_message = @user2.post :status_message, :message => "hi"
|
||||
@user.receive status_message.to_diaspora_xml
|
||||
|
||||
|
||||
@user.posts.count.should == 1
|
||||
|
||||
@user.reload
|
||||
|
||||
@user.posts.count.should == 1
|
||||
|
||||
@user.unfriend(@user2.person)
|
||||
|
||||
puts @user.inspect
|
||||
@user.reload
|
||||
puts @user.inspect
|
||||
@user.posts.count.should == 0
|
||||
|
||||
puts Post.all.inspect
|
||||
Post.count.should be 1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue