Sha256: 37a922d70ad286ca91ee02bbd057c2b1a300179de53f243449a390a523bdc06e
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true module Decidim module Proposals # The data store for a Proposal in the Decidim::Proposals component. class Proposal < Proposals::ApplicationRecord include Decidim::Resourceable include Decidim::Authorable include Decidim::HasFeature include Decidim::HasScope include Decidim::HasCategory feature_manifest_name "proposals" has_many :votes, foreign_key: "decidim_proposal_id", class_name: ProposalVote, dependent: :destroy validates :title, :body, presence: true scope :accepted, -> { where(state: "accepted") } scope :rejected, -> { where(state: "rejected") } def author_name user_group&.name || author&.name || I18n.t("decidim.proposals.models.proposal.fields.official_proposal") end def author_avatar_url author&.avatar&.url || ActionController::Base.helpers.asset_path("decidim/default-avatar.svg") end # Public: Check if the user has voted the proposal. # # Returns Boolean. def voted_by?(user) votes.any? { |vote| vote.author == user } end # Public: Checks if the organization has given an answer for the proposal. # # Returns Boolean. def answered? answered_at.present? end # Public: Checks if the organization has accepted a proposal. # # Returns Boolean. def accepted? state == "accepted" end # Public: Checks if the organization has rejected a proposal. # # Returns Boolean. def rejected? state == "rejected" end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
decidim-proposals-0.0.3 | app/models/decidim/proposals/proposal.rb |
decidim-0.0.3 | decidim-proposals/app/models/decidim/proposals/proposal.rb |