Sha256: 351f263608337e1c2e405c96ed12fbb7cc23955f0ffd44c0297868002a02a342

Contents?: true

Size: 895 Bytes

Versions: 61

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # A comment can include user votes. A user should be able to upVote, votes with
    # weight 1 and downVote, votes with weight -1.
    class CommentVote < ApplicationRecord
      belongs_to :comment, foreign_key: "decidim_comment_id", class_name: "Comment"
      belongs_to :author, foreign_key: "decidim_author_id", class_name: "Decidim::User"

      validates :comment, uniqueness: { scope: :author }
      validates :weight, inclusion: { in: [-1, 1] }
      validate :author_and_comment_same_organization

      private

      # Private: check if the comment and the author have the same organization
      def author_and_comment_same_organization
        return unless author.present? && comment.present?
        errors.add(:comment, :invalid) unless author.organization == comment.organization
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 2 rubygems

Version Path
decidim-comments-0.12.2 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.12.1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.12.0 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.11.2 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.12.0.pre app/models/decidim/comments/comment_vote.rb
decidim-comments-0.11.1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.11.0.pre1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.10.1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.10.0 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.9.3 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.9.2 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.9.1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.9.0 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.8.4 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.8.3 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.8.2 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.8.1 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.8.0 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.7.4 app/models/decidim/comments/comment_vote.rb
decidim-comments-0.7.3 app/models/decidim/comments/comment_vote.rb