diff --git a/app/models/comment.rb b/app/models/comment.rb index da4f0a6f7..1fac00c8d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -29,6 +29,8 @@ class Comment < ActiveRecord::Base has_many :reports, as: :item + has_one :signature, class_name: "CommentSignature", dependent: :delete + scope :including_author, -> { includes(:author => :profile) } scope :for_a_stream, -> { including_author.merge(order('created_at ASC')) } diff --git a/app/models/comment_signature.rb b/app/models/comment_signature.rb new file mode 100644 index 000000000..357bcb3b8 --- /dev/null +++ b/app/models/comment_signature.rb @@ -0,0 +1,7 @@ +class CommentSignature < ActiveRecord::Base + include Diaspora::Signature + + self.primary_key = :comment_id + belongs_to :comment + validates :comment, presence: true +end diff --git a/app/models/like.rb b/app/models/like.rb index c04fe7fc8..78eb9c3da 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -10,6 +10,8 @@ class Like < ActiveRecord::Base include Diaspora::Relayable + has_one :signature, class_name: "LikeSignature", dependent: :delete + alias_attribute :parent, :target class Generator < Diaspora::Federated::Generator diff --git a/app/models/like_signature.rb b/app/models/like_signature.rb new file mode 100644 index 000000000..6978704a9 --- /dev/null +++ b/app/models/like_signature.rb @@ -0,0 +1,7 @@ +class LikeSignature < ActiveRecord::Base + include Diaspora::Signature + + self.primary_key = :like_id + belongs_to :like + validates :like, presence: true +end diff --git a/app/models/poll_participation.rb b/app/models/poll_participation.rb index 67494e11d..8dba27465 100644 --- a/app/models/poll_participation.rb +++ b/app/models/poll_participation.rb @@ -7,6 +7,8 @@ class PollParticipation < ActiveRecord::Base belongs_to :poll belongs_to :poll_answer, counter_cache: :vote_count + has_one :signature, class_name: "PollParticipationSignature", dependent: :delete + alias_attribute :parent, :poll validates :poll_answer, presence: true diff --git a/app/models/poll_participation_signature.rb b/app/models/poll_participation_signature.rb new file mode 100644 index 000000000..90701f286 --- /dev/null +++ b/app/models/poll_participation_signature.rb @@ -0,0 +1,7 @@ +class PollParticipationSignature < ActiveRecord::Base + include Diaspora::Signature + + self.primary_key = :poll_participation_id + belongs_to :poll_participation + validates :poll_participation, presence: true +end diff --git a/app/models/signature_order.rb b/app/models/signature_order.rb new file mode 100644 index 000000000..83cbfb51a --- /dev/null +++ b/app/models/signature_order.rb @@ -0,0 +1,3 @@ +class SignatureOrder < ActiveRecord::Base + validates :order, presence: true, uniqueness: true +end diff --git a/lib/diaspora/signature.rb b/lib/diaspora/signature.rb new file mode 100644 index 000000000..e2b49caef --- /dev/null +++ b/lib/diaspora/signature.rb @@ -0,0 +1,14 @@ +module Diaspora + module Signature + def self.included(model) + model.class_eval do + belongs_to :signature_order + validates :signature_order, presence: true + + validates :author_signature, presence: true + + serialize :additional_data, Hash + end + end + end +end