Sha256: b3506b2082c3a7cb55f0e48e4c5fbc5972245ab037a118902a4dc41ec0489d9a

Contents?: true

Size: 1.72 KB

Versions: 28

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Comments
    # Shared behaviour for commentable models.
    module Commentable
      extend ActiveSupport::Concern

      included do
        has_many :comment_threads, as: :root_commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment"
        has_many :comments, as: :commentable, foreign_key: "decidim_root_commentable_id", foreign_type: "decidim_root_commentable_type", class_name: "Decidim::Comments::Comment"

        # Public: Whether the object's comments are visible or not.
        def commentable?
          true
        end

        # Public: Whether the object can have new comments or not.
        def accepts_new_comments?
          true
        end

        # Public: Whether the object's comments can have alignment or not. It enables the
        # alignment selector in the add new comment form.
        def comments_have_alignment?
          false
        end

        # Public: Whether the object's comments can have have votes or not. It enables the
        # upvote and downvote buttons for comments.
        def comments_have_votes?
          false
        end

        # Public: Identifies the commentable type in the API.
        def commentable_type
          self.class.name
        end

        # Public: Defines which users will receive a notification when a comment is created.
        # This method can be overridden at each resource model to include or exclude
        # other users, eg. admins.
        # Returns: a relation of Decidim::User objects.
        def users_to_notify_on_comment_created
          Decidim::User.none
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-comments-0.17.2 lib/decidim/comments/commentable.rb
decidim-comments-0.17.1 lib/decidim/comments/commentable.rb
decidim-comments-0.16.1 lib/decidim/comments/commentable.rb
decidim-comments-0.17.0 lib/decidim/comments/commentable.rb
decidim-comments-0.16.0 lib/decidim/comments/commentable.rb
decidim-comments-0.15.2 lib/decidim/comments/commentable.rb
decidim-comments-0.15.1 lib/decidim/comments/commentable.rb
decidim-comments-0.15.0 lib/decidim/comments/commentable.rb
decidim-comments-0.14.4 lib/decidim/comments/commentable.rb
decidim-comments-0.14.3 lib/decidim/comments/commentable.rb
decidim-comments-0.14.2 lib/decidim/comments/commentable.rb
decidim-comments-0.14.1 lib/decidim/comments/commentable.rb
decidim-comments-0.13.1 lib/decidim/comments/commentable.rb
decidim-comments-0.12.2 lib/decidim/comments/commentable.rb
decidim-comments-0.13.0 lib/decidim/comments/commentable.rb
decidim-comments-0.12.1 lib/decidim/comments/commentable.rb
decidim-comments-0.13.0.pre1 lib/decidim/comments/commentable.rb
decidim-comments-0.12.0 lib/decidim/comments/commentable.rb
decidim-comments-0.11.2 lib/decidim/comments/commentable.rb
decidim-comments-0.12.0.pre lib/decidim/comments/commentable.rb