Class: Decidim::Proposals::Proposal
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Proposals::Proposal
- Includes:
- Authorable, Fingerprintable, Followable, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, CommentableProposal, Reportable, Resourceable, ScopableComponent, Searchable, Traceable
- 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.
-
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the proposal.
-
#can_accumulate_supports_beyond_threshold ⇒ Object
Public: Can accumulate more votres than maximum for this proposal.
-
#draft? ⇒ Boolean
Public: Whether the proposal is a draft or not.
-
#editable_by?(user) ⇒ Boolean
Checks whether the user can edit the given proposal.
-
#endorsed_by?(user, user_group = nil) ⇒ Boolean
Public: Check if the user has endorsed the proposal.
-
#evaluating? ⇒ Boolean
Public: Checks if the organization has marked the proposal as evaluating it.
-
#maximum_votes ⇒ Object
Public: The maximum amount of votes allowed for this proposal.
-
#maximum_votes_reached? ⇒ Boolean
Public: The maximum amount of votes allowed for this proposal.
-
#official? ⇒ Boolean
Public: Whether the proposal is official or not.
-
#published? ⇒ Boolean
Public: Checks if the proposal has been published or not.
-
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a proposal.
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
-
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the proposal.
-
#withdrawable_by?(user) ⇒ Boolean
Checks whether the user can withdraw the given proposal.
-
#withdrawn? ⇒ Boolean
Public: Checks if the author has withdrawn the proposal.
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
59 60 61 |
# File 'app/models/decidim/proposals/proposal.rb', line 59 def self.log_presenter_class_for(_log) Decidim::Proposals::AdminLog::ProposalPresenter end |
.order_randomly(seed) ⇒ Object
52 53 54 55 56 57 |
# File 'app/models/decidim/proposals/proposal.rb', line 52 def self.order_randomly(seed) transaction do connection.execute("SELECT setseed(#{connection.quote(seed)})") order(Arel.sql("RANDOM()")).load end end |
Instance Method Details
#accepted? ⇒ Boolean
Public: Checks if the organization has accepted a proposal.
Returns Boolean.
95 96 97 |
# File 'app/models/decidim/proposals/proposal.rb', line 95 def accepted? answered? && state == "accepted" end |
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the proposal.
Returns Boolean.
88 89 90 |
# File 'app/models/decidim/proposals/proposal.rb', line 88 def answered? answered_at.present? && state.present? end |
#can_accumulate_supports_beyond_threshold ⇒ Object
Public: Can accumulate more votres than maximum for this proposal.
Returns true if can accumulate, false otherwise
152 153 154 |
# File 'app/models/decidim/proposals/proposal.rb', line 152 def can_accumulate_supports_beyond_threshold component.settings.can_accumulate_supports_beyond_threshold end |
#draft? ⇒ Boolean
Public: Whether the proposal is a draft or not.
172 173 174 |
# File 'app/models/decidim/proposals/proposal.rb', line 172 def draft? published_at.nil? end |
#editable_by?(user) ⇒ Boolean
Checks whether the user can edit the given proposal.
user - the user to check for authorship
159 160 161 162 |
# File 'app/models/decidim/proposals/proposal.rb', line 159 def editable_by?(user) return true if draft? (user) && !answered? && within_edit_time_limit? && !copied_from_other_component? end |
#endorsed_by?(user, user_group = nil) ⇒ Boolean
Public: Check if the user has endorsed the proposal.
-
user_group: may be nil if user is not representing any user_group.
Returns Boolean.
74 75 76 |
# File 'app/models/decidim/proposals/proposal.rb', line 74 def endorsed_by?(user, user_group = nil) endorsements.where(author: user, user_group: user_group).any? end |
#evaluating? ⇒ Boolean
Public: Checks if the organization has marked the proposal as evaluating it.
Returns Boolean.
109 110 111 |
# File 'app/models/decidim/proposals/proposal.rb', line 109 def evaluating? answered? && state == "evaluating" end |
#maximum_votes ⇒ Object
Public: The maximum amount of votes allowed for this proposal.
Returns an Integer with the maximum amount of votes, nil otherwise.
133 134 135 136 137 138 |
# File 'app/models/decidim/proposals/proposal.rb', line 133 def maximum_votes maximum_votes = component.settings.threshold_per_proposal return nil if maximum_votes.zero? maximum_votes end |
#maximum_votes_reached? ⇒ Boolean
Public: The maximum amount of votes allowed for this proposal. 0 means infinite.
Returns true if reached, false otherwise.
143 144 145 146 147 |
# File 'app/models/decidim/proposals/proposal.rb', line 143 def maximum_votes_reached? return false unless maximum_votes votes.count >= maximum_votes end |
#official? ⇒ Boolean
Public: Whether the proposal is official or not.
126 127 128 |
# File 'app/models/decidim/proposals/proposal.rb', line 126 def official? .nil? end |
#published? ⇒ Boolean
Public: Checks if the proposal has been published or not.
Returns Boolean.
81 82 83 |
# File 'app/models/decidim/proposals/proposal.rb', line 81 def published? published_at.present? end |
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a proposal.
Returns Boolean.
102 103 104 |
# File 'app/models/decidim/proposals/proposal.rb', line 102 def rejected? answered? && state == "rejected" end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
121 122 123 |
# File 'app/models/decidim/proposals/proposal.rb', line 121 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the proposal.
Returns Boolean.
66 67 68 |
# File 'app/models/decidim/proposals/proposal.rb', line 66 def voted_by?(user) votes.where(author: user).any? end |
#withdrawable_by?(user) ⇒ Boolean
Checks whether the user can withdraw the given proposal.
user - the user to check for withdrawability.
167 168 169 |
# File 'app/models/decidim/proposals/proposal.rb', line 167 def withdrawable_by?(user) user && !withdrawn? && (user) && !copied_from_other_component? end |
#withdrawn? ⇒ Boolean
Public: Checks if the author has withdrawn the proposal.
Returns Boolean.
116 117 118 |
# File 'app/models/decidim/proposals/proposal.rb', line 116 def withdrawn? state == "withdrawn" end |