Class: Decidim::Proposals::Proposal
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Proposals::Proposal
- Includes:
- Authorable, Comments::Commentable, HasCategory, HasFeature, HasReference, HasScope, Reportable, Resourceable
- Defined in:
- app/models/decidim/proposals/proposal.rb
Overview
The data store for a Proposal in the Decidim::Proposals component.
Class Method Summary collapse
Instance Method Summary collapse
-
#accepted? ⇒ Boolean
Public: Checks if the organization has accepted a proposal.
-
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
-
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the proposal.
- #author_avatar_url ⇒ Object
- #author_name ⇒ Object
-
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
-
#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.
-
#notifiable?(context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method.
-
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a proposal.
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
-
#users_to_notify ⇒ Object
Public: Overrides the ‘users_to_notify` Notifiable concern method.
-
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the proposal.
Class Method Details
.order_randomly(seed) ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/decidim/proposals/proposal.rb', line 27 def self.order_randomly(seed) transaction do connection.execute("SELECT setseed(#{connection.quote(seed)})") order("RANDOM()").load end end |
Instance Method Details
#accepted? ⇒ Boolean
Public: Checks if the organization has accepted a proposal.
Returns Boolean.
59 60 61 |
# File 'app/models/decidim/proposals/proposal.rb', line 59 def accepted? state == "accepted" end |
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
76 77 78 |
# File 'app/models/decidim/proposals/proposal.rb', line 76 def accepts_new_comments? commentable? && !feature.active_step_settings.comments_blocked end |
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the proposal.
Returns Boolean.
52 53 54 |
# File 'app/models/decidim/proposals/proposal.rb', line 52 def answered? answered_at.present? end |
#author_avatar_url ⇒ Object
38 39 40 |
# File 'app/models/decidim/proposals/proposal.rb', line 38 def &.avatar&.url || ActionController::Base.helpers.asset_path("decidim/default-avatar.svg") end |
#author_name ⇒ Object
34 35 36 |
# File 'app/models/decidim/proposals/proposal.rb', line 34 def user_group&.name || &.name || I18n.t("decidim.proposals.models.proposal.fields.official_proposal") end |
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
71 72 73 |
# File 'app/models/decidim/proposals/proposal.rb', line 71 def commentable? feature.settings.comments_enabled? end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
81 82 83 |
# File 'app/models/decidim/proposals/proposal.rb', line 81 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
86 87 88 |
# File 'app/models/decidim/proposals/proposal.rb', line 86 def comments_have_votes? true end |
#notifiable?(context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method. When a proposal is commented the proposal’s author is notified if it is not the same who has commented the proposal and if the proposal’s author has comment notifications enabled.
98 99 100 |
# File 'app/models/decidim/proposals/proposal.rb', line 98 def notifiable?(context) context[:author] != && .comments_notifications? end |
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a proposal.
Returns Boolean.
66 67 68 |
# File 'app/models/decidim/proposals/proposal.rb', line 66 def rejected? state == "rejected" end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
91 92 93 |
# File 'app/models/decidim/proposals/proposal.rb', line 91 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#users_to_notify ⇒ Object
Public: Overrides the ‘users_to_notify` Notifiable concern method.
103 104 105 |
# File 'app/models/decidim/proposals/proposal.rb', line 103 def users_to_notify [] end |
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the proposal.
Returns Boolean.
45 46 47 |
# File 'app/models/decidim/proposals/proposal.rb', line 45 def voted_by?(user) votes.where(author: user).any? end |