From 283e376712a7dd6f9ec2a63364b8aee4cc31fb3a Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 1 Jun 2011 16:42:15 -0700 Subject: [PATCH] Move initialize_signatures method out of user and into relayable --- app/models/comment.rb | 2 +- app/models/like.rb | 2 +- app/models/user.rb | 16 ++++------------ lib/diaspora/relayable.rb | 10 ++++++++++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index e3084553f..f0d829dd4 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -9,8 +9,8 @@ class Comment < ActiveRecord::Base include ROXML include Diaspora::Webhooks - include Diaspora::Relayable include Diaspora::Guid + include Diaspora::Relayable include Diaspora::Socketable diff --git a/app/models/like.rb b/app/models/like.rb index baf4b0ff0..156775e44 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -7,8 +7,8 @@ class Like < ActiveRecord::Base include ROXML include Diaspora::Webhooks - include Diaspora::Relayable include Diaspora::Guid + include Diaspora::Relayable include Diaspora::Socketable diff --git a/app/models/user.rb b/app/models/user.rb index bd7da1297..c7184d3ec 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -154,18 +154,10 @@ class User < ActiveRecord::Base end def build_relayable(model, options = {}) - m = model.new(options.merge(:author_id => self.person.id)) - m.set_guid - - #sign relayable as model creator - m.author_signature = m.sign_with_key(self.encryption_key) - - if !m.post_id.blank? && person.owns?(m.parent) - #sign relayable as parent object owner - m.parent_author_signature = m.sign_with_key(self.encryption_key) - end - - m + r = model.new(options.merge(:author_id => self.person.id)) + r.set_guid + r.initialize_signatures + r end ######## Commenting ######## diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 44798d242..d92a87ab8 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -64,6 +64,16 @@ module Diaspora self end + def initialize_signatures + #sign relayable as model creator + self.author_signature = self.sign_with_key(author.owner.encryption_key) + + if !self.post_id.blank? && self.author.owns?(self.parent) + #sign relayable as parent object owner + self.parent_author_signature = sign_with_key(author.owner.encryption_key) + end + end + def verify_parent_author_signature verify_signature(self.parent_author_signature, self.parent.author) end