app/models/decidim/proposals/proposal.rb in decidim-proposals-0.11.2 vs app/models/decidim/proposals/proposal.rb in decidim-proposals-0.12.0.pre
- old
+ new
@@ -12,13 +12,17 @@
include Decidim::HasCategory
include Decidim::Reportable
include Decidim::HasAttachments
include Decidim::Followable
include Decidim::Proposals::CommentableProposal
+ include Decidim::Searchable
include Decidim::Traceable
include Decidim::Loggable
+ include Decidim::Fingerprintable
+ fingerprint fields: [:title, :body]
+
component_manifest_name "proposals"
has_many :endorsements, foreign_key: "decidim_proposal_id", class_name: "ProposalEndorsement", dependent: :destroy, counter_cache: "proposal_endorsements_count"
has_many :votes, foreign_key: "decidim_proposal_id", class_name: "ProposalVote", dependent: :destroy, counter_cache: "proposal_votes_count"
has_many :notes, foreign_key: "decidim_proposal_id", class_name: "ProposalNote", dependent: :destroy, counter_cache: "proposal_notes_count"
@@ -29,17 +33,26 @@
scope :accepted, -> { where(state: "accepted") }
scope :rejected, -> { where(state: "rejected") }
scope :evaluating, -> { where(state: "evaluating") }
scope :withdrawn, -> { where(state: "withdrawn") }
+ scope :except_rejected, -> { where.not(state: "rejected").or(where(state: nil)) }
scope :except_withdrawn, -> { where.not(state: "withdrawn").or(where(state: nil)) }
scope :published, -> { where.not(published_at: nil) }
+ searchable_fields(
+ scope_id: :decidim_scope_id,
+ participatory_space: { component: :participatory_space },
+ A: :title,
+ D: :body,
+ datetime: :published_at
+ )
+
def self.order_randomly(seed)
transaction do
connection.execute("SELECT setseed(#{connection.quote(seed)})")
- order("RANDOM()").load
+ order(Arel.sql("RANDOM()")).load
end
end
def self.log_presenter_class_for(_log)
Decidim::Proposals::AdminLog::ProposalPresenter
@@ -58,14 +71,21 @@
# Returns Boolean.
def endorsed_by?(user, user_group = nil)
endorsements.where(author: user, user_group: user_group).any?
end
+ # Public: Checks if the proposal has been published or not.
+ #
+ # Returns Boolean.
+ def published?
+ published_at.present?
+ end
+
# Public: Checks if the organization has given an answer for the proposal.
#
# Returns Boolean.
def answered?
- answered_at.present?
+ answered_at.present? && state.present?
end
# Public: Checks if the organization has accepted a proposal.
#
# Returns Boolean.