Move initialize_signatures method out of user and into relayable

This commit is contained in:
Raphael Sofaer 2011-06-01 16:42:15 -07:00
parent df04b59857
commit 283e376712
4 changed files with 16 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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 ########

View file

@ -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