Class: Decidim::Debates::Debate
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Debates::Debate
- Includes:
- Authorable, Comments::Commentable, Decidim::DataPortability, Followable, HasCategory, HasComponent, HasReference, Loggable, NewsletterParticipant, Reportable, Resourceable, ScopableComponent, Traceable
- Defined in:
- app/models/decidim/debates/debate.rb
Overview
The data store for a Debate in the Decidim::Debates component. It stores a title, description and any other useful information to render a custom debate.
Class Method Summary collapse
- .export_serializer ⇒ Object
- .log_presenter_class_for(_log) ⇒ Object
- .newsletter_participant_ids(component) ⇒ Object
Instance Method Summary collapse
-
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
-
#ama? ⇒ Boolean
Public: Calculates whether the current debate is an AMA-styled one or not.
-
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
-
#commentable_type ⇒ Object
Public: Identifies the commentable type in the API.
-
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
-
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
-
#official? ⇒ Boolean
Public: Checks whether the debate is official or not.
-
#open? ⇒ Boolean
Public: Checks if the debate is open or not.
-
#open_ama? ⇒ Boolean
Public: Checks whether the debate is an AMA-styled one and is open.
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
-
#user_allowed_to_comment?(user) ⇒ Boolean
Public: Whether the object can have new comments or not.
-
#users_to_notify_on_comment_created ⇒ Object
Public: Override Commentable concern method ‘users_to_notify_on_comment_created`.
Class Method Details
.export_serializer ⇒ Object
101 102 103 |
# File 'app/models/decidim/debates/debate.rb', line 101 def self.export_serializer Decidim::Debates::DataPortabilityDebateSerializer end |
.log_presenter_class_for(_log) ⇒ Object
27 28 29 |
# File 'app/models/decidim/debates/debate.rb', line 27 def self.log_presenter_class_for(_log) Decidim::Debates::AdminLog::DebatePresenter end |
.newsletter_participant_ids(component) ⇒ Object
110 111 112 113 114 115 |
# File 'app/models/decidim/debates/debate.rb', line 110 def self.(component) Decidim::Debates::Debate.where(component: component).joins(:component) .where(decidim_author_type: Decidim::UserBaseEntity.name) .where.not(author: nil) .pluck(:decidim_author_id).flatten.compact.uniq end |
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
73 74 75 76 77 |
# File 'app/models/decidim/debates/debate.rb', line 73 def accepts_new_comments? return false unless open? commentable? && !comments_blocked? end |
#ama? ⇒ Boolean
Public: Calculates whether the current debate is an AMA-styled one or not. AMA-styled debates are those that have a start and end time set, and comments are only open during that timelapse. AMA stands for Ask Me Anything, a type of debate inspired by Reddit.
Returns a Boolean.
49 50 51 |
# File 'app/models/decidim/debates/debate.rb', line 49 def ama? start_time.present? && end_time.present? end |
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
68 69 70 |
# File 'app/models/decidim/debates/debate.rb', line 68 def commentable? component.settings.comments_enabled? end |
#commentable_type ⇒ Object
Public: Identifies the commentable type in the API.
90 91 92 |
# File 'app/models/decidim/debates/debate.rb', line 90 def commentable_type self.class.name end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
80 81 82 |
# File 'app/models/decidim/debates/debate.rb', line 80 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
85 86 87 |
# File 'app/models/decidim/debates/debate.rb', line 85 def comments_have_votes? true end |
#official? ⇒ Boolean
Public: Checks whether the debate is official or not.
Returns a boolean.
34 35 36 |
# File 'app/models/decidim/debates/debate.rb', line 34 def official? .is_a?(Decidim::Organization) end |
#open? ⇒ Boolean
Public: Checks if the debate is open or not.
Returns a boolean.
63 64 65 |
# File 'app/models/decidim/debates/debate.rb', line 63 def open? (ama? && open_ama?) || !ama? end |
#open_ama? ⇒ Boolean
Public: Checks whether the debate is an AMA-styled one and is open.
Returns a boolean.
56 57 58 |
# File 'app/models/decidim/debates/debate.rb', line 56 def open_ama? ama? && Time.current.between?(start_time, end_time) end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
39 40 41 |
# File 'app/models/decidim/debates/debate.rb', line 39 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#user_allowed_to_comment?(user) ⇒ Boolean
Public: Whether the object can have new comments or not.
106 107 108 |
# File 'app/models/decidim/debates/debate.rb', line 106 def user_allowed_to_comment?(user) can_participate_in_space?(user) end |
#users_to_notify_on_comment_created ⇒ Object
Public: Override Commentable concern method ‘users_to_notify_on_comment_created`
95 96 97 98 99 |
# File 'app/models/decidim/debates/debate.rb', line 95 def users_to_notify_on_comment_created return Decidim::User.where(id: followers).or(Decidim::User.where(id: component.participatory_space.admins)).distinct if official? followers end |