app/models/decidim/proposals/proposal.rb in decidim-proposals-0.0.1 vs app/models/decidim/proposals/proposal.rb in decidim-proposals-0.0.2

- old
+ new

@@ -6,10 +6,11 @@ belongs_to :feature, foreign_key: "decidim_feature_id", class_name: Decidim::Feature belongs_to :author, foreign_key: "decidim_author_id", class_name: Decidim::User belongs_to :category, foreign_key: "decidim_category_id", class_name: Decidim::Category belongs_to :scope, foreign_key: "decidim_scope_id", class_name: Decidim::Scope has_one :organization, through: :feature + has_many :votes, foreign_key: "decidim_proposal_id", class_name: ProposalVote, dependent: :destroy validates :title, :feature, :body, presence: true validate :category_belongs_to_feature validate :scope_belongs_to_organization validate :author_belongs_to_organization @@ -28,9 +29,16 @@ # assume all proposals can be commented. # # Returns Boolean def commentable? true + end + + # Public: Check if the user has voted the proposal + # + # Returns Boolean + def voted_by?(user) + votes.any? { |vote| vote.author == user } end private def category_belongs_to_feature