diaspora/app/models/comment.rb

74 lines
1.9 KiB
Ruby

# Copyright 2010 Diaspora Inc.
#
# This file is part of Diaspora.
#
# Diaspora is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diaspora is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Diaspora. If not, see <http://www.gnu.org/licenses/>.
#
class Comment
include MongoMapper::Document
include ROXML
include Diaspora::Webhooks
include Encryptable
include Diaspora::Socketable
xml_accessor :text
xml_accessor :person, :as => Person
xml_accessor :post_id
xml_accessor :_id
key :text, String
key :post_id, ObjectId
key :person_id, ObjectId
belongs_to :post, :class_name => "Post"
belongs_to :person, :class_name => "Person"
validates_presence_of :text
timestamps!
#ENCRYPTION
xml_accessor :creator_signature
xml_accessor :post_creator_signature
key :creator_signature, String
key :post_creator_signature, String
def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition|
definition.accessor}
accessors.delete 'person'
accessors.delete 'creator_signature'
accessors.delete 'post_creator_signature'
accessors
end
def signable_string
signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';'
end
def verify_post_creator_signature
verify_signature(post_creator_signature, post.person)
end
def signature_valid?
verify_signature(creator_signature, person)
end
end