Sha256: baa2f19d66e163aea413c8d42c2db66e95eb2ec34a7825004efc252bbc58757b

Contents?: true

Size: 1005 Bytes

Versions: 44

Compression:

Stored size: 1005 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Comments
    # Commentable overriding some methods to include settings and
    # authorizations given by a component the resource belongs to
    module CommentableWithComponent
      extend ActiveSupport::Concern
      include Decidim::Comments::Commentable

      included do
        # Public: Overrides the `commentable?` Commentable concern method.
        def commentable?
          component.settings.comments_enabled?
        end

        # Public: Overrides the `accepts_new_comments?` Commentable concern method.
        def accepts_new_comments?
          commentable? && !component.current_settings.comments_blocked
        end

        # Public: Whether the object can have new comments or not.
        def user_allowed_to_comment?(user)
          return unless can_participate?(user)

          ActionAuthorizer.new(user, "comment", component, self).authorize.ok?
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-comments-0.25.0.rc4 lib/decidim/comments/commentable_with_component.rb
decidim-comments-0.25.0.rc3 lib/decidim/comments/commentable_with_component.rb
decidim-comments-0.25.0.rc2 lib/decidim/comments/commentable_with_component.rb
decidim-comments-0.25.0.rc1 lib/decidim/comments/commentable_with_component.rb