Class: Decidim::Comments::CommentType
- Inherits:
-
Api::Types::BaseObject
- Object
- Api::Types::BaseObject
- Decidim::Comments::CommentType
- 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
- #already_reported ⇒ Object
- #down_voted ⇒ Object
- #has_comments? ⇒ Boolean
- #sgid ⇒ Object
- #up_voted ⇒ Object
- #user_allowed_to_comment ⇒ Object
Class Method Details
.authorized?(object, context) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/decidim/api/comment_type.rb', line 52 def self.(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_reported ⇒ Object
44 45 46 |
# File 'lib/decidim/api/comment_type.rb', line 44 def already_reported object.reported_by?(context[:current_user]) end |
#down_voted ⇒ Object
36 37 38 |
# File 'lib/decidim/api/comment_type.rb', line 36 def down_voted object.down_voted_by?(context[:current_user]) end |
#has_comments? ⇒ Boolean
40 41 42 |
# File 'lib/decidim/api/comment_type.rb', line 40 def has_comments? object.comment_threads.not_hidden.size.positive? end |
#sgid ⇒ Object
28 29 30 |
# File 'lib/decidim/api/comment_type.rb', line 28 def sgid object.to_sgid.to_s end |
#up_voted ⇒ Object
32 33 34 |
# File 'lib/decidim/api/comment_type.rb', line 32 def up_voted object.up_voted_by?(context[:current_user]) end |
#user_allowed_to_comment ⇒ Object
48 49 50 |
# File 'lib/decidim/api/comment_type.rb', line 48 def user_allowed_to_comment object.root_commentable.commentable? && object.root_commentable.user_allowed_to_comment?(context[:current_user]) end |