app/models/decidim/proposals/proposal.rb in decidim-proposals-0.0.3 vs app/models/decidim/proposals/proposal.rb in decidim-proposals-0.0.5
- old
+ new
@@ -6,14 +6,15 @@
include Decidim::Resourceable
include Decidim::Authorable
include Decidim::HasFeature
include Decidim::HasScope
include Decidim::HasCategory
+ include Decidim::Comments::Commentable
feature_manifest_name "proposals"
- has_many :votes, foreign_key: "decidim_proposal_id", class_name: ProposalVote, dependent: :destroy
+ has_many :votes, foreign_key: "decidim_proposal_id", class_name: ProposalVote, dependent: :destroy, counter_cache: "proposal_votes_count"
validates :title, :body, presence: true
scope :accepted, -> { where(state: "accepted") }
scope :rejected, -> { where(state: "rejected") }
@@ -28,11 +29,11 @@
# Public: Check if the user has voted the proposal.
#
# Returns Boolean.
def voted_by?(user)
- votes.any? { |vote| vote.author == user }
+ votes.where(author: user).any?
end
# Public: Checks if the organization has given an answer for the proposal.
#
# Returns Boolean.
@@ -50,9 +51,29 @@
# Public: Checks if the organization has rejected a proposal.
#
# Returns Boolean.
def rejected?
state == "rejected"
+ end
+
+ # Public: Overrides the `commentable?` Commentable concern method.
+ def commentable?
+ feature.settings.comments_enabled?
+ end
+
+ # Public: Overrides the `accepts_new_comments?` Commentable concern method.
+ def accepts_new_comments?
+ commentable? && !feature.active_step_settings.comments_blocked
+ end
+
+ # Public: Overrides the `comments_have_alignment?` Commentable concern method.
+ def comments_have_alignment?
+ true
+ end
+
+ # Public: Overrides the `comments_have_votes?` Commentable concern method.
+ def comments_have_votes?
+ true
end
end
end
end