add models for signature data

This commit is contained in:
Benjamin Neff 2016-07-18 22:41:17 +02:00
parent 5f3e4fc358
commit 081d0167b7
8 changed files with 44 additions and 0 deletions

View file

@ -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')) }

View file

@ -0,0 +1,7 @@
class CommentSignature < ActiveRecord::Base
include Diaspora::Signature
self.primary_key = :comment_id
belongs_to :comment
validates :comment, presence: true
end

View file

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

View file

@ -0,0 +1,7 @@
class LikeSignature < ActiveRecord::Base
include Diaspora::Signature
self.primary_key = :like_id
belongs_to :like
validates :like, presence: true
end

View file

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

View file

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

View file

@ -0,0 +1,3 @@
class SignatureOrder < ActiveRecord::Base
validates :order, presence: true, uniqueness: true
end

14
lib/diaspora/signature.rb Normal file
View file

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