Sha256: bfe743eff6cdaf529d26ea73389ec1baa007fe5a0f9847f56bc761b9a4c12aa3

Contents?: true

Size: 1.54 KB

Versions: 28

Compression:

Stored size: 1.54 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 :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_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 & 2 rubygems

Version Path
decidim-comments-0.8.4 lib/decidim/comments/commentable.rb
decidim-comments-0.8.3 lib/decidim/comments/commentable.rb
decidim-comments-0.8.2 lib/decidim/comments/commentable.rb
decidim-comments-0.8.1 lib/decidim/comments/commentable.rb
decidim-comments-0.8.0 lib/decidim/comments/commentable.rb
decidim-comments-0.7.4 lib/decidim/comments/commentable.rb
decidim-comments-0.7.3 lib/decidim/comments/commentable.rb
decidim-comments-0.7.2 lib/decidim/comments/commentable.rb
decidim-comments-0.7.1 lib/decidim/comments/commentable.rb
decidim-comments-0.7.0 lib/decidim/comments/commentable.rb
decidim-comments-0.6.8 lib/decidim/comments/commentable.rb
decidim-0.6.8 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.6.7 lib/decidim/comments/commentable.rb
decidim-0.6.7 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.6.6 lib/decidim/comments/commentable.rb
decidim-0.6.6 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.6.5 lib/decidim/comments/commentable.rb
decidim-0.6.5 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.6.4 lib/decidim/comments/commentable.rb
decidim-0.6.4 decidim-comments/lib/decidim/comments/commentable.rb