DG MS; put validates_associated in relayable, removed from receiver logic
This commit is contained in:
parent
5177e5b218
commit
0ab0526cd6
8 changed files with 20 additions and 26 deletions
|
|
@ -27,7 +27,7 @@ class Comment < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
validates :text, :presence => true, :length => { :maximum => 2500 }
|
||||
validates :post, :presence => true
|
||||
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
|
||||
|
||||
serialize :youtube_titles, Hash
|
||||
|
||||
|
|
@ -56,23 +56,15 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def notification_type(user, person)
|
||||
if user.owns?(self.post)
|
||||
if self.post.author == user.person
|
||||
return Notifications::CommentOnPost
|
||||
elsif user_has_commented_on_others_post?(person, self.post, user)
|
||||
elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id
|
||||
return Notifications::AlsoCommented
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def user_has_commented_on_others_post?(author, post, user)
|
||||
Comment.comments_by_author_on_post_exist?(author, post.id) && self.author_id != user.person.id
|
||||
end
|
||||
|
||||
def self.comments_by_author_on_post_exist?(author, post_id)
|
||||
Comment.exists?(:author_id => author.id, :post_id => post_id)
|
||||
end
|
||||
|
||||
def parent_class
|
||||
Post
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ class Like < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
|
||||
validates :author, :presence => true
|
||||
validates :target, :presence => true
|
||||
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
|
||||
|
||||
after_create do
|
||||
self.parent.update_likes_counter
|
||||
|
|
|
|||
|
|
@ -15,21 +15,20 @@ class Message < ActiveRecord::Base
|
|||
belongs_to :conversation, :touch => true
|
||||
|
||||
validates :text, :presence => true
|
||||
validate :participant_of_parent_conversation
|
||||
|
||||
after_create do
|
||||
#sign comment as commenter
|
||||
self.author_signature = self.sign_with_key(self.author.owner.encryption_key) if self.author.owner
|
||||
|
||||
if !self.parent.blank? && self.author.owns?(self.parent)
|
||||
if self.author.owns?(self.parent)
|
||||
#sign comment as post owner
|
||||
self.parent_author_signature = self.sign_with_key( self.parent.author.owner.encryption_key) if self.parent.author.owner
|
||||
self.parent_author_signature = self.sign_with_key(self.parent.author.owner.encryption_key) if self.parent.author.owner
|
||||
end
|
||||
self.save!
|
||||
self
|
||||
end
|
||||
|
||||
validate :participant_of_parent_conversation
|
||||
|
||||
def diaspora_handle
|
||||
self.author.diaspora_handle
|
||||
end
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class Person < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def owns?(obj)
|
||||
self == obj.author
|
||||
self.id == obj.author_id
|
||||
end
|
||||
|
||||
def url
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ module Diaspora
|
|||
xml_attr :parent_guid
|
||||
xml_attr :parent_author_signature
|
||||
xml_attr :author_signature
|
||||
|
||||
validates_associated :parent
|
||||
validates :author, :presence => true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ module Postzord
|
|||
end
|
||||
|
||||
def receive_relayable
|
||||
# unless @object.parent.present?
|
||||
# raise RelayableObjectWithoutParent.new("Receiving a relayable object without parent object present locally!")
|
||||
# end
|
||||
|
||||
if @object.parent.author.local?
|
||||
# receive relayable object only for the owner of the parent object
|
||||
@object.receive(@object.parent.author.user, @author)
|
||||
|
|
@ -50,7 +46,6 @@ module Postzord
|
|||
@object.save!
|
||||
end
|
||||
|
||||
|
||||
# @return [Array<Integer>] User ids
|
||||
def recipient_user_ids
|
||||
User.all_sharing_with_person(@author).select('users.id').map!{ |u| u.id }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ describe Message do
|
|||
:messages_attributes => [ {:author => @user1.person, :text => 'stuff'} ]
|
||||
}
|
||||
|
||||
@cnv = Conversation.create(@create_hash)
|
||||
@cnv = Conversation.create!(@create_hash)
|
||||
@message = @cnv.messages.first
|
||||
@xml = @message.to_diaspora_xml
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@ require 'spec_helper'
|
|||
|
||||
describe Diaspora::Relayable do
|
||||
shared_examples_for "it is relayable" do
|
||||
|
||||
context 'validation' do
|
||||
it 'ensures an valid associated parent'
|
||||
it 'ensures the presence of an author'
|
||||
end
|
||||
|
||||
context 'encryption' do
|
||||
describe '#parent_author_signature' do
|
||||
it 'should sign the object if the user is the post author' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue