Class: Decidim::Proposals::Proposal
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Proposals::Proposal
- Includes:
- Authorable, Followable, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, CommentableProposal, Reportable, Resourceable, ScopableComponent, 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.
-
#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
44 45 46 |
# File 'app/models/decidim/proposals/proposal.rb', line 44 def self.log_presenter_class_for(_log) Decidim::Proposals::AdminLog::ProposalPresenter end |
.order_randomly(seed) ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/decidim/proposals/proposal.rb', line 37 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.
73 74 75 |
# File 'app/models/decidim/proposals/proposal.rb', line 73 def accepted? answered? && state == "accepted" end |
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the proposal.
Returns Boolean.
66 67 68 |
# File 'app/models/decidim/proposals/proposal.rb', line 66 def answered? answered_at.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
130 131 132 |
# File 'app/models/decidim/proposals/proposal.rb', line 130 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.
150 151 152 |
# File 'app/models/decidim/proposals/proposal.rb', line 150 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
137 138 139 140 |
# File 'app/models/decidim/proposals/proposal.rb', line 137 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.
59 60 61 |
# File 'app/models/decidim/proposals/proposal.rb', line 59 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.
87 88 89 |
# File 'app/models/decidim/proposals/proposal.rb', line 87 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.
111 112 113 114 115 116 |
# File 'app/models/decidim/proposals/proposal.rb', line 111 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.
121 122 123 124 125 |
# File 'app/models/decidim/proposals/proposal.rb', line 121 def maximum_votes_reached? return false unless maximum_votes votes.count >= maximum_votes end |
#official? ⇒ Boolean
Public: Whether the proposal is official or not.
104 105 106 |
# File 'app/models/decidim/proposals/proposal.rb', line 104 def official? .nil? end |
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a proposal.
Returns Boolean.
80 81 82 |
# File 'app/models/decidim/proposals/proposal.rb', line 80 def rejected? answered? && state == "rejected" end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
99 100 101 |
# File 'app/models/decidim/proposals/proposal.rb', line 99 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the proposal.
Returns Boolean.
51 52 53 |
# File 'app/models/decidim/proposals/proposal.rb', line 51 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.
145 146 147 |
# File 'app/models/decidim/proposals/proposal.rb', line 145 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.
94 95 96 |
# File 'app/models/decidim/proposals/proposal.rb', line 94 def withdrawn? state == "withdrawn" end |