Class: Decidim::Comments::CommentType

Inherits:
Api::Types::BaseObject
  • Object
show all
Defined in:
lib/decidim/api/comment_type.rb

Overview

This type represents a comment on a commentable object.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authorized?(object, context) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/decidim/api/comment_type.rb', line 55

def self.authorized?(object, context)
  chain = []
  if object.respond_to?(:commentable) && !object.commentable.is_a?(Decidim::Comments::Comment)
    chain.unshift(allowed_to?(:read, object.commentable, object.commentable,
                              context))
  end

  chain.unshift(!object.hidden?)
  chain.unshift(!object.deleted?)

  super && chain.all?
end

Instance Method Details

#already_reportedObject



47
48
49
# File 'lib/decidim/api/comment_type.rb', line 47

def already_reported
  object.reported_by?(context[:current_user])
end

#authorObject



27
28
29
# File 'lib/decidim/api/comment_type.rb', line 27

def author
  object.user_group || object.author
end

#down_votedObject



39
40
41
# File 'lib/decidim/api/comment_type.rb', line 39

def down_voted
  object.down_voted_by?(context[:current_user])
end

#has_comments?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/decidim/api/comment_type.rb', line 43

def has_comments?
  object.comment_threads.not_hidden.size.positive?
end

#sgidObject



31
32
33
# File 'lib/decidim/api/comment_type.rb', line 31

def sgid
  object.to_sgid.to_s
end

#up_votedObject



35
36
37
# File 'lib/decidim/api/comment_type.rb', line 35

def up_voted
  object.up_voted_by?(context[:current_user])
end

#user_allowed_to_commentObject



51
52
53
# File 'lib/decidim/api/comment_type.rb', line 51

def user_allowed_to_comment
  object.root_commentable.commentable? && object.root_commentable.user_allowed_to_comment?(context[:current_user])
end